Example #1
0
if (!$license_active || 'expired' == $license_status) {
    $schedule_style_disabled = 'disabled';
}
//Make sure backup folder exists
$backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
$backup_folder_exists = false;
if (!is_dir($backup_dir)) {
    if (@mkdir($backup_dir, 0755)) {
        $backup_folder_exists = true;
    }
} else {
    $backup_folder_exists = true;
}
//Cleanup old backups - this can be removed in a few months.
//Get Zip File List
$file_system = new WPBackItUp_FileSystem($logger);
$file_list = $file_system->get_fileonly_list($backup_folder_root, 'zip|log');
//If there are zip files then move them into their own folders
$logger->log_info(__METHOD__, 'Files in backup folder: ' . var_export($file_list, true));
$logger->log_info(__METHOD__, 'Last Error: ' . var_export(error_get_last(), true));
if (null != $file_list) {
    foreach ($file_list as $file) {
        //remove the suffix
        $file_name = substr(basename($file), 0, -4);
        //strip off the suffix IF one exists
        $folder_name = $file_name;
        if (($str_pos = strpos($folder_name, '-main-')) !== false) {
            $suffix = substr($folder_name, $str_pos);
            $folder_name = str_replace($suffix, '', $folder_name);
        }
        if (($str_pos = strpos($folder_name, '-others-')) !== false) {
 public function rename_folder($from_folder_name, $to_folder_name)
 {
     $this->logger->log_info(__METHOD__, 'Begin');
     $this->logger->log_info(__METHOD__, 'Rename from folder name:' . $from_folder_name);
     $this->logger->log_info(__METHOD__, 'Rename to folder name: ' . $to_folder_name);
     $file_system = new WPBackItUp_FileSystem($this->logger);
     if (!$file_system->rename_file($from_folder_name, $to_folder_name)) {
         $this->logger->log_error(__METHOD__, 'Folder could not be renamed');
         return false;
     }
     $this->logger->log_info(__METHOD__, 'End');
     return true;
 }
function get_response_file()
{
    global $logger;
    $response_file_path = WPBACKITUP__PLUGIN_PATH . 'logs/backup_response.log';
    $filesytem = new WPBackItUp_FileSystem($logger);
    return $filesytem->get_file_handle($response_file_path, false);
}
 $logger->log('**END CLEAN DELETED BACKUPS**');
 $logger->log('**CLEAN OLD BACKUPS**');
 //Cleanup any folders that exceed retention limit
 $wp_backup->cleanup_old_backups();
 $logger->log('**END CLEAN OLD BACKUPS**');
 $logger->log('**CLEAN OLD RESTORES**');
 //Cleanup any folders that exceed retention limit
 $wp_restore = new WPBackItUp_Restore($logger, $job_name, null);
 $wp_restore->delete_restore_folder();
 $logger->log('**END CLEAN OLD RESTORES**');
 $logger->log('**PURGE OLD FILES**');
 $wp_backup->purge_old_files();
 $logger->log('**END PURGE OLD FILES**');
 $logger->log('**SECURE FOLDERS**');
 //Make sure backup folder is secured
 $file_system = new WPBackItUp_FileSystem();
 //Make sure backup folder is secured
 $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
 $file_system->secure_folder($backup_dir);
 //--Check restore folder folders
 $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
 $file_system->secure_folder($restore_dir);
 //Make sure logs folder is secured
 $logs_dir = WPBACKITUP__PLUGIN_PATH . '/logs/';
 $file_system->secure_folder($logs_dir);
 $logger->log('**END SECURE FOLDERS**');
 $logger->log('**CLEANUP OLD JOBS**');
 $backup_job_purge_count = WPBackItUp_Job_v2::purge_completed_jobs('backup');
 $logger->log('Backup job records purged:' . $backup_job_purge_count);
 $cleanup_job_purge_count = WPBackItUp_Job_v2::purge_completed_jobs('cleanup');
 $logger->log('Cleanup job records purged:' . $cleanup_job_purge_count);
 /**
  * Activation action -  will run ONLY on activation
  */
 public static function activate()
 {
     try {
         //add cron task for once per hour starting in 1 hour
         if (!wp_next_scheduled('wpbackitup_queue_scheduled_jobs')) {
             wp_schedule_event(time() + 3600, 'hourly', 'wpbackitup_queue_scheduled_jobs');
         }
         require_once WPBACKITUP__PLUGIN_PATH . '/lib/includes/class-filesystem.php';
         $file_system = new WPBackItUp_FileSystem();
         //Check backup folder folders
         $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
         $file_system->secure_folder($backup_dir);
         //--Check restore folder folders
         $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
         $file_system->secure_folder($restore_dir);
         $logs_dir = WPBACKITUP__PLUGIN_PATH . '/logs/';
         $file_system->secure_folder($logs_dir);
         //Make sure they exist now
         if (!is_dir($backup_dir) || !is_dir($restore_dir)) {
             exit('WP BackItUp was not able to create the required backup and restore folders.');
         }
         //Run database update routines
         self::maybe_update();
         do_action('wpbackitup_check_license', true);
     } catch (Exception $e) {
         exit('WP BackItUp encountered an error during activation.</br>' . $e->getMessage());
     }
 }
function get_restore_Log()
{
    global $logger;
    $status_file_path = WPBACKITUP__PLUGIN_PATH . '/logs/restore_status.log';
    $filesystem = new WPBackItUp_FileSystem($logger);
    return $filesystem->get_file_handle($status_file_path);
}