Exemplo n.º 1
0
 function Initialise_Backup(&$bootstrap, &$progress, &$next_step)
 {
     global $wpdb;
     // First of all, clean up everything from last backup
     if ($progress['initialise'] < ++$next_step) {
         $this->CleanUp();
         $progress['initialise'] = $next_step;
         $bootstrap->Tick();
     }
     // First of all, clear back activity logs
     if ($progress['initialise'] < ++$next_step) {
         do {
             if (($ret = $wpdb->query('DELETE a, e FROM `' . $this->db_prefix . 'wponlinebackup_activity_log` a ' . 'LEFT JOIN `' . $this->db_prefix . 'wponlinebackup_event_log` e ON (e.activity_id = a.activity_id) ' . 'WHERE a.start < ' . strtotime('-' . $this->WPOnlineBackup->Get_Setting('max_log_age') . ' months', $progress['start_time']))) === false) {
                 return $bootstrap->DBError(__LINE__, __FILE__);
             }
             // Before the Tick so we skip completely if we're done
             if (!$ret) {
                 $progress['initialise'] = $next_step;
             }
             $bootstrap->Tick();
         } while ($ret);
     }
     if ($progress['initialise'] < ++$next_step) {
         // If online, add a synchronisation job
         if ($progress['config']['target'] == 'online') {
             $progress['jobs'][] = array('processor' => 'transmission', 'progress' => 0, 'progresslen' => 5, 'retries' => 0, 'action' => 'synchronise', 'total_items' => 0, 'total_generations' => 0, 'done_items' => 0, 'done_generations' => 0);
         }
         $progress['initialise'] = $next_step;
         $bootstrap->Tick();
     }
     if ($progress['initialise'] < ++$next_step) {
         // Are we backing up the database?
         if ($progress['config']['backup_database']) {
             require_once WPONLINEBACKUP_PATH . '/include/tables.php';
             $tables = new WPOnlineBackup_Backup_Tables($this->WPOnlineBackup, $this->db_force_master);
             // Initialise - pass ourself so we can log events, and also pass the progress and its tracker
             if (true !== ($ret = $tables->Initialise($this, $progress))) {
                 return $ret;
             }
         }
         $progress['initialise'] = $next_step;
         $bootstrap->Tick();
     }
     if ($progress['initialise'] < ++$next_step) {
         // Are we backing up the filesystem?
         if ($progress['config']['backup_filesystem']) {
             require_once WPONLINEBACKUP_PATH . '/include/files.php';
             $files = new WPOnlineBackup_Backup_Files($this->WPOnlineBackup, $this->db_force_master);
             // Initialise - pass ourselves so we can log events, and also pass the progress and its tracker
             if (true !== ($ret = $files->Initialise($this, $progress))) {
                 return $ret;
             }
         }
         $progress['initialise'] = $next_step;
         $bootstrap->Tick();
     }
     if ($progress['initialise'] < ++$next_step) {
         // Reconstruct the data files
         $progress['jobs'][] = array('processor' => 'reconstruct', 'progress' => 0, 'progresslen' => 5);
         if ($progress['config']['target'] == 'online') {
             // Online needs to transmit
             $progress['jobs'][] = array('processor' => 'transmission', 'progress' => 0, 'progresslen' => 10, 'retries' => 0, 'action' => 'transmit', 'total' => 0, 'done' => 0, 'done_retention' => 0, 'retention_size' => 0, 'new_bsn' => 0, 'wait' => false);
         } else {
             if ($progress['config']['target'] == 'email') {
                 // Email needs to email
                 $progress['jobs'][] = array('processor' => 'email', 'progress' => 0, 'progresslen' => 10, 'retries' => 0);
             }
         }
         // Add the cleanups to the end of the job list so they happen only after the main backup jobs have finished
         $progress['jobs'] = array_merge($progress['jobs'], $progress['cleanups']);
         $progress['cleanups'] = array();
         // Add on the file cleanup - this places local backups in their correct place and deletes files for online backup etc.
         $progress['jobs'][] = array('processor' => 'cleanupfiles', 'progress' => 0, 'progresslen' => 5);
         // Retention for local backups should be done AFTER cleanupfiles, since cleanupfiles adds to the database the current backup and retention should take that into account
         if ($progress['config']['target'] == 'download') {
             // Local needs retention
             $progress['jobs'][] = array('processor' => 'localretention', 'progress' => 0, 'progresslen' => 5, 'deleted_gens' => 0, 'deleted_storage' => 0, 'delete_error' => 0);
         }
         // Total up the jobcount as total of all progresslens - makes calculating progress % easier
         foreach ($progress['jobs'] as $job) {
             $progress['jobcount'] += $job['progresslen'];
         }
         $progress['initialise'] = $next_step;
         $bootstrap->Tick();
     }
     if ($progress['initialise'] < ++$next_step) {
         if ($progress['config']['target'] == 'download') {
             // Create the local backup directory
             if (true !== ($ret = $bootstrap->Create_Dir_Local_Backup())) {
                 return $ret;
             }
         }
         // Try to create the temporary backup directory
         if (true !== ($ret = $bootstrap->Create_Dir_Temporary())) {
             return $ret;
         }
         $progress['initialise'] = $next_step;
         // Force a save here since we did some file operation checks and it'll save us doing it again
         $bootstrap->Tick(false, true);
     }
     // Prepare the stream configuration
     // - the streams use this configuration instead of the central configuration so we can use different settings in different streams
     $config = array('designated_path' => $progress['cache']['local_tmp_dir'], 'compression' => $this->WPOnlineBackup->Get_Env('deflate_available') ? 'DEFLATE' : 'store', 'encryption' => $progress['cache']['enc_type'], 'encryption_key' => $progress['cache']['enc_key']);
     // Set up the required stream
     if ($progress['config']['target'] == 'online') {
         $stream_type = 'Stream_Delta';
     } else {
         $stream_type = 'Stream_Full';
     }
     require_once WPONLINEBACKUP_PATH . '/include/' . strtolower($stream_type) . '.php';
     $name = 'WPOnlineBackup_' . $stream_type;
     $stream = new $name($this->WPOnlineBackup);
     // Open the file - suppress errors in html_entity_decode as PHP4 will flood out warnings about multibyte characters
     if (($ret = $stream->Open($config, @html_entity_decode(get_bloginfo('name'), ENT_QUOTES, get_bloginfo('charset')), @html_entity_decode(get_bloginfo('description'), ENT_QUOTES, get_bloginfo('charset')))) !== true) {
         return $bootstrap->Create_Failure();
     }
     if ($progress['config']['target'] == 'email') {
         // Check we aren't too big to process. Add 50% to the filesize to allow for MIME encoding and headers etc, and take 5MB from Memory_Limit for processing
         $max = floor((($memory_limit = $this->WPOnlineBackup->Memory_Limit()) - 5 * 1024 * 1024) / 2.5);
     }
     // Store the steam - we cannot store it in this->stream until it is Opened because we call CleanUp in On_Shutdown if an error occurs and CleanUp can not be called until after Open or Load
     $bootstrap->Set_Stream($stream_type, $stream);
     return true;
 }