Esempio n. 1
1
 public function __construct($type, $existingState = '')
 {
     pb_backupbuddy::status('details', 'Constructing rollback class.');
     if ('rollback' != $type && 'restore' != $type) {
         $this->_error('Invalid restore type `' . htmlentities($type) . '`.');
         return false;
     }
     register_shutdown_function(array(&$this, 'shutdown_function'));
     pb_backupbuddy::status('details', 'Setting restore state defaults.');
     $this->_state = array('type' => $type, 'archive' => '', 'serial' => '', 'tempPath' => '', 'data' => array(), 'undoURL' => '', 'forceMysqlMethods' => array(), 'autoAdvance' => true, 'maxExecutionTime' => backupbuddy_core::detectMaxExecutionTime(), 'dbImportPoint' => 0, 'zipMethodStrategy' => 'all', 'restoreFiles' => true, 'restoreDatabase' => true, 'migrateHtaccess' => true, 'databaseSettings' => array('server' => '', 'database' => '', 'username' => '', 'password' => '', 'prefix' => '', 'tempPrefix' => '', 'wipePrefix' => false, 'renamePrefix' => false, 'wipeDatabase' => false, 'ignoreSqlErrors' => false, 'sqlFiles' => array(), 'sqlFilesLocation' => '', 'databaseMethodStrategy' => 'php', 'importResumePoint' => '', 'importedResumeRows' => 0, 'importedResumeFails' => 0, 'importedResumeTime' => 0, 'migrateDatabase' => true, 'migrateDatabaseBruteForce' => true, 'migrateResumeSteps' => '', 'migrateResumePoint' => ''), 'cleanup' => array('deleteArchive' => true, 'deleteTempFiles' => true, 'deleteImportBuddy' => true, 'deleteImportLog' => true), 'potentialProblems' => array(), 'stepHistory' => array());
     // Restore-specific default options.
     if ('restore' == $type) {
         $this->_state['skipUnzip'] = false;
         $this->_state['restoreFiles'] = true;
         $this->_state['restoreDatabase'] = true;
         $this->_state['migrateHtaccess'] = true;
         $this->_state['tempPath'] = ABSPATH . 'importbuddy/temp_' . pb_backupbuddy::$options['log_serial'] . '/';
     } elseif ('rollback' == $type) {
         $this->_state['tempPath'] = backupbuddy_core::getTempDirectory() . $this->_state['type'] . '_' . $this->_state['serial'] . '/';
     }
     if (is_array($existingState)) {
         // User passed along an existing state to resume.
         pb_backupbuddy::status('details', 'Using provided restore state data.');
         $this->_state = $this->_array_replace_recursive($this->_state, $existingState);
     }
     // Check if a default state override exists.  Used by automated restoring.
     /*
     if ( isset( pb_backupbuddy::$options['default_state_overrides'] ) && ( count( pb_backupbuddy::$options['default_state_overrides'] ) > 0 ) ) { // Default state overrides exist. Apply them.
     	$this->_state = array_merge( $this->_state, pb_backupbuddy::$options['default_state_overrides'] );
     }
     */
     pb_backupbuddy::status('details', 'Restore class constructed in `' . $type . '` mode.');
     pb_backupbuddy::set_greedy_script_limits();
     // Just always assume we need this during restores/rollback...
 }
Esempio n. 2
0
File: 1.php Progetto: brettex/pspark
/**
 *	upload()
 *
 *	Processes uploaded backup file.
 *
 *	@return		array		True on upload success; false otherwise.
 */
