Beispiel #1
0
 /**
  * Creates the backup archive
  */
 private function create_archive()
 {
     //load folders to backup
     $folders_to_backup = $this->get_folders_to_backup();
     $this->substeps_todo = $this->count_folder + 1;
     //initial settings for restarts in archiving
     if (!isset($this->steps_data[$this->step_working]['on_file'])) {
         $this->steps_data[$this->step_working]['on_file'] = '';
     }
     if (!isset($this->steps_data[$this->step_working]['on_folder'])) {
         $this->steps_data[$this->step_working]['on_folder'] = '';
     }
     if ($this->steps_data[$this->step_working]['on_folder'] == '' && $this->steps_data[$this->step_working]['on_file'] == '' && is_file($this->backup_folder . $this->backup_file)) {
         unlink($this->backup_folder . $this->backup_file);
     }
     if ($this->steps_data[$this->step_working]['SAVE_STEP_TRY'] != $this->steps_data[$this->step_working]['STEP_TRY']) {
         $this->log(sprintf(__('%d. Trying to create backup archive …', 'backwpup'), $this->steps_data[$this->step_working]['STEP_TRY']), E_USER_NOTICE);
     }
     try {
         $backup_archive = new BackWPup_Create_Archive($this->backup_folder . $this->backup_file);
         //show method for creation
         if ($this->substeps_done == 0) {
             $this->log(sprintf(_x('Compressing files as %s. Please be patient, this may take a moment.', 'Archive compression method', 'backwpup'), $backup_archive->get_method()));
         }
         //add extra files
         if ($this->substeps_done == 0) {
             if (!empty($this->additional_files_to_backup) && $this->substeps_done == 0) {
                 if ($this->is_debug()) {
                     $this->log(__('Adding Extra files to Archive', 'backwpup'));
                 }
                 foreach ($this->additional_files_to_backup as $file) {
                     if ($backup_archive->add_file($file, basename($file))) {
                         $this->count_files++;
                         $this->count_files_size = $this->count_files_size + filesize($file);
                         $this->update_working_data();
                     } else {
                         $backup_archive->close();
                         $this->steps_data[$this->step_working]['on_file'] = '';
                         $this->steps_data[$this->step_working]['on_folder'] = '';
                         $this->log(__('Cannot create backup archive correctly. Aborting creation.', 'backwpup'), E_USER_ERROR);
                         return false;
                     }
                 }
             }
             $this->substeps_done++;
         }
         //add normal files
         while ($folder = array_shift($folders_to_backup)) {
             //jump over already done folders
             if (in_array($this->steps_data[$this->step_working]['on_folder'], $folders_to_backup, true)) {
                 continue;
             }
             if ($this->is_debug()) {
                 $this->log(sprintf(__('Archiving Folder: %s', 'backwpup'), $folder));
             }
             $this->steps_data[$this->step_working]['on_folder'] = $folder;
             $files_in_folder = $this->get_files_in_folder($folder);
             //add empty folders
             if (empty($files_in_folder)) {
                 $folder_name_in_archive = trim(ltrim($this->get_destination_path_replacement($folder), '/'));
                 if (!empty($folder_name_in_archive)) {
                     $backup_archive->add_empty_folder($folder, $folder_name_in_archive);
                 }
                 continue;
             }
             //add files
             while ($file = array_shift($files_in_folder)) {
                 //jump over already done files
                 if (in_array($this->steps_data[$this->step_working]['on_file'], $files_in_folder, true)) {
                     continue;
                 }
                 $this->steps_data[$this->step_working]['on_file'] = $file;
                 //restart if needed
                 $restart_time = $this->get_restart_time();
                 if ($restart_time <= 0) {
                     unset($backup_archive);
                     $this->do_restart_time(true);
                     return false;
                 }
                 //generate filename in archive
                 $in_archive_filename = ltrim($this->get_destination_path_replacement($file), '/');
                 //add file to archive
                 if ($backup_archive->add_file($file, $in_archive_filename)) {
                     $this->count_files++;
                     $this->count_files_size = $this->count_files_size + filesize($file);
                     $this->update_working_data();
                 } else {
                     $backup_archive->close();
                     unset($backup_archive);
                     $this->steps_data[$this->step_working]['on_file'] = '';
                     $this->steps_data[$this->step_working]['on_folder'] = '';
                     $this->substeps_done = 0;
                     $this->backup_filesize = filesize($this->backup_folder . $this->backup_file);
                     if ($this->backup_filesize === false) {
                         $this->backup_filesize = PHP_INT_MAX;
                     }
                     $this->log(__('Cannot create backup archive correctly. Aborting creation.', 'backwpup'), E_USER_ERROR);
                     return false;
                 }
             }
             $this->steps_data[$this->step_working]['on_file'] = '';
             $this->substeps_done++;
         }
         $backup_archive->close();
         unset($backup_archive);
         $this->log(__('Backup archive created.', 'backwpup'), E_USER_NOTICE);
     } catch (Exception $e) {
         $this->log($e->getMessage(), E_USER_ERROR, $e->getFile(), $e->getLine());
         unset($backup_archive);
         return false;
     }
     $this->backup_filesize = filesize($this->backup_folder . $this->backup_file);
     if ($this->backup_filesize === false) {
         $this->backup_filesize = PHP_INT_MAX;
     }
     if ($this->backup_filesize >= PHP_INT_MAX) {
         $this->log(__('The Backup archive will be too large for file operations with this PHP Version. You might want to consider splitting the backup job in multiple jobs with less files each.', 'backwpup'), E_USER_ERROR);
         $this->end();
     } else {
         $this->log(sprintf(__('Archive size is %s.', 'backwpup'), size_format($this->backup_filesize, 2)), E_USER_NOTICE);
     }
     $this->log(sprintf(__('%1$d Files with %2$s in Archive.', 'backwpup'), $this->count_files, size_format($this->count_files_size, 2)), E_USER_NOTICE);
     return true;
 }
 /**
  * Creates the backup archive
  */
 private function create_archive()
 {
     //load folders to backup
     $folders_to_backup = $this->get_folders_to_backup();
     $this->substeps_todo = $this->count_folder + 1;
     //initial settings for restarts in archiving
     if (!isset($this->steps_data[$this->step_working]['on_file'])) {
         $this->steps_data[$this->step_working]['on_file'] = '';
     }
     if (!isset($this->steps_data[$this->step_working]['on_folder'])) {
         $this->steps_data[$this->step_working]['on_folder'] = '';
     }
     if ($this->steps_data[$this->step_working]['on_folder'] == '' && $this->steps_data[$this->step_working]['on_file'] == '' && is_file($this->backup_folder . $this->backup_file)) {
         unlink($this->backup_folder . $this->backup_file);
     }
     if ($this->steps_data[$this->step_working]['SAVE_STEP_TRY'] != $this->steps_data[$this->step_working]['STEP_TRY']) {
         $this->log(sprintf(__('%d. Trying to create backup archive &hellip;', 'backwpup'), $this->steps_data[$this->step_working]['STEP_TRY']), E_USER_NOTICE);
     }
     try {
         $backup_archive = new BackWPup_Create_Archive($this->backup_folder . $this->backup_file);
         //show method for creation
         if ($this->substeps_done == 0) {
             $this->log(sprintf(_x('Compressing files as %s. Please be patient, this may take a moment.', 'Archive compression method', 'backwpup'), $backup_archive->get_method()));
         }
         //add extra files
         if ($this->substeps_done == 0) {
             if (!empty($this->additional_files_to_backup) && $this->substeps_done == 0) {
                 foreach ($this->additional_files_to_backup as $file) {
                     if ($backup_archive->add_file($file, basename($file))) {
                         $this->count_files++;
                         $this->count_filesize = filesize($file);
                         $this->update_working_data();
                     } else {
                         $backup_archive->close();
                         $this->steps_data[$this->step_working]['on_file'] = '';
                         $this->steps_data[$this->step_working]['on_folder'] = '';
                         $this->log(__('Cannot create backup archive correctly. Aborting creation.', 'backwpup'), E_USER_ERROR);
                         return FALSE;
                     }
                 }
             }
             $this->substeps_done++;
         }
         //add normal files
         while ($folder = array_shift($folders_to_backup)) {
             //jump over already done folders
             if (in_array($this->steps_data[$this->step_working]['on_folder'], $folders_to_backup)) {
                 continue;
             }
             $this->steps_data[$this->step_working]['on_folder'] = $folder;
             $files_in_folder = $this->get_files_in_folder($folder);
             //add empty folders
             if (empty($files_in_folder)) {
                 $folder_name_in_archive = trim(ltrim(str_replace($this->remove_path, '', $folder), '/'));
                 if (!empty($folder_name_in_archive)) {
                     $backup_archive->add_empty_folder($folder, $folder_name_in_archive);
                 }
                 continue;
             }
             //add files
             while ($file = array_shift($files_in_folder)) {
                 //jump over already done files
                 if (in_array($this->steps_data[$this->step_working]['on_file'], $files_in_folder)) {
                     continue;
                 }
                 $this->steps_data[$this->step_working]['on_file'] = $file;
                 //close archive before restart
                 $restart_time = $this->get_restart_time();
                 if ($restart_time < 0) {
                     unset($backup_archive);
                     $this->do_restart_time(TRUE);
                 }
                 //generate filename in archive
                 $in_archive_filename = ltrim(str_replace($this->remove_path, '', $file), '/');
                 //add file to archive
                 if ($backup_archive->add_file($file, $in_archive_filename)) {
                     $this->update_working_data();
                 } else {
                     $backup_archive->close();
                     $this->steps_data[$this->step_working]['on_file'] = '';
                     $this->steps_data[$this->step_working]['on_folder'] = '';
                     $this->substeps_done = 0;
                     $this->backup_filesize = filesize($this->backup_folder . $this->backup_file);
                     if ($this->backup_filesize + filesize($file) >= 2147483647) {
                         $this->log(__('Aborting creation.', 'backwpup'), E_USER_ERROR);
                         return TRUE;
                     }
                     $this->log(__('Cannot create backup archive correctly. Aborting creation.', 'backwpup'), E_USER_ERROR);
                     return FALSE;
                 }
             }
             $this->steps_data[$this->step_working]['on_file'] = '';
             $this->substeps_done++;
         }
         //restart if needed
         $restart_time = $this->get_restart_time();
         if ($restart_time < 5) {
             unset($backup_archive);
             $this->do_restart_time(TRUE);
         }
         $backup_archive->close();
         unset($backup_archive);
         $this->log(__('Backup archive created.', 'backwpup'), E_USER_NOTICE);
     } catch (Exception $e) {
         $this->log($e->getMessage(), E_USER_ERROR, $e->getFile(), $e->getLine());
         unset($backup_archive);
         return FALSE;
     }
     $this->backup_filesize = filesize($this->backup_folder . $this->backup_file);
     if ($this->backup_filesize) {
         $this->log(sprintf(__('Archive size is %s.', 'backwpup'), size_format($this->backup_filesize, 2)), E_USER_NOTICE);
     }
     $this->log(sprintf(__('%1$d Files with %2$s in Archive.', 'backwpup'), $this->count_files + $this->count_files_in_folder, size_format($this->count_filesize + $this->count_filesize_in_folder, 2)), E_USER_NOTICE);
     return TRUE;
 }