1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.1 Server backup methods

Discussion in 'XenForo Questions and Support' started by Neil E., Jul 11, 2012.

  1. Neil E.

    Neil E. Active Member

    I've had a look at Jake's guide for forum backup and see that shell access is recommended. That requires a move to a different sever and extra charges from my host. Before I go that route, I looked at what is in the standard server tools (linux). It has backup, backup wizard and phpmyadmin.

    From what I can tell these programs can do backup work BUT will only restore back to their original source. So if I mess up a backup, I'd just be swapping garbage around. The idea of using shell access to restore to a different directory sounds like it should be more flexible. It would let me do some testing to see if things worked correctly. Is this valid or is there a lot more to a restore in terms of redirecting everything to work with the new directory? I am a total noob at this.
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Changing directories during a restore is simply a matter of restoring the XF files to the new location, and editing the library/config.php file in that new location to point to the database to which you restored your db backup. Once the forum is up and running then you need to update this setting:

    Admin CP -> Home -> Options -> Basic Board Information -> Board URL
    vVv likes this.
  3. vVv

    vVv Guest

    Replying for future reference...But confused as to how you just restore a database, if the board url in the backup (that's being restored on new host) will work on the new host, and be up and running? Because if user had it on "-http://myhappy.com", backed up, and then restore it on new host, and in directory "-http://myhappyspot.com/community/" .. the forum wouldn't just be "up and running", to change the url, would it?

    Unless the board url is supposed to be updated/changed in the current location (-http://myhappy.com) first, before taking backup (for restoring exactly where new location will be later on).. then import into new database... ? What I usually do is, obviously make new database, user, pass for it on new host... Then, upload a ZIP archive of ALL the files fully intact from old host to the new host via File Manager. Once it's uploaded there, unzip it via File Manager. Once uncompressed, in File Manager, edit config.php with new database details.

    Then, upload a huge "Find and Replace" database script I've used many many times, to new forum root, and run it.

    // Find and replace facility for complete MySQL database
    // Written by Mark Jackson @ MJDIGITAL
    // Can be used by anyone - but give me a nod if you do!
    // http://www.mjdigital.co.uk/blog
    $search        = 'http://myhappy.com/';
    $replace    = 'http://myhappyspot.com/community/'; // (used if queryType below is set to 'replace')
    // DB Details
    $hostname = "localhost";
    $database = "my-new-database-name";
    $username = "database-user";
    $password = "database-password";
    // Query Type: 'search' or 'replace'
    $queryType = 'replace';
    // show errors (.ini file dependant) - true/false
    $showErrors = true;
    //        DO NOT EDIT BELOW
    if($showErrors) {
        ini_set('error_reporting', E_ALL);
    // Create connectio to DB
    $MJCONN = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
    // Get list of tables
    $table_sql = 'SHOW TABLES';
    $table_q = mysql_query($table_sql,$MJCONN) or die("Cannot Query DB: ".mysql_error());
    $tables_r = mysql_fetch_assoc($table_q);
    $tables = array();
        $tables[] = $tables_r['Tables_in_'.strtolower($database)];
    }while($tables_r = mysql_fetch_assoc($table_q));
    // create array to hold required SQL
    $use_sql = array();
    $rowHeading = ($queryType=='replace') ?
            'Replacing \''.$search.'\' with \''.$replace.'\' in \''.$database."'\n\nSTATUS    |    ROWS AFFECTED    |    TABLE/FIELD    (+ERROR)\n"
          : 'Searching for \''.$search.'\' in \''.$database."'\n\nSTATUS    |    ROWS CONTAINING    |    TABLE/FIELD    (+ERROR)\n";
    $output = $rowHeading;
    $summary = '';
    foreach($tables as $table) {
        $field_sql = 'SHOW FIELDS FROM '.$table;
        $field_q = mysql_query($field_sql,$MJCONN);
        $field_r = mysql_fetch_assoc($field_q);
        // compile + run SQL
        do {
            $field = $field_r['Field'];
            $type = $field_r['Type'];
            switch(true) {
                // set which column types can be replaced/searched
                case stristr(strtolower($type),'char'): $typeOK = true; break;
                case stristr(strtolower($type),'text'): $typeOK = true; break;
                case stristr(strtolower($type),'blob'): $typeOK = true; break;
                case stristr(strtolower($field_r['Key']),'pri'): $typeOK = false; break; // do not replace on primary keys
                default: $typeOK = false; break;
            if($typeOK) { // Field type is OK ro replacement
                // create unique handle for update_sql array
                $handle = $table.'_'.$field;
                if($queryType=='replace') {
                    $sql[$handle]['sql'] = 'UPDATE '.$table.' SET '.$field.' = REPLACE('.$field.',\''.$search.'\',\''.$replace.'\')';
                } else {
                    $sql[$handle]['sql'] = 'SELECT * FROM '.$table.' WHERE '.$field.' REGEXP(\''.$search.'\')';
                // execute SQL
                $error = false;
                $query = @mysql_query($sql[$handle]['sql'],$MJCONN) or $error = mysql_error();
                $row_count = @mysql_affected_rows() or $row_count = 0;
                // store the output (just in case)
                $sql[$handle]['result'] = $query;
                $sql[$handle]['affected'] = $row_count;
                $sql[$handle]['error'] = $error;
                // Write out Results into $output
                $output .= ($query) ? 'OK        ' : '--        ';
                $output .= ($row_count>0) ? '<strong>'.$row_count.'</strong>            ' : '<span style="color:#CCC">'.$row_count.'</span>            ';
                $fieldName = '`'.$table.'`.`'.$field.'`';
                $output .= $fieldName;
                $erTab = str_repeat(' ', (60-strlen($fieldName)) );
                $output .= ($error) ? $erTab.'(ERROR: '.$error.')' : '';
                $output .= "\n";
        }while($field_r = mysql_fetch_assoc($field_q));
    // write the output out to the page
    echo '<pre>';
    echo $output."\n";
    echo '<pre>';
    -http://myhappyspot.com/community/findandreplace.php" to find and replace traces of "-http://myhappy.com/" to replace with "-http://myhappyspot.com/community/" .. after it runs and loads results page, go back to forum root and usually it's up and going. Lol! I know, seems like a huge process, but does work 99% of the time for me.. wheee! (note, this find and replace can be used for anything too, not just urls lol.)
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    vVv likes this.
  5. vVv

    vVv Guest

    Ah, okay... Thanks Jake, I guess I'm so used to other software being so complex for restoring their backups, assumed XF was the same.. haha. :p Most before, say.. "before restoring, find and replace traces of old domain with the new domain." lol. Aight, I guess I have a huge restore to do ugh.. *gets more coffee*

Share This Page