function upload()
{
    if (isset($_POST['upload']) && $_POST['upload'] == 'local') {
        if (pb_backupbuddy::$options['password'] != '#PASSWORD#') {
            $path_parts = pathinfo($_FILES['file']['name']);
            if (strtolower(substr($_FILES['file']['name'], 0, 6)) == 'backup' && strtolower($path_parts['extension']) == 'zip') {
                if (move_uploaded_file($_FILES['file']['tmp_name'], basename($_FILES['file']['name']))) {
                    pb_backupbuddy::alert('File Uploaded. Your backup was successfully uploaded.');
                    return true;
                } else {
                    pb_backupbuddy::alert('Sorry, there was a problem uploading your file.', true);
                    return false;
                }
            } else {
                pb_backupbuddy::alert('Only properly named BackupBuddy zip archives with a zip extension may be uploaded.', true);
                return false;
            }
        } else {
            pb_backupbuddy::alert('Upload Access Denied. To prevent unauthorized file uploads an importbuddy password must be configured and properly entered to use this feature.');
            return false;
        }
    }
    // DOWNLOAD FILE FROM STASH TO LOCAL.
    if (pb_backupbuddy::_POST('upload') == 'stash') {
        pb_backupbuddy::set_greedy_script_limits(true);
        /*
        echo '<pre>';
        print_r( $_POST );
        echo '</pre>';
        */
        $requestcore_file = dirname(dirname(dirname(__FILE__))) . '/lib/requestcore/requestcore.class.php';
        require_once $requestcore_file;
        $link = pb_backupbuddy::_POST('link');
        $destination_file = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . basename(pb_backupbuddy::_POST('link'));
        $destination_file = substr($destination_file, 0, stripos($destination_file, '.zip') + 4);
        $_GET['file'] = basename($destination_file);
        $request = new RequestCore($link);
        $request->set_write_file($destination_file);
        echo '<div id="pb_importbuddy_working" style="padding: 20px;">Downloading backup from Stash to `' . $destination_file . '`...<br><br><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."><br><br></div>';
        flush();
        $response = $request->send_request(false);
        if ($response !== true) {
            pb_backupbuddy::alert('Error #8548459598. Unable to download file from Stash. You may manually download it and upload to the server via FTP.');
        } else {
            // No error.
            if (!file_exists($destination_file)) {
                pb_backupbuddy::alert('Error #34845745878. Stash returned a success but the backup file was not found locally. Check this server\'s directory write permissions. You may manually download it and upload to the server via FTP.');
            }
        }
        echo '<script type="text/javascript">jQuery("#pb_importbuddy_working").hide();</script>';
    }
}
Esempio n. 3
0
/**
 *	extract()
 *
 *	Extract backup zip file.
 *
 *	@return		array		True if the extraction was a success OR skipping of extraction is set.
 */
function extract_files()
{
    if (true === pb_backupbuddy::$options['skip_files']) {
        // Option to skip all file updating / extracting.
        pb_backupbuddy::status('message', 'Skipped extracting files based on debugging options.');
        return true;
    } else {
        pb_backupbuddy::set_greedy_script_limits();
        pb_backupbuddy::status('message', 'Unzipping into `' . ABSPATH . '`');
        $backup_archive = ABSPATH . pb_backupbuddy::$options['file'];
        $destination_directory = ABSPATH;
        // Set compatibility mode if defined in advanced options.
        $compatibility_mode = false;
        // Default to no compatibility mode.
        if (pb_backupbuddy::$options['force_compatibility_medium'] != false) {
            $compatibility_mode = 'ziparchive';
        } elseif (pb_backupbuddy::$options['force_compatibility_slow'] != false) {
            $compatibility_mode = 'pclzip';
        }
        // Zip & Unzip library setup.
        require_once ABSPATH . 'importbuddy/lib/zipbuddy/zipbuddy.php';
        $_zipbuddy = new pluginbuddy_zipbuddy(ABSPATH, array(), 'unzip');
        // Extract zip file & verify it worked.
        if (true !== ($result = $_zipbuddy->unzip($backup_archive, $destination_directory, $compatibility_mode))) {
            pb_backupbuddy::status('error', 'Failed unzipping archive.');
            pb_backupbuddy::alert('Failed unzipping archive.', true);
            return false;
        } else {
            // Reported success; verify extraction.
            $_backupdata_file = ABSPATH . 'wp-content/uploads/temp_' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php';
            // OLD 1.x FORMAT. Full backup dat file location.
            $_backupdata_file_dbonly = ABSPATH . 'backupbuddy_dat.php';
            // DB only dat file location
            $_backupdata_file_new = ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php';
            // Full backup dat file location
            if (!file_exists($_backupdata_file) && !file_exists($_backupdata_file_dbonly) && !file_exists($_backupdata_file_new)) {
                $error_message = 'Error #9004: Key files missing. The unzip process reported success but the backup data file, backupbuddy_dat.php was not found in the extracted files. The unzip process either failed to fully complete, you renamed the backup ZIP file (rename it back to correct this), or the zip file is not a proper BackupBuddy backup.';
                pb_backupbuddy::status('error', $error_message);
                pb_backupbuddy::alert($error_message, true, '9004');
                return false;
            }
            pb_backupbuddy::status('details', 'Success extracting Zip File "' . ABSPATH . pb_backupbuddy::$options['file'] . '" into "' . ABSPATH . '".');
            return true;
        }
    }
}
Esempio n. 4
0
<?php

pb_backupbuddy::set_greedy_script_limits(true);
$data = array('detected_max_execution_time' => 30, 'backup_archives' => get_archives_list(), 'wordpress_exists' => wordpress_exists(), 'step' => '1');
$detected_max_execution_time = str_ireplace('s', '', ini_get('max_execution_time'));
if (is_numeric($detected_max_execution_time)) {
    $data['detected_max_execution_time'] = $detected_max_execution_time;
}
/**
 *	upload()
 *
 *	Processes uploaded backup file.
 *
 *	@return		array		True on upload success; false otherwise.
 */
function upload()
{
    if (isset($_POST['upload']) && $_POST['upload'] == 'local') {
        if (pb_backupbuddy::$options['password'] != '#PASSWORD#') {
            $path_parts = pathinfo($_FILES['file']['name']);
            if (strtolower(substr($_FILES['file']['name'], 0, 6)) == 'backup' && strtolower($path_parts['extension']) == 'zip') {
                if (move_uploaded_file($_FILES['file']['tmp_name'], basename($_FILES['file']['name']))) {
                    pb_backupbuddy::alert('File Uploaded. Your backup was successfully uploaded.');
                    return true;
                } else {
                    pb_backupbuddy::alert('Sorry, there was a problem uploading your file.', true);
                    return false;
                }
            } else {
                pb_backupbuddy::alert('Only properly named BackupBuddy zip archives with a zip extension may be uploaded.', true);
                return false;
Esempio n. 5
0
 public function php_max_runtime_test()
 {
     $stop_time_limit = 240;
     pb_backupbuddy::set_greedy_script_limits();
     // Crank it up for the test!
     $m = "# Starting BackupBuddy PHP Max Execution Time Tester. Determines what your ACTUAL limit is (usually shorter than the server reports so now you can find out the truth!). Stopping test if it gets to `{$stop_time_limit}` seconds. When your browser stops loading this page then the script has most likely timed out at your actual PHP limit.";
     pb_backupbuddy::status('details', $m);
     echo $m . "<br>\n";
     $t = 0;
     // Time = 0;
     while ($t < $stop_time_limit) {
         pb_backupbuddy::status('details', 'Max PHP Execution Time Test status: ' . $t);
         echo $t . "<br>\n";
         //sleep( 1 );
         $now = time();
         while (time() < $now + 1) {
             true;
         }
         flush();
         $t++;
     }
     $m = '# Ending BackupBuddy PHP Max Execution Time The test was stopped as the test time limit of ' . $stop_time_limit . ' seconds.';
     pb_backupbuddy::status('details', $m);
     echo $m . "<br>\n";
     die;
 }
Esempio n. 6
0
 function process_ftp_copy($backup, $ftp_server, $ftp_username, $ftp_password, $ftp_directory, $port = '21', $ftps = '0')
 {
     pb_backupbuddy::set_greedy_script_limits();
     if (!class_exists('backupbuddy_core')) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     }
     // Connect to server.
     if ($ftps == '1') {
         // Connect with FTPs.
         if (function_exists('ftp_ssl_connect')) {
             $conn_id = ftp_ssl_connect($ftp_server, $port);
             if ($conn_id === false) {
                 pb_backupbuddy::status('details', 'Unable to connect to FTPS  (check address/FTPS support).', 'error');
                 return false;
             } else {
                 pb_backupbuddy::status('details', 'Connected to FTPs.');
             }
         } else {
             pb_backupbuddy::status('details', 'Your web server doesnt support FTPS in PHP.', 'error');
             return false;
         }
     } else {
         // Connect with FTP (normal).
         if (function_exists('ftp_connect')) {
             $conn_id = ftp_connect($ftp_server, $port);
             if ($conn_id === false) {
                 pb_backupbuddy::status('details', 'ERROR: Unable to connect to FTP (check address).', 'error');
                 return false;
             } else {
                 pb_backupbuddy::status('details', 'Connected to FTP.');
             }
         } else {
             pb_backupbuddy::status('details', 'Your web server doesnt support FTP in PHP.', 'error');
             return false;
         }
     }
     // login with username and password
     $login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
     // try to download $server_file and save to $local_file
     $destination_file = backupbuddy_core::getBackupDirectory() . $backup;
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     if (ftp_get($conn_id, $destination_file, $ftp_directory . $backup, FTP_BINARY)) {
         pb_backupbuddy::status('message', 'Successfully wrote remote file locally to `' . $destination_file . '`.');
     } else {
         pb_backupbuddy::status('error', 'Error writing remote file locally to `' . $destination_file . '`.');
     }
     // close this connection
     ftp_close($conn_id);
 }
Esempio n. 7
0
 public static function importbuddy($output_file = '', $importbuddy_pass_hash = '', $return_not_echo = false)
 {
     pb_backupbuddy::set_greedy_script_limits();
     // Some people run out of PHP memory.
     if ($importbuddy_pass_hash == '') {
         if (!isset(pb_backupbuddy::$options)) {
             pb_backupbuddy::load();
         }
         $importbuddy_pass_hash = pb_backupbuddy::$options['importbuddy_pass_hash'];
     }
     if ($importbuddy_pass_hash == '') {
         $message = 'Warning #9032 - You have not set an ImportBuddy password on the BackupBuddy Settings page. Once this password is set a copy of the importbuddy.php file needed to restore your backup will be included in Full backup zip files for convenience. It may manually be downloaded from the Restore / Migrate page.';
         pb_backupbuddy::status('warning', $message);
         return false;
     }
     pb_backupbuddy::status('details', 'Loading importbuddy core file into memory.');
     $output = file_get_contents(pb_backupbuddy::plugin_path() . '/_importbuddy/_importbuddy.php');
     if ($importbuddy_pass_hash != '') {
         $output = preg_replace('/#PASSWORD#/', $importbuddy_pass_hash, $output, 1);
         // Only replaces first instance.
     }
     $version_string = pb_backupbuddy::settings('version') . ' (downloaded ' . date(DATE_W3C) . ')';
     // If on DEV system (.git dir exists) then append some details on current.
     if (defined('BACKUPBUDDY_DEV') && true === BACKUPBUDDY_DEV) {
         if (@file_exists(pb_backupbuddy::plugin_path() . '/.git/logs/HEAD')) {
             $commit_log = escapeshellarg(pb_backupbuddy::plugin_path() . '/.git/logs/HEAD');
             $commit_line = str_replace('\'', '`', exec("tail -n 1 {$commit_log}"));
             $version_string .= ' <span style="font-size: 8px;">[DEV: ' . $commit_line . ']</span>';
         }
     }
     $output = preg_replace('/#VERSION#/', $version_string, $output, 1);
     // Only replaces first instance.
     // PACK IMPORTBUDDY
     $_packdata = array('_importbuddy/importbuddy' => 'importbuddy', 'classes/_migrate_database.php' => 'importbuddy/classes/_migrate_database.php', 'classes/core.php' => 'importbuddy/classes/core.php', 'classes/import.php' => 'importbuddy/classes/import.php', 'classes/restore.php' => 'importbuddy/classes/restore.php', 'classes/_restoreFiles.php' => 'importbuddy/classes/_restoreFiles.php', 'classes/remote_api.php' => 'importbuddy/classes/remote_api.php', 'js/jquery.leanModal.min.js' => 'importbuddy/js/jquery.leanModal.min.js', 'js/jquery.joyride-2.0.3.js' => 'importbuddy/js/jquery.joyride-2.0.3.js', 'js/modernizr.mq.js' => 'importbuddy/js/modernizr.mq.js', 'css/joyride.css' => 'importbuddy/css/joyride.css', 'images/working.gif' => 'importbuddy/images/working.gif', 'images/bullet_go.png' => 'importbuddy/images/bullet_go.png', 'images/favicon.png' => 'importbuddy/images/favicon.png', 'images/sort_down.png' => 'importbuddy/images/sort_down.png', 'images/icon_menu_32x32.png' => 'importbuddy/images/icon_menu_32x32.png', 'lib/dbreplace' => 'importbuddy/lib/dbreplace', 'lib/dbimport' => 'importbuddy/lib/dbimport', 'lib/commandbuddy' => 'importbuddy/lib/commandbuddy', 'lib/zipbuddy' => 'importbuddy/lib/zipbuddy', 'lib/mysqlbuddy' => 'importbuddy/lib/mysqlbuddy', 'lib/textreplacebuddy' => 'importbuddy/lib/textreplacebuddy', 'lib/cpanel' => 'importbuddy/lib/cpanel', 'pluginbuddy' => 'importbuddy/pluginbuddy', 'controllers/pages/server_info' => 'importbuddy/controllers/pages/server_info', 'controllers/pages/server_tools.php' => 'importbuddy/controllers/pages/server_tools.php', 'destinations/stash/lib/class.itx_helper.php' => 'importbuddy/classes/class.itx_helper.php', 'destinations/_s3lib/aws-sdk/lib/requestcore' => 'importbuddy/lib/requestcore');
     pb_backupbuddy::status('details', 'Loading each file into memory for writing master importbuddy file.');
     $output .= "\n<?php /*\n###PACKDATA,BEGIN\n";
     foreach ($_packdata as $pack_source => $pack_destination) {
         $pack_source = '/' . $pack_source;
         if (is_dir(pb_backupbuddy::plugin_path() . $pack_source)) {
             $files = pb_backupbuddy::$filesystem->deepglob(pb_backupbuddy::plugin_path() . $pack_source);
         } else {
             $files = array(pb_backupbuddy::plugin_path() . $pack_source);
         }
         foreach ($files as $file) {
             if (is_file($file)) {
                 $source = str_replace(pb_backupbuddy::plugin_path(), '', $file);
                 $destination = $pack_destination . substr($source, strlen($pack_source));
                 $output .= "###PACKDATA,FILE_START,{$source},{$destination}\n";
                 $output .= base64_encode(file_get_contents($file));
                 $output .= "\n";
                 $output .= "###PACKDATA,FILE_END,{$source},{$destination}\n";
             }
         }
     }
     $output .= "###PACKDATA,END\n*/";
     $output .= "\n\n\n\n\n\n\n\n\n\n";
     if (true === $return_not_echo) {
         return $output;
     }
     if ($output_file == '') {
         // No file so output to browser.
         header('Content-Description: File Transfer');
         header('Content-Type: text/plain; name=importbuddy.php');
         header('Content-Disposition: attachment; filename=importbuddy.php');
         header('Expires: 0');
         header('Content-Length: ' . strlen($output));
         pb_backupbuddy::flush();
         echo $output;
         pb_backupbuddy::flush();
         // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER!
     } else {
         // Write to file.
         pb_backupbuddy::status('details', 'Writing importbuddy master file to disk.');
         if (false === file_put_contents($output_file, $output)) {
             pb_backupbuddy::status('error', 'Error #483894: Unable to write to file `' . $output_file . '`.');
             return false;
         } else {
             return true;
         }
     }
 }
Esempio n. 8
0
 public static function importbuddy($output_file = '', $importbuddy_pass_hash = '')
 {
     if (defined('PB_DEMO_MODE')) {
         echo 'Access denied in demo mode.';
         return;
     }
     pb_backupbuddy::set_greedy_script_limits();
     // Some people run out of PHP memory.
     if ($importbuddy_pass_hash == '') {
         if (!isset(pb_backupbuddy::$options)) {
             pb_backupbuddy::load();
         }
         $importbuddy_pass_hash = pb_backupbuddy::$options['importbuddy_pass_hash'];
     }
     if ($importbuddy_pass_hash == '') {
         $message = 'Error #9032: Warning only - You have not set a password to generate the ImportBuddy script yet on the BackupBuddy Settings page. If you are creating a backup, the importbuddy.php restore script will not be included in the backup. You can download it from the Restore page.  If you were trying to download ImportBuddy then you may have a plugin confict preventing the page from prompting you to enter a password.';
         pb_backupbuddy::status('warning', $message);
         return false;
     }
     $output = file_get_contents(pb_backupbuddy::plugin_path() . '/_importbuddy/_importbuddy.php');
     if ($importbuddy_pass_hash != '') {
         $output = preg_replace('/#PASSWORD#/', $importbuddy_pass_hash, $output, 1);
         // Only replaces first instance.
     }
     $output = preg_replace('/#VERSION#/', pb_backupbuddy::settings('version'), $output, 1);
     // Only replaces first instance.
     // PACK IMPORTBUDDY
     $_packdata = array('_importbuddy/importbuddy' => 'importbuddy', 'classes/_migrate_database.php' => 'importbuddy/classes/_migrate_database.php', 'classes/core.php' => 'importbuddy/classes/core.php', 'classes/import.php' => 'importbuddy/classes/import.php', 'images/working.gif' => 'importbuddy/images/working.gif', 'images/bullet_go.png' => 'importbuddy/images/bullet_go.png', 'images/favicon.png' => 'importbuddy/images/favicon.png', 'images/sort_down.png' => 'importbuddy/images/sort_down.png', 'lib/dbreplace' => 'importbuddy/lib/dbreplace', 'lib/dbimport' => 'importbuddy/lib/dbimport', 'lib/commandbuddy' => 'importbuddy/lib/commandbuddy', 'lib/zipbuddy' => 'importbuddy/lib/zipbuddy', 'lib/mysqlbuddy' => 'importbuddy/lib/mysqlbuddy', 'lib/textreplacebuddy' => 'importbuddy/lib/textreplacebuddy', 'lib/cpanel' => 'importbuddy/lib/cpanel', 'pluginbuddy' => 'importbuddy/pluginbuddy', 'controllers/pages/server_info' => 'importbuddy/controllers/pages/server_info', 'controllers/pages/server_info.php' => 'importbuddy/controllers/pages/server_info.php', 'destinations/stash/lib/class.itx_helper.php' => 'importbuddy/classes/class.itx_helper.php', 'destinations/_s3lib/aws-sdk/lib/requestcore' => 'importbuddy/lib/requestcore');
     $output .= "\n<?php /*\n###PACKDATA,BEGIN\n";
     foreach ($_packdata as $pack_source => $pack_destination) {
         $pack_source = '/' . $pack_source;
         if (is_dir(pb_backupbuddy::plugin_path() . $pack_source)) {
             $files = pb_backupbuddy::$filesystem->deepglob(pb_backupbuddy::plugin_path() . $pack_source);
         } else {
             $files = array(pb_backupbuddy::plugin_path() . $pack_source);
         }
         foreach ($files as $file) {
             if (is_file($file)) {
                 $source = str_replace(pb_backupbuddy::plugin_path(), '', $file);
                 $destination = $pack_destination . substr($source, strlen($pack_source));
                 $output .= "###PACKDATA,FILE_START,{$source},{$destination}\n";
                 $output .= base64_encode(file_get_contents($file));
                 $output .= "\n";
                 $output .= "###PACKDATA,FILE_END,{$source},{$destination}\n";
             }
         }
     }
     $output .= "###PACKDATA,END\n*/";
     $output .= "\n\n\n\n\n\n\n\n\n\n";
     if ($output_file == '') {
         // No file so output to browser.
         header('Content-Description: File Transfer');
         header('Content-Type: text/plain; name=importbuddy.php');
         header('Content-Disposition: attachment; filename=importbuddy.php');
         header('Expires: 0');
         header('Content-Length: ' . strlen($output));
         flush();
         echo $output;
         flush();
         // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER!
     } else {
         // Write to file.
         file_put_contents($output_file, $output);
     }
 }
Esempio n. 9
0
/**
 *	import_database()
 *
 *	Parses various submitted options and settings from step 1.
 *
 *	@return		array		array( import_success, import_complete ).
 *							import_success: false if unable to import into database, true if import is working thus far/completed.
 *							import_complete: If incomplete, an integer of the next query to begin on. If complete, true. False if import_success = false.
 */
function import_database()
{
    pb_backupbuddy::set_greedy_script_limits();
    // Migrate htaccess.
    pb_backupbuddy::$classes['import']->migrate_htaccess();
    if (true === pb_backupbuddy::$options['skip_database_import']) {
        pb_backupbuddy::status('message', 'Skipping database restore based on settings.');
        return array(true, true);
    }
    pb_backupbuddy::status('message', 'Verifying database connection and settings...');
    if (pb_backupbuddy::$classes['import']->connect_database() === false) {
        pb_backupbuddy::alert('ERROR: Unable to select your specified database. Verify the database name and that you have set up proper permissions for your specified username to access it. Details: ' . mysql_error(), true, '9007');
        return array(false, false);
    } else {
        pb_backupbuddy::status('message', 'Database connection and settings verified. Connected to database `' . pb_backupbuddy::$options['db_name'] . '`.');
        // Import database unless disabled.
        $db_continue = false;
        // Wipe database with matching prefix if option was selected.
        if (pb_backupbuddy::$options['wipe_database'] == true) {
            if (isset($_POST['db_continue']) && is_numeric($_POST['db_continue'])) {
                // do nothing
            } else {
                // dont wipe on substeps of db import.
                pb_backupbuddy::status('message', 'Wiping existing database tables with the same prefix based on settings...');
                $failed = !pb_backupbuddy::$classes['import']->wipe_database(pb_backupbuddy::$options['db_prefix']);
                if (false !== $failed) {
                    pb_backupbuddy::message('error', 'Unable to wipe database as configured in the settings.');
                    pb_backupbuddy::alert('Unable to wipe database as configured in the settings.', true);
                }
            }
        }
        // Wipe database of ALL TABLES if option was selected.
        if (pb_backupbuddy::$options['wipe_database_all'] == true) {
            if (isset($_POST['db_continue']) && is_numeric($_POST['db_continue'])) {
                // do nothing
            } else {
                // dont wipe on substeps of db import.
                pb_backupbuddy::status('message', 'Wiping ALL existing database tables based on settings (use with caution)...');
                $failed = !pb_backupbuddy::$classes['import']->wipe_database_all(true);
                if (false !== $failed) {
                    pb_backupbuddy::message('error', 'Unable to wipe database as configured in the settings.');
                    pb_backupbuddy::alert('Unable to wipe database as configured in the settings.', true);
                }
            }
        }
        // Sanitize db continuation value if needed.
        if (isset($_POST['db_continue']) && is_numeric($_POST['db_continue'])) {
            // do nothing
        } else {
            $_POST['db_continue'] = 0;
        }
        // Look through and try to find .SQL file to import.
        $possible_sql_files = array(ABSPATH . 'wp-content/uploads/temp_' . pb_backupbuddy::$options['zip_id'] . '/db.sql', ABSPATH . 'db.sql', ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/db_1.sql', ABSPATH . 'db_1.sql');
        if (!defined('PB_STANDALONE')) {
            // When in WordPress add import paths also.
            $possible_sql_files[] = ABSPATH . 'wp-content/uploads/backupbuddy_temp/import_' . pb_backupbuddy::$options['zip_id'] . '/wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/db_1.sql';
            // Multisite import >= 2.0.
            $possible_sql_files[] = pb_backupbuddy::$options['database_directory'] . 'db_1.sql';
            // Multisite import >= v2.0.
        }
        $sql_file = '';
        foreach ($possible_sql_files as $possible_sql_file) {
            // Check each file location to see which hits.
            if (file_exists($possible_sql_file)) {
                $sql_file = $possible_sql_file;
                // Set SQL file location.
                break;
                // Search is over. Use ths found file.
            }
        }
        // End foreach().
        unset($possible_sql_files);
        if ($sql_file == '') {
            pb_backupbuddy::status('error', 'Unable to find db_1.sql or other expected database file in the extracted files. Make sure you did not rename your backup ZIP file. You may manually restore your SQL file if you can find it via phpmyadmin or similar tool then on Step 1 of ImportBuddy select the advanced option to skip database import. This will allow you to proceed.');
        }
        // Whether or not to ignore existing tables errors.
        if (pb_backupbuddy::$options['ignore_sql_errors'] != false) {
            $ignore_existing = true;
        } else {
            $ignore_existing = false;
        }
        /********** Start mysqlbuddy use **********/
        $force_mysqlbuddy_methods = array();
        // Default, not forcing of methods.
        if (pb_backupbuddy::$options['mysqlbuddy_compatibility'] != false) {
            // mysqldump compatibility mode.
            $force_mysqlbuddy_methods = array('php');
        }
        require_once pb_backupbuddy::plugin_path() . '/lib/mysqlbuddy/mysqlbuddy.php';
        pb_backupbuddy::$classes['mysqlbuddy'] = new pb_backupbuddy_mysqlbuddy(pb_backupbuddy::$options['db_server'], pb_backupbuddy::$options['db_name'], pb_backupbuddy::$options['db_user'], pb_backupbuddy::$options['db_password'], pb_backupbuddy::$options['db_prefix'], $force_mysqlbuddy_methods);
        // $database_host, $database_name, $database_user, $database_pass, $old_prefix, $force_method = array()
        $import_result = pb_backupbuddy::$classes['mysqlbuddy']->import($sql_file, pb_backupbuddy::$options['dat_file']['db_prefix'], $_POST['db_continue'], $ignore_existing);
        /********** End mysqlbuddy use **********/
        if (true === $import_result) {
            // Fully finished successfully.
            return array(true, true);
        } elseif (false === $import_result) {
            // Full failure.
            return array(false, false);
        } else {
            // Needs to chunk up DB import and continue...
            //$db_continue = true;
            // Continue on query $import_result...
            pb_backupbuddy::status('message', 'Next step will begin import on query ' . $import_result . '.');
            return array(true, $import_result);
        }
    }
}
Esempio n. 10
0
/**
 *	extract()
 *
 *	Extract backup zip file.
 *
 *	@return		array		True if the extraction was a success OR skipping of extraction is set.
 */
function extract_files()
{
    // Zip & Unzip library setup.
    require_once ABSPATH . 'importbuddy/lib/zipbuddy/zipbuddy.php';
    pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(ABSPATH, array(), 'unzip');
    $backup_archive = ABSPATH . pb_backupbuddy::$options['file'];
    if (true === pb_backupbuddy::$options['skip_files']) {
        // Option to skip all file updating / extracting.
        pb_backupbuddy::status('message', 'Skipped extracting files based on debugging options.');
    } else {
        pb_backupbuddy::set_greedy_script_limits();
        pb_backupbuddy::status('message', 'Unzipping into `' . ABSPATH . '`');
        $destination_directory = ABSPATH;
        // Set compatibility mode if defined in advanced options.
        $compatibility_mode = false;
        // Default to no compatibility mode.
        if (pb_backupbuddy::$options['force_compatibility_medium'] != false) {
            $compatibility_mode = 'ziparchive';
        } elseif (pb_backupbuddy::$options['force_compatibility_slow'] != false) {
            $compatibility_mode = 'pclzip';
        }
        // Extract zip file & verify it worked.
        if (true !== ($result = pb_backupbuddy::$classes['zipbuddy']->unzip($backup_archive, $destination_directory, $compatibility_mode))) {
            pb_backupbuddy::status('error', 'Failed unzipping archive.');
            pb_backupbuddy::alert('Failed unzipping archive.', true);
            return false;
        }
        pb_backupbuddy::status('details', 'Success extracting Zip File "' . ABSPATH . pb_backupbuddy::$options['file'] . '" into "' . ABSPATH . '".');
    }
    // End extraction not skipped.
    // Made it here so zip returned true OR skipped unzip step.
    // Handle meta data in comment.
    pb_backupbuddy::status('details', 'Retrieving meta data from ZIP file (if any).');
    $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($backup_archive);
    $comment = pb_backupbuddy::$classes['core']->normalize_comment_data($comment);
    $comment_text = print_r($comment, true);
    $comment_text = str_replace(array("\n", "\r"), '; ', $comment_text);
    pb_backupbuddy::status('details', 'Backup meta data: `' . $comment_text . '`.');
    // Use meta to find DAT file (if possible). BB v3.3+.
    $dat_file = '';
    if ('' != $comment['dat_path']) {
        // Specific DAT location is known.
        pb_backupbuddy::status('details', 'Checking for DAT file as reported by meta data as file `' . ABSPATH . $comment['dat_path'] . '`.');
        if (file_exists(ABSPATH . $comment['dat_path'])) {
            $dat_file = ABSPATH . $comment['dat_path'];
            pb_backupbuddy::status('details', 'DAT file found based on meta path.');
        } else {
            pb_backupbuddy::status('warning', 'DAT file was not found as reported by meta data. This is unusual but may not be fatal. Commencing search for file...');
        }
    }
    // Deduce DAT file location based on backup filename. BB < v3.3.
    if ('' == $dat_file) {
        pb_backupbuddy::status('details', 'Scanning for DAT file based on backup file name.');
        $dat_file_locations = array(ABSPATH . 'wp-content/uploads/temp_' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php', ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php', ABSPATH . 'backupbuddy_dat.php');
        $dat_file = '';
        foreach ($dat_file_locations as $dat_file_location) {
            if (file_exists($dat_file_location)) {
                $dat_file = $dat_file_location;
                break;
            }
        }
        if ('' == $dat_file) {
            // DAT not found.
            $error_message = 'Error #9004: Key files missing. Backup data file, backupbuddy_dat.php was not found in the extracted files in any expected location. The unzip process either failed to fully complete, you renamed the backup ZIP file (rename it back to correct this), or the zip file is not a proper BackupBuddy backup.';
            pb_backupbuddy::status('error', $error_message);
            pb_backupbuddy::alert($error_message, true, '9004');
            return false;
        }
        pb_backupbuddy::status('details', 'Successfully found DAT file based on backup file name: `' . $dat_file . '`.');
    }
    // Get DAT file contents & save into options..
    pb_backupbuddy::$options['dat_file'] = pb_backupbuddy::$classes['import']->get_dat_file_array($dat_file);
    pb_backupbuddy::save();
    return true;
}
Esempio n. 11
0
 public function icicle()
 {
     pb_backupbuddy::set_greedy_script_limits();
     // Building the directory tree can take a bit.
     if (!isset(pb_backupbuddy::$classes['core'])) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
         pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core();
     }
     $response = pb_backupbuddy::$classes['core']->build_icicle(ABSPATH, ABSPATH, '', -1);
     echo $response[0];
     die;
 }
Esempio n. 12
0
 function process_ftp_copy($backup, $ftp_server, $ftp_username, $ftp_password, $ftp_directory)
 {
     pb_backupbuddy::set_greedy_script_limits();
     // connect to server
     $conn_id = ftp_connect($ftp_server) or die('Could not connect to ' . $ftp_server);
     // login with username and password
     $login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
     // try to download $server_file and save to $local_file
     $destination_file = ABSPATH . 'wp-content/uploads/backupbuddy_backups/' . $backup;
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     if (ftp_get($conn_id, $destination_file, $ftp_directory . $backup, FTP_BINARY)) {
         pb_backupbuddy::status('message', 'Successfully wrote remote file locally to `' . $destination_file . '`.');
     } else {
         pb_backupbuddy::status('error', 'Error writing remote file locally to `' . $destination_file . '`.');
     }
     // close this connection
     ftp_close($conn_id);
 }
Esempio n. 13
0
 public static function process_backup($serial = 'blank')
 {
     pb_backupbuddy::set_status_serial($serial);
     pb_backupbuddy::status('details', '--- New PHP process.');
     pb_backupbuddy::set_greedy_script_limits();
     pb_backupbuddy::status('message', 'Running process for serial `' . $serial . '`...');
     require_once pb_backupbuddy::plugin_path() . '/classes/backup.php';
     $newBackup = new pb_backupbuddy_backup();
     return $newBackup->process_backup($serial);
 }