/wp-content/plugins/updraftplus/updraftplus.php
PHP | 2438 lines | 1898 code | 265 blank | 275 comment | 496 complexity | 472068cefb4b0eec666fc93e24832b40 MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- Plugin Name: UpdraftPlus - Backup/Restore
- Plugin URI: http://updraftplus.com
- Description: Backup and restore: your content and database can be automatically backed up to Amazon S3, Dropbox, Google Drive, FTP or email, on separate schedules.
- Author: David Anderson
- Version: 1.4.14
- Donate link: http://david.dw-perspective.org.uk/donate
- License: GPLv3 or later
- Author URI: http://wordshell.net
- */
- /*
- TODO
- //Put in old-WP-version warning, and point them to where they can get help
- //Add SFTP, Box.Net, SugarSync and Microsoft Skydrive support??
- //The restorer has a hard-coded wp-content - fix
- //Change DB encryption to not require whole gzip in memory (twice)
- //improve error reporting / pretty up return messages in admin area. One thing: have a "backup is now finished" flag. Otherwise with the resuming things get ambiguous/confusing. See http://wordpress.org/support/topic/backup-status - user was not aware that backup completely failed. Maybe a "backup status" field for each nonce that gets updated? (Even via AJAX?)
- //?? On 'backup now', open up a Lightbox, count down 5 seconds, then start examining the log file (if it can be found)
- //Should make clear in dashboard what is a non-fatal error (i.e. can be retried) - leads to unnecessary bug reports
- // Move the inclusion, cloud and retention data into the backup job (i.e. don't read current config, make it an attribute of each job). In fact, everything should be. So audit all code for where get_option is called inside a backup run: it shouldn't happen.
- // Should we resume if the only errors were upon deletion (i.e. the backup itself was fine?) Presently we do, but it displays errors for the user to confuse them. Perhaps better to make pruning a separate scheuled task??
- // Warn the user if their zip-file creation is slooowww...
- // Create a "Want Support?" button/console, that leads them through what is needed, and performs some basic tests...
- // Resuming partial FTP uploads
- // Provide backup/restoration for UpdraftPlus's settings, to allow 'bootstrap' on a fresh WP install - some kind of single-use code which a remote UpdraftPlus can use to authenticate
- // Multiple jobs
- // Change FTP to use SSL by default
- // Chunked downloading of material for resumption + do resume it
- // Disk free-space display
- // Multisite add-on should allow restoring of each blog individually
- // When looking for files to delete, is the current encryption setting used? Should not be.
- // Create single zip, containing even WordPress itself
- // When a new backup starts, AJAX-update the 'Last backup' display in the admin page.
- // Remove the recurrence of admin notices when settings are saved due to _wp_referer
- // Auto-detect what the real execution time is (max_execution_time is just one of the upper limits, there can be others, some insivible directly), and tweak our resumption time accordingly
- Encrypt filesystem, if memory allows (and have option for abort if not); split up into multiple zips when needed
- // Does not delete old custom directories upon a restore?
- // New sub-module to verify that the backups are there, independently of backup thread
- */
- /* Portions copyright 2010 Paul Kehrer
- Portions copyright 2011-13 David Anderson
- Other portions copyright as indicated authors in the relevant files
- Particular thanks to Sorin Iclanzan, author of the "Backup" plugin, from which much Google Drive code was taken under the GPLv3+
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- // 15 minutes
- @set_time_limit(900);
- define('UPDRAFTPLUS_DIR', dirname(__FILE__));
- define('UPDRAFTPLUS_URL', plugins_url('', __FILE__));
- define('UPDRAFT_DEFAULT_OTHERS_EXCLUDE','upgrade,cache,updraft,index.php,backup,backups');
- // This is used in various places, based on our assumption of the maximum time any job should take. May need lengthening in future if we get reports which show enormous sets hitting the limit.
- // Also one section requires at least 1% progress each run, so on a 5-minute schedule, that equals just under 9 hours - then an extra allowance takes it just over
- define('UPDRAFT_TRANSTIME', 3600*9+5);
- // Load add-ons
- if (is_file(UPDRAFTPLUS_DIR.'/premium.php')) require_once(UPDRAFTPLUS_DIR.'/premium.php');
- if ($dir_handle = opendir(UPDRAFTPLUS_DIR.'/addons')) {
- while ($e = readdir($dir_handle)) {
- if (is_file(UPDRAFTPLUS_DIR.'/addons/'.$e) && preg_match('/\.php$/', $e)) {
- include_once(UPDRAFTPLUS_DIR.'/addons/'.$e);
- }
- }
- @closedir($dir_handle);
- }
- if (!isset($updraftplus)) $updraftplus = new UpdraftPlus();
- if (!$updraftplus->memory_check(192)) {
- # TODO: Better solution is to split the backup set into manageable chunks based on this limit
- @ini_set('memory_limit', '192M'); //up the memory limit for large backup files
- }
- if (!class_exists('UpdraftPlus_Options')) require_once(UPDRAFTPLUS_DIR.'/options.php');
- class UpdraftPlus {
- var $version;
- var $plugin_title = 'UpdraftPlus Backup/Restore';
- // Choices will be shown in the admin menu in the order used here
- var $backup_methods = array (
- "s3" => "Amazon S3",
- "dropbox" => "Dropbox",
- "googledrive" => "Google Drive",
- "ftp" => "FTP",
- "email" => "Email"
- );
- var $dbhandle;
- var $dbhandle_isgz;
- var $errors = array();
- var $nonce;
- var $logfile_name = "";
- var $logfile_handle = false;
- var $backup_time;
- var $opened_log_time;
- var $backup_dir;
- var $jobdata;
- // Used to schedule resumption attempts beyond the tenth, if needed
- var $current_resumption;
- var $newresumption_scheduled = false;
- var $zipfiles_added;
- var $zipfiles_existingfiles;
- var $zipfiles_dirbatched;
- var $zipfiles_batched;
- var $zip_preferpcl = false;
- function __construct() {
- // Initialisation actions - takes place on plugin load
- if ($fp = fopen( __FILE__, 'r')) {
- $file_data = fread( $fp, 1024 );
- if (preg_match("/Version: ([\d\.]+)(\r|\n)/", $file_data, $matches)) {
- $this->version = $matches[1];
- }
- fclose( $fp );
- }
- # Create admin page
- add_action('admin_init', array($this, 'admin_init'));
- add_action('updraft_backup', array($this,'backup_files'));
- add_action('updraft_backup_database', array($this,'backup_database'));
- # backup_all is used by the manual "Backup Now" button
- add_action('updraft_backup_all', array($this,'backup_all'));
- # this is our runs-after-backup event, whose purpose is to see if it succeeded or failed, and resume/mom-up etc.
- add_action('updraft_backup_resume', array($this,'backup_resume'), 10, 3);
- add_action('wp_ajax_updraft_download_backup', array($this, 'updraft_download_backup'));
- add_action('wp_ajax_updraft_ajax', array($this, 'updraft_ajax_handler'));
- # http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
- add_filter('cron_schedules', array($this,'modify_cron_schedules'));
- add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
- add_action('init', array($this, 'handle_url_actions'));
- }
- // Handle actions passed on to method plugins; e.g. Google OAuth 2.0 - ?page=updraftplus&action=updraftmethod-googledrive-auth
- // Also handle action=downloadlog
- function handle_url_actions() {
- // First, basic security check: must be an admin page, with ability to manage options, with the right parameters
- if ( UpdraftPlus_Options::user_can_manage() && isset( $_GET['page'] ) && $_GET['page'] == 'updraftplus' && isset($_GET['action']) ) {
- if (preg_match("/^updraftmethod-([a-z]+)-([a-z]+)$/", $_GET['action'], $matches) && file_exists(UPDRAFTPLUS_DIR.'/methods/'.$matches[1].'.php')) {
- $method = $matches[1];
- require_once(UPDRAFTPLUS_DIR.'/methods/'.$method.'.php');
- $call_class = "UpdraftPlus_BackupModule_".$method;
- $call_method = "action_".$matches[2];
- if (method_exists($call_class, $call_method)) call_user_func(array($call_class,$call_method));
- } elseif ($_GET['action'] == 'downloadlog' && isset($_GET['updraftplus_backup_nonce']) && preg_match("/^[0-9a-f]{12}$/",$_GET['updraftplus_backup_nonce'])) {
- $updraft_dir = $this->backups_dir_location();
- $log_file = $updraft_dir.'/log.'.$_GET['updraftplus_backup_nonce'].'.txt';
- if (is_readable($log_file)) {
- header('Content-type: text/plain');
- readfile($log_file);
- exit;
- } else {
- add_action('admin_notices', array($this,'show_admin_warning_unreadablelog') );
- }
- }
- }
- }
- // Cleans up temporary files found in the updraft directory
- function clean_temporary_files() {
- $updraft_dir = $this->backups_dir_location();
- if ($handle = opendir($updraft_dir)) {
- $now_time=time();
- while (false !== ($entry = readdir($handle))) {
- if (preg_match('/\.tmp(\.gz)?$/', $entry) && is_file($updraft_dir.'/'.$entry) && $now_time-filemtime($updraft_dir.'/'.$entry)>86400) {
- $this->log("Deleting old temporary file: $entry");
- @unlink($updraft_dir.'/'.$entry);
- }
- }
- @closedir($handle);
- }
- }
- # Adds the settings link under the plugin on the plugin screen.
- function plugin_action_links($links, $file) {
- if ($file == plugin_basename(__FILE__)){
- $settings_link = '<a href="'.site_url().'/wp-admin/options-general.php?page=updraftplus">'.__("Settings", "UpdraftPlus").'</a>';
- array_unshift($links, $settings_link);
- $settings_link = '<a href="http://david.dw-perspective.org.uk/donate">'.__("Donate","UpdraftPlus").'</a>';
- array_unshift($links, $settings_link);
- $settings_link = '<a href="http://updraftplus.com">'.__("Add-Ons / Pro Support","UpdraftPlus").'</a>';
- array_unshift($links, $settings_link);
- }
- return $links;
- }
- function backup_time_nonce() {
- $this->backup_time = time();
- $nonce = substr(md5(time().rand()), 20);
- $this->nonce = $nonce;
- }
- function logfile_open($nonce) {
- //set log file name and open log file
- $updraft_dir = $this->backups_dir_location();
- $this->logfile_name = $updraft_dir. "/log.$nonce.txt";
- // Use append mode in case it already exists
- $this->logfile_handle = fopen($this->logfile_name, 'a');
- $this->opened_log_time = microtime(true);
- $this->log("Opened log file at time: ".date('r'));
- global $wp_version;
- $logline = "UpdraftPlus: ".$this->version." WordPress: ".$wp_version." PHP: ".phpversion()." (".php_uname().") PHP Max Execution Time: ".@ini_get("max_execution_time")." ZipArchive::addFile exists: ";
- // method_exists causes some faulty PHP installations to segfault, leading to support requests
- if (version_compare(phpversion(), '5.2.0', '>=') && extension_loaded('zip')) {
- $logline .= 'Y';
- } else {
- $logline .= (method_exists('ZipArchive', 'addFile')) ? "Y" : "N";
- }
- $this->log($logline);
- }
- # Logs the given line, adding (relative) time stamp and newline
- function log($line) {
- if ($this->logfile_handle) fwrite($this->logfile_handle, sprintf("%08.03f", round(microtime(true)-$this->opened_log_time, 3))." ".$line."\n");
- UpdraftPlus_Options::update_updraft_option("updraft_lastmessage", $line." (".date('M d H:i:s').")");
- }
- // This function is used by cloud methods to provide standardised logging, but more importantly to help us detect that meaningful activity took place during a resumption run, so that we can schedule further resumptions if it is worthwhile
- function record_uploaded_chunk($percent, $extra) {
- // Log it
- $service = $this->jobdata_get('service');
- $log = ucfirst($service)." chunked upload: $percent % uploaded";
- if ($extra) $log .= " ($extra)";
- $this->log($log);
- // If we are on an 'overtime' resumption run, and we are still meainingfully uploading, then schedule a new resumption
- // Our definition of meaningful is that we must maintain an overall average of at least 1% per run, after allowing 9 runs for everything else to get going
- // i.e. Max 109 runs = 545 minutes = 9 hrs 05
- // If they get 2 minutes on each run, and the file is 1Gb, then that equals 10.2Mb/120s = minimum 87Kb/s upload speed required
- if ($this->current_resumption >= 9 && $this->newresumption_scheduled == false && $percent > ( $this->current_resumption - 9)) {
- $resume_interval = $this->jobdata_get('resume_interval');
- if (!is_numeric($resume_interval) || $resume_interval<200) { $resume_interval = 200; }
- $schedule_for = time()+$resume_interval;
- $this->newresumption_scheduled = $schedule_for;
- $this->log("This is resumption ".$this->current_resumption.", but meaningful uploading is still taking place; so a new one will be scheduled");
- wp_schedule_single_event($schedule_for, 'updraft_backup_resume', array($this->current_resumption + 1, $this->nonce));
- }
- }
- function backup_resume($resumption_no, $bnonce) {
- @ignore_user_abort(true);
- // This is scheduled for 5 minutes after a backup job starts
- // Restore state
- if ($resumption_no > 0) {
- $this->nonce = $bnonce;
- $this->backup_time = $this->jobdata_get('backup_time');
- $this->logfile_open($bnonce);
- }
- $btime = $this->backup_time;
- $this->log("Backup run: resumption=$resumption_no, nonce=$bnonce, begun at=$btime");
- $this->current_resumption = $resumption_no;
- // Schedule again, to run in 5 minutes again, in case we again fail
- // The actual interval can be increased (for future resumptions) by other code, if it detects apparent overlapping
- $resume_interval = $this->jobdata_get('resume_interval');
- if (!is_numeric($resume_interval) || $resume_interval<200) $resume_interval = 200;
- // A different argument than before is needed otherwise the event is ignored
- $next_resumption = $resumption_no+1;
- if ($next_resumption < 10) {
- $this->log("Scheduling a resumption ($next_resumption) in case this run gets aborted");
- $schedule_for = time()+$resume_interval;
- wp_schedule_single_event($schedule_for, 'updraft_backup_resume', array($next_resumption, $bnonce));
- $this->newresumption_scheduled = $schedule_for;
- } else {
- $this->log("The current run is our tenth attempt - will not schedule a further attempt until we see something useful happening");
- }
- // This should be always called; if there were no files in this run, it returns us an empty array
- $backup_array = $this->resumable_backup_of_files($resumption_no);
- // This save, if there was something, is then immediately picked up again
- if (is_array($backup_array)) $this->save_backup_history($backup_array);
- // Returns an array, most recent first, of backup sets
- $backup_history = $this->get_backup_history();
- if (!isset($backup_history[$btime])) {
- $this->log("Could not find a record in the database of a backup with this timestamp");
- }
- $our_files=$backup_history[$btime];
- if (!is_array($our_files)) $our_files = array();
- $undone_files = array();
- $backup_database = $this->jobdata_get('backup_database');
- // The transient is read and written below (instead of using the existing variable) so that we can copy-and-paste this part as needed.
- if ($backup_database == "begun" || $backup_database == 'finished' || $backup_database == 'encrypted') {
- if ($backup_database == "begun") {
- if ($resumption_no > 0) {
- $this->log("Resuming creation of database dump");
- } else {
- $this->log("Beginning creation of database dump");
- }
- } elseif ($backup_database == 'encrypted') {
- $this->log("Database dump: Creation and encryption were completed already");
- } else {
- $this->log("Database dump: Creation was completed already");
- }
- $db_backup = $this->backup_db($backup_database);
- if(is_array($our_files) && is_string($db_backup)) $our_files['db'] = $db_backup;
- if ($backup_database != 'encrypted') $this->jobdata_set("backup_database", 'finished');
- } else {
- $this->log("Unrecognised data when trying to ascertain if the database was backed up ($backup_database)");
- }
- // Save this to our history so we can track backups for the retain feature
- $this->log("Saving backup history");
- // This is done before cloud despatch, because we want a record of what *should* be in the backup. Whether it actually makes it there or not is not yet known.
- $this->save_backup_history($our_files);
- // Potentially encrypt the database if it is not already
- if (isset($our_files['db']) && !preg_match("/\.crypt$/", $our_files['db'])) {
- $our_files['db'] = $this->encrypt_file($our_files['db']);
- $this->save_backup_history($our_files);
- if (preg_match("/\.crypt$/", $our_files['db'])) $this->jobdata_set("backup_database", 'encrypted');
- }
- foreach ($our_files as $key => $file) {
- // Only continue if the stored info was about a dump
- if ($key != 'plugins' && $key != 'themes' && $key != 'others' && $key != 'uploads' && $key != 'db') continue;
- $hash = md5($file);
- $fullpath = $this->backups_dir_location().'/'.$file;
- if ($this->jobdata_get("uploaded_$hash") === "yes") {
- $this->log("$file: $key: This file has already been successfully uploaded");
- } elseif (is_file($fullpath)) {
- $this->log("$file: $key: This file has not yet been successfully uploaded: will queue");
- $undone_files[$key] = $file;
- } else {
- $this->log("$file: Note: This file was not marked as successfully uploaded, but does not exist on the local filesystem");
- $this->uploaded_file($file);
- }
- }
- if (count($undone_files) == 0) {
- $this->log("There were no more files that needed uploading; backup job is complete");
- // No email, as the user probably already got one if something else completed the run
- $this->backup_finish($next_resumption, true, false, $resumption_no);
- return;
- }
- $this->log("Requesting backup of the files that were not successfully uploaded");
- $this->cloud_backup($undone_files);
- $this->log("Resume backup ($bnonce, $resumption_no): finish run");
- if (is_array($our_files)) $this->save_last_backup($our_files);
- $this->backup_finish($next_resumption, true, true, $resumption_no);
- }
- function backup_all() {
- $this->boot_backup(true,true);
- }
-
- function backup_files() {
- # Note that the "false" for database gets over-ridden automatically if they turn out to have the same schedules
- $this->boot_backup(true,false);
- }
-
- function backup_database() {
- # Note that nothing will happen if the file backup had the same schedule
- $this->boot_backup(false,true);
- }
- function jobdata_set($key, $value) {
- if (is_array($this->jobdata)) {
- $this->jobdata[$key] = $value;
- } else {
- $this->jobdata = array($key => $value);
- }
- set_transient("updraft_jobdata_".$this->nonce, $this->jobdata, 14400);
- }
- function jobdata_get($key) {
- if (!is_array($this->jobdata)) {
- $this->jobdata = get_transient("updraft_jobdata_".$this->nonce);
- if (!is_array($this->jobdata)) return false;
- }
- return (isset($this->jobdata[$key])) ? $this->jobdata[$key] : false;
- }
- // This uses a transient; its only purpose is to indicate *total* completion; there is no actual danger, just wasted time, in resuming when it was not needed. So the transient just helps save resources.
- function resumable_backup_of_files($resumption_no) {
- //backup directories and return a numerically indexed array of file paths to the backup files
- $transient_status = $this->jobdata_get('backup_files');
- if ($transient_status == 'finished') {
- $this->log("Creation of backups of directories: already finished");
- } elseif ($transient_status == "begun") {
- if ($resumption_no>0) {
- $this->log("Creation of backups of directories: had begun; will resume");
- } else {
- $this->log("Creation of backups of directories: beginning");
- }
- } else {
- # This is not necessarily a backup run which is meant to contain files at all
- $this->log("This backup run is not intended for files - skipping");
- return array();
- }
- // We want this array, even if already finished
- $backup_array = $this->backup_dirs($transient_status);
- // This can get over-written later
- $this->jobdata_set('backup_files', 'finished');
- return $backup_array;
- }
- // This procedure initiates a backup run
- function boot_backup($backup_files, $backup_database) {
- @ignore_user_abort(true);
- //generate backup information
- $this->backup_time_nonce();
- $this->logfile_open($this->nonce);
- // Some house-cleaning
- $this->clean_temporary_files();
- // Log some information that may be helpful
- $this->log("Tasks: Backup files: $backup_files (schedule: ".UpdraftPlus_Options::get_updraft_option('updraft_interval', 'unset').") Backup DB: $backup_database (schedule: ".UpdraftPlus_Options::get_updraft_option('updraft_interval_database', 'unset').")");
- # If the files and database schedules are the same, and if this the file one, then we rope in database too.
- # On the other hand, if the schedules were the same and this was the database run, then there is nothing to do.
- if (UpdraftPlus_Options::get_updraft_option('updraft_interval') == UpdraftPlus_Options::get_updraft_option('updraft_interval_database') || UpdraftPlus_Options::get_updraft_option('updraft_interval_database','xyz') == 'xyz' ) {
- $backup_database = ($backup_files == true) ? true : false;
- }
- $this->log("Processed schedules. Tasks now: Backup files: $backup_files Backup DB: $backup_database");
- # If nothing to be done, then just finish
- if (!$backup_files && !$backup_database) {
- $this->backup_finish(1, false, false, 0);
- return;
- }
- // Save what *should* be done, to make it resumable from this point on
- if ($backup_database) $this->jobdata_set("backup_database", 'begun');
- if ($backup_files) $this->jobdata_set('backup_files', 'begun');
- $this->jobdata_set('service', UpdraftPlus_Options::get_updraft_option('updraft_service'));
- // This can be adapted if we see a need
- $this->jobdata_set('resume_interval', 300);
- $this->jobdata_set('backup_time', $this->backup_time);
- // Everthing is now set up; now go
- $this->backup_resume(0, $this->nonce);
- }
- // Encrypts the file if the option is set; returns the basename of the file (according to whether it was encrypted or nto)
- function encrypt_file($file) {
- $encryption = UpdraftPlus_Options::get_updraft_option('updraft_encryptionphrase');
- if (strlen($encryption) > 0) {
- $this->log("$file: applying encryption");
- $encryption_error = 0;
- $microstart = microtime(true);
- require_once(UPDRAFTPLUS_DIR.'/includes/Rijndael.php');
- $rijndael = new Crypt_Rijndael();
- $rijndael->setKey($encryption);
- $updraft_dir = $this->backups_dir_location();
- $file_size = @filesize($updraft_dir.'/'.$file)/1024;
- if (false === file_put_contents($updraft_dir.'/'.$file.'.crypt' , $rijndael->encrypt(file_get_contents($updraft_dir.'/'.$file)))) {$encryption_error = 1;}
- if (0 == $encryption_error) {
- $time_taken = max(0.000001, microtime(true)-$microstart);
- $this->log("$file: encryption successful: ".round($file_size,1)."Kb in ".round($time_taken,1)."s (".round($file_size/$time_taken, 1)."Kb/s)");
- # Delete unencrypted file
- @unlink($updraft_dir.'/'.$file);
- return basename($file.'.crypt');
- } else {
- $this->log("Encryption error occurred when encrypting database. Encryption aborted.");
- $this->error("Encryption error occurred when encrypting database. Encryption aborted.");
- return basename($file);
- }
- } else {
- return basename($file);
- }
- }
- function backup_finish($cancel_event, $clear_nonce_transient, $allow_email, $resumption_no) {
- // In fact, leaving the hook to run (if debug is set) is harmless, as the resume job should only do tasks that were left unfinished, which at this stage is none.
- if (empty($this->errors)) {
- if ($clear_nonce_transient) {
- $this->log("There were no errors in the uploads, so the 'resume' event is being unscheduled");
- wp_clear_scheduled_hook('updraft_backup_resume', array($cancel_event, $this->nonce));
- // TODO: Delete the job transient (is presently useful for debugging, and only lasts 4 hours)
- }
- } else {
- $this->log("There were errors in the uploads, so the 'resume' event is remaining scheduled");
- }
- // Send the results email if appropriate, which means:
- // - The caller allowed it (which is not the case in an 'empty' run)
- // - And: An email address was set (which must be so in email mode)
- // And one of:
- // - Debug mode
- // - There were no errors (which means we completed and so this is the final run - time for the final report)
- // - It was the tenth resumption; everything failed
- $send_an_email = false;
- // Make sure that the final status is shown
- if (empty($this->errors)) {
- $send_an_email = true;
- $final_message = "The backup apparently succeeded and is now complete";
- } elseif ($this->newresumption_scheduled == false) {
- $send_an_email = true;
- $final_message = "The backup attempt has finished, apparently unsuccessfully";
- } else {
- // There are errors, but a resumption will be attempted
- $final_message = "The backup has not finished; a resumption is scheduled within 5 minutes";
- }
- // Now over-ride the decision to send an email, if needed
- if (UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) {
- $send_an_email = true;
- $this->log("An email has been scheduled for this job, because we are in debug mode");
- }
- // If there's no email address, or the set was empty, that is the final over-ride: don't send
- if (!$allow_email) {
- $send_an_email = false;
- $this->log("No email will be sent - this backup set was empty.");
- } elseif (UpdraftPlus_Options::get_updraft_option('updraft_email') == '') {
- $send_an_email = false;
- $this->log("No email will/can be sent - the user has not configured an email address.");
- }
- if ($send_an_email) $this->send_results_email($final_message);
- $this->log($final_message);
- @fclose($this->logfile_handle);
- // Don't delete the log file now; delete it upon rotation
- //if (!UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) @unlink($this->logfile_name);
- }
- function send_results_email($final_message) {
- $debug_mode = UpdraftPlus_Options::get_updraft_option('updraft_debug_mode');
- $sendmail_to = UpdraftPlus_Options::get_updraft_option('updraft_email');
- $backup_files = $this->jobdata_get('backup_files');
- $backup_db = $this->jobdata_get("backup_database");
- if ($backup_files == 'finished' && ( $backup_db == 'finished' || $backup_db == 'encrypted' ) ) {
- $backup_contains = "Files and database";
- } elseif ($backup_files == 'finished') {
- $backup_contains = ($backup_db == "begun") ? "Files (database backup has not completed)" : "Files only (database was not part of this particular schedule)";
- } elseif ($backup_db == 'finished' || $backup_db == 'encrypted') {
- $backup_contains = ($backup_files == "begun") ? "Database (files backup has not completed)" : "Database only (files were not part of this particular schedule)";
- } else {
- $backup_contains = "Unknown/unexpected error - please raise a support request";
- }
- $this->log("Sending email ('$backup_contains') report to: ".substr($sendmail_to, 0, 5)."...");
- $append_log = ($debug_mode && $this->logfile_name != "") ? "\r\nLog contents:\r\n".file_get_contents($this->logfile_name) : "" ;
- wp_mail($sendmail_to,'Backed up: '.get_bloginfo('name').' (UpdraftPlus '.$this->version.') '.date('Y-m-d H:i',time()),'Site: '.site_url()."\r\nUpdraftPlus WordPress backup is complete.\r\nBackup contains: ".$backup_contains."\r\nLatest status: $final_message\r\n\r\n".$this->wordshell_random_advert(0)."\r\n".$append_log);
- }
- function save_last_backup($backup_array) {
- $success = (empty($this->errors)) ? 1 : 0;
- $last_backup = array('backup_time'=>$this->backup_time, 'backup_array'=>$backup_array, 'success'=>$success, 'errors'=>$this->errors, 'backup_nonce' => $this->nonce);
- UpdraftPlus_Options::update_updraft_option('updraft_last_backup', $last_backup);
- }
- // This should be called whenever a file is successfully uploaded
- function uploaded_file($file, $id = false) {
- $hash = md5($file);
- $this->log("Recording as successfully uploaded: $file ($hash)");
- $this->jobdata_set("uploaded_$hash", "yes");
- if ($id) {
- $ids = UpdraftPlus_Options::get_updraft_option('updraft_file_ids', array() );
- $ids[$file] = $id;
- UpdraftPlus_Options::update_updraft_option('updraft_file_ids',$ids);
- $this->log("Stored file<->id correlation in database ($file <-> $id)");
- }
- // Delete local files immediately if the option is set
- // Where we are only backing up locally, only the "prune" function should do deleting
- if ($this->jobdata_get('service') != '' && $this->jobdata_get('service') != 'none') $this->delete_local($file);
- }
- // Dispatch to the relevant function
- function cloud_backup($backup_array) {
- $service = $this->jobdata_get('service');
- $this->log("Cloud backup selection: ".$service);
- @set_time_limit(900);
- $method_include = UPDRAFTPLUS_DIR.'/methods/'.$service.'.php';
- if (file_exists($method_include)) require_once($method_include);
- if ($service == "none") {
- $this->log("No remote despatch: user chose no remote backup service");
- } else {
- $this->log("Beginning dispatch of backup to remote");
- }
- $objname = "UpdraftPlus_BackupModule_${service}";
- if (method_exists($objname, "backup")) {
- // New style - external, allowing more plugability
- $remote_obj = new $objname;
- $remote_obj->backup($backup_array);
- } elseif ($service == "none") {
- $this->prune_retained_backups("none", null, null);
- }
- }
- function prune_file($service, $dofile, $method_object = null, $object_passback = null ) {
- $this->log("Delete this file: $dofile, service=$service");
- $fullpath = $this->backups_dir_location().'/'.$dofile;
- // delete it if it's locally available
- if (file_exists($fullpath)) {
- $this->log("Deleting local copy ($fullpath)");
- @unlink($fullpath);
- }
- // Despatch to the particular method's deletion routine
- if (!is_null($method_object)) $method_object->delete($dofile, $object_passback);
- }
- // Carries out retain behaviour. Pass in a valid S3 or FTP object and path if relevant.
- function prune_retained_backups($service, $backup_method_object = null, $backup_passback = null) {
- // If they turned off deletion on local backups, then there is nothing to do
- if (UpdraftPlus_Options::get_updraft_option('updraft_delete_local') == 0 && $service == 'none') {
- $this->log("Prune old backups from local store: nothing to do, since the user disabled local deletion and we are using local backups");
- return;
- }
- $this->log("Retain: beginning examination of existing backup sets");
- // Number of backups to retain - files
- $updraft_retain = UpdraftPlus_Options::get_updraft_option('updraft_retain', 1);
- $updraft_retain = (is_numeric($updraft_retain)) ? $updraft_retain : 1;
- $this->log("Retain files: user setting: number to retain = $updraft_retain");
- // Number of backups to retain - db
- $updraft_retain_db = UpdraftPlus_Options::get_updraft_option('updraft_retain_db', $updraft_retain);
- $updraft_retain_db = (is_numeric($updraft_retain_db)) ? $updraft_retain_db : 1;
- $this->log("Retain db: user setting: number to retain = $updraft_retain_db");
- // Returns an array, most recent first, of backup sets
- $backup_history = $this->get_backup_history();
- $db_backups_found = 0;
- $file_backups_found = 0;
- $this->log("Number of backup sets in history: ".count($backup_history));
- foreach ($backup_history as $backup_datestamp => $backup_to_examine) {
- // $backup_to_examine is an array of file names, keyed on db/plugins/themes/uploads
- // The new backup_history array is saved afterwards, so remember to unset the ones that are to be deleted
- $this->log("Examining backup set with datestamp: $backup_datestamp");
- if (isset($backup_to_examine['db'])) {
- $db_backups_found++;
- $this->log("$backup_datestamp: this set includes a database (".$backup_to_examine['db']."); db count is now $db_backups_found");
- if ($db_backups_found > $updraft_retain_db) {
- $this->log("$backup_datestamp: over retain limit ($updraft_retain_db); will delete this database");
- $dofile = $backup_to_examine['db'];
- if (!empty($dofile)) $this->prune_file($service, $dofile, $backup_method_object, $backup_passback);
- unset($backup_to_examine['db']);
- }
- }
- if (isset($backup_to_examine['plugins']) || isset($backup_to_examine['themes']) || isset($backup_to_examine['uploads']) || isset($backup_to_examine['others'])) {
- $file_backups_found++;
- $this->log("$backup_datestamp: this set includes files; fileset count is now $file_backups_found");
- if ($file_backups_found > $updraft_retain) {
- $this->log("$backup_datestamp: over retain limit ($updraft_retain); will delete this file set");
- $file = isset($backup_to_examine['plugins']) ? $backup_to_examine['plugins'] : "";
- $file2 = isset($backup_to_examine['themes']) ? $backup_to_examine['themes'] : "";
- $file3 = isset($backup_to_examine['uploads']) ? $backup_to_examine['uploads'] : "";
- $file4 = isset($backup_to_examine['others']) ? $backup_to_examine['others'] : "";
- foreach (array($file, $file2, $file3, $file4) as $dofile) {
- if (!empty($dofile)) $this->prune_file($service, $dofile, $backup_method_object, $backup_passback);
- }
- unset($backup_to_examine['plugins']);
- unset($backup_to_examine['themes']);
- unset($backup_to_examine['uploads']);
- unset($backup_to_examine['others']);
- }
- }
- // Delete backup set completely if empty, o/w just remove DB
- if (count($backup_to_examine) == 0 || (count($backup_to_examine) == 1 && isset($backup_to_examine['nonce']))) {
- $this->log("$backup_datestamp: this backup set is now empty; will remove from history");
- unset($backup_history[$backup_datestamp]);
- if (isset($backup_to_examine['nonce'])) {
- $fullpath = $this->backups_dir_location().'/log.'.$backup_to_examine['nonce'].'.txt';
- if (is_file($fullpath)) {
- $this->log("$backup_datestamp: deleting log file (log.".$backup_to_examine['nonce'].".txt)");
- @unlink($fullpath);
- } else {
- $this->log("$backup_datestamp: corresponding log file not found - must have already been deleted");
- }
- } else {
- $this->log("$backup_datestamp: no nonce record found in the backup set, so cannot delete any remaining log file");
- }
- } else {
- $this->log("$backup_datestamp: this backup set remains non-empty; will retain in history");
- $backup_history[$backup_datestamp] = $backup_to_examine;
- }
- }
- $this->log("Retain: saving new backup history (sets now: ".count($backup_history).") and finishing retain operation");
- UpdraftPlus_Options::update_updraft_option('updraft_backup_history',$backup_history);
- }
- function delete_local($file) {
- if(UpdraftPlus_Options::get_updraft_option('updraft_delete_local')) {
- $this->log("Deleting local file: $file");
- //need error checking so we don't delete what isn't successfully uploaded?
- $fullpath = $this->backups_dir_location().'/'.$file;
- return unlink($fullpath);
- }
- return true;
- }
- function reschedule($how_far_ahead) {
- // Reschedule - remove presently scheduled event
- wp_clear_scheduled_hook('updraft_backup_resume', array($this->current_resumption + 1, $this->nonce));
- // Add new event
- if ($how_far_ahead < 200) $how_far_ahead=200;
- $schedule_for = time() + $how_far_ahead;
- wp_schedule_single_event($schedule_for, 'updraft_backup_resume', array($this->current_resumption + 1, $this->nonce));
- $this->newresumption_scheduled = $schedule_for;
- }
- function increase_resume_and_reschedule($howmuch = 120) {
- $resume_interval = $this->jobdata_get('resume_interval');
- if (!is_numeric($resume_interval) || $resume_interval<200) { $resume_interval = 200; }
- if ($this->newresumption_scheduled != false) $this->reschedule($resume_interval+$howmuch);
- $this->jobdata_set('resume_interval', $resume_interval+$howmuch);
- $this->log("To decrease the likelihood of overlaps, increasing resumption interval to: ".($resume_interval+$howmuch));
- }
- function create_zip($create_from_dir, $whichone, $create_in_dir, $backup_file_basename) {
- // Note: $create_from_dir can be an array or a string
- @set_time_limit(900);
- if ($whichone != "others") $this->log("Beginning creation of dump of $whichone");
- $full_path = $create_in_dir.'/'.$backup_file_basename.'-'.$whichone.'.zip';
- if (file_exists($full_path)) {
- $this->log("$backup_file_basename-$whichone.zip: this file has already been created");
- return basename($full_path);
- }
- // Temporary file, to be able to detect actual completion (upon which, it is renamed)
- // Firstly, make sure that the temporary file is not already being written to - which can happen if a resumption takes place whilst an old run is still active
- $zip_name = $full_path.'.tmp';
- $time_now = time();
- $time_mod = (int)@filemtime($zip_name);
- if (file_exists($zip_name) && $time_mod>100 && ($time_now-$time_mod)<30) {
- $file_size = filesize($zip_name);
- $this->log("Terminate: the temporary file $zip_name already exists, and was modified within the last 30 seconds (time_mod=$time_mod, time_now=$time_now, diff=".($time_now-$time_mod).", size=$file_size). This likely means that another UpdraftPlus run is still at work; so we will exit.");
- $this->increase_resume_and_reschedule(120);
- die;
- } elseif (file_exists($zip_name)) {
- $this->log("File exists ($zip_name), but was apparently not modified within the last 30 seconds, so we assume that any previous run has now terminated (time_mod=$time_mod, time_now=$time_now, diff=".($time_now-$time_mod).")");
- }
- $microtime_start = microtime(true);
- # The paths in the zip should then begin with '$whichone', having removed WP_CONTENT_DIR from the front
- $zipcode = $this->make_zipfile($create_from_dir, $zip_name);
- if ($zipcode !== true) {
- $this->log("ERROR: Zip failure: /*Could not create*/ $whichone zip: code=$zipcode");
- $this->error("Could not create $whichone zip: code $zipcode. Consult the log file for more information.");
- return false;
- } else {
- rename($full_path.'.tmp', $full_path);
- $timetaken = max(microtime(true)-$microtime_start, 0.000001);
- $kbsize = filesize($full_path)/1024;
- $rate = round($kbsize/$timetaken, 1);
- $this->log("Created $whichone zip - file size is ".round($kbsize,1)." Kb in ".round($timetaken,1)." s ($rate Kb/s)");
- }
- return basename($full_path);
- }
- // This function is resumable
- function backup_dirs($transient_status) {
- if(!$this->backup_time) $this->backup_time_nonce();
- $updraft_dir = $this->backups_dir_location();
- if(!is_writable($updraft_dir)) {
- $this->log("Backup directory ($updraft_dir) is not writable, or does not exist");
- $this->error("Backup directory ($updraft_dir) is not writable, or does not exist.");
- return array();
- }
- //get the blog name and rip out all non-alphanumeric chars other than _
- $blog_name = str_replace(' ','_',substr(get_bloginfo(), 0, 96));
- $blog_name = preg_replace('/[^A-Za-z0-9_]/','', $blog_name);
- if(!$blog_name) $blog_name = 'non_alpha_name';
- $backup_file_basename = 'backup_'.date('Y-m-d-Hi', $this->backup_time).'_'.$blog_name.'_'.$this->nonce;
- $backup_array = array();
- $wp_themes_dir = WP_CONTENT_DIR.'/themes';
- $wp_upload_dir = wp_upload_dir();
- $wp_upload_dir = $wp_upload_dir['basedir'];
- $wp_plugins_dir = WP_PLUGIN_DIR;
- $possible_backups = array ('plugins' => $wp_plugins_dir, 'themes' => $wp_themes_dir, 'uploads' => $wp_upload_dir);
- # Plugins, themes, uploads
- foreach ($possible_backups as $youwhat => $whichdir) {
- if (UpdraftPlus_Options::get_updraft_option("updraft_include_$youwhat", true)) {
- if ($transient_status == 'finished') {
- $backup_array[$youwhat] = $backup_file_basename.'-'.$youwhat.'.zip';
- } else {
- $created = $this->create_zip($whichdir, $youwhat, $updraft_dir, $backup_file_basename);
- if ($created) $backup_array[$youwhat] = $created;
- }
- } else {
- $this->log("No backup of $youwhat: excluded by user's options");
- }
- }
- # Others
- if (UpdraftPlus_Options::get_updraft_option('updraft_include_others', true)) {
- if ($transient_status == 'finished') {
- $backup_array['others'] = $backup_file_basename.'-others.zip';
- } else {
- $this->log("Beginning backup of other directories found in the content directory");
- // http://www.phpconcept.net/pclzip/user-guide/53
- /* First parameter to create is:
- An array of filenames or dirnames,
- or
- A string containing the filename or a dirname,
- or
- A string containing a list of filename or dirname separated by a comma.
- */
- # Initialise
- $other_dirlist = array();
- $others_skip = preg_split("/,/",UpdraftPlus_Options::get_updraft_option('updraft_include_others_exclude', UPDRAFT_DEFAULT_OTHERS_EXCLUDE));
- # Make the values into the keys
- $others_skip = array_flip($others_skip);
- $this->log('Looking for candidates to back up in: '.WP_CONTENT_DIR);
- if ($handle = opendir(WP_CONTENT_DIR)) {
- while (false !== ($entry = readdir($handle))) {
- $candidate = WP_CONTENT_DIR.'/'.$entry;
- if ($entry == "." || $entry == "..") { ; }
- elseif ($candidate == $updraft_dir) { $this->log("others: $entry: skipping: this is the updraft directory"); }
- elseif ($candidate == $wp_themes_dir) { $this->log("others: $entry: skipping: this is the themes directory"); }
- elseif ($candidate == $wp_upload_dir) { $this->log("others: $entry: skipping: this is the uploads directory"); }
- elseif ($candidate == $wp_plugins_dir) { $this->log("others: $entry: skipping: this is the plugins directory"); }
- elseif (isset($others_skip[$entry])) { $this->log("others: $entry: skipping: excluded by options"); }
- else { $this->log("others: $entry: adding to list"); array_push($other_dirlist, $candidate); }
- }
- @closedir($handle);
- } else {
- $this->log('ERROR: Could not read the content directory: '.WP_CONTENT_DIR);
- $this->error('Could not read the content directory: '.WP_CONTENT_DIR);
- }
- if (count($other_dirlist)>0) {
- $created = $this->create_zip($other_dirlist, 'others', $updraft_dir, $backup_file_basename);
- if ($created) $backup_array['others'] = $created;
- } else {
- $this->log("No backup of other directories: there was nothing found to back up");
- }
- # If we are not already finished
- }
- } else {
- $this->log("No backup of other directories: excluded by user's options");
- }
- return $backup_array;
- }
- function save_backup_history($backup_array) {
- if(is_array($backup_array)) {
- $backup_history = UpdraftPlus_Options::get_updraft_option('updraft_backup_history');
- $backup_history = (is_array($backup_history)) ? $backup_history : array();
- $backup_array['nonce'] = $this->nonce;
- $backup_history[$this->backup_time] = $backup_array;
- UpdraftPlus_Options::update_updraft_option('updraft_backup_history',$backup_history);
- } else {
- $this->log('Could not save backup history because we have no backup array. Backup probably failed.');
- $this->error('Could not save backup history because we have no backup array. Backup probably failed.');
- }
- }
-
- function get_backup_history() {
- //$backup_history = UpdraftPlus_Options::get_updraft_option('updraft_backup_history');
- //by doing a raw DB query to get the most up-to-date data from this option we slightly narrow the window for the multiple-cron race condition
- global $wpdb;
- $backup_history = @unserialize($wpdb->get_var($wpdb->prepare("SELECT option_value from $wpdb->options WHERE option_name='updraft_backup_history'")));
- if(is_array($backup_history)) {
- krsort($backup_history); //reverse sort so earliest backup is last on the array. Then we can array_pop.
- } else {
- $backup_history = array();
- }
- return $backup_history;
- }
- // Open a file, store its filehandle
- function backup_db_open($file, $allow_gz = true) {
- if (function_exists('gzopen') && $allow_gz == true) {
- $this->dbhandle = @gzopen($file, 'w');
- $this->dbhandle_isgz = true;
- } else {
- $this->dbhandle = @fopen($file, 'w');
- $this->dbhandle_isgz = false;
- }
- if(!$this->dbhandle) {
- $this->log("ERROR: $file: Could not open the backup file for writing");
- $this->error("$file: Could not open the backup file for writing");
- }
- }
- function backup_db_header() {
- //Begin new backup of MySql
- $this->stow("# " . 'WordPress MySQL database backup' . "\n");
- $this->stow("#\n");
- $this->stow("# " . sprintf(__('Generated: %s','wp-db-backup'),date("l j. F Y H:i T")) . "\n");
- $this->stow("# " . sprintf(__('Hostname: %s','wp-db-backup'),DB_HOST) . "\n");
- $this->stow("# " . sprintf(__('Database: %s','wp-db-backup'),$this->backquote(DB_NAME)) . "\n");
- $this->stow("# --------------------------------------------------------\n");
- if (defined("DB_CHARSET")) {
- $this->stow("/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n");
- $this->stow("/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n");
- $this->stow("/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n");
- $this->stow("/*!40101 SET NAMES " . DB_CHARSET . " */;\n");
- }
- $this->stow("/*!40101 SET foreign_key_checks = 0 */;\n");
- }
- /* This function is resumable, using the following method:
- - Each table is written out to ($final_filename).table.tmp
- - When the writing finishes, it is renamed to ($final_filename).table
- - When all tables are finished, they are concatenated into the final file
- */
- function backup_db($already_done = "begun") {
- // Get the file prefix
- $updraft_dir = $this->backups_dir_location();
- if(!$this->backup_time) $this->backup_time_nonce();
- if (!$this->opened_log_time) $this->logfile_open($this->nonce);
- // Get the blog name and rip out all non-alphanumeric chars other than _
- $blog_name = preg_replace('/[^A-Za-z0-9_]/','', str_replace(' ','_', substr(get_bloginfo(), 0, 96)));
- if (!$blog_name) $blog_name = 'non_alpha_name';
- $file_base = 'backup_'.date('Y-m-d-Hi',$this->backup_time).'_'.$blog_name.'_'.$this->nonce;
- $backup_file_base = $updraft_dir.'/'.$file_base;
- if ('finished' == $already_done) return basename($backup_file_base.'-db.gz');
- if ('encrypted' == $already_done) return basename($backup_file_base.'-db.gz.crypt');
- $total_tables = 0;
- global $table_prefix, $wpdb;
- $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
- $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables);
- if (!is_writable($updraft_dir)) {
- $this->log("The backup directory ($updraft_dir) is not writable.");
- $this->error("The backup directory ($updraft_dir) is not writable.");
- return false;
- }
- $stitch_files = array();
- foreach ($all_tables as $table) {
- $total_tables++;
- // Increase script execution time-limit to 15 min for every table.
- if ( !@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == "off") @set_time_limit(15*60);
- // The table file may already exist if we have produced it on a previous run
- $table_file_prefix = $file_base.'-db-table-'.$table.'.table';
- if (file_exists($updraft_dir.'/'.$table_file_prefix.'.gz')) {
- $this->log("Table $table: corresponding file already exists; moving on");
- } else {
- // Open file, store the handle
- $this->backup_db_open($updraft_dir.'/'.$table_file_prefix.'.tmp.gz', true);
- # === is needed, otherwise 'false' matches (i.e. prefix does not match)
- if ( strpos($table, $table_prefix) === 0 ) {
- // Create the SQL statements
- $this->stow("# --------------------------------------------------------\n");
- $this->stow("# " . sprintf(__('Table: %s','wp-db-backup'),$this->backquote($table)) . "\n");
- $this->stow("# --------------------------------------------------------\n");
- $this->backup_table($table);
- } else {
- $this->stow("# --------------------------------------------------------\n");
- $this->stow("# " . sprintf(__('Skipping non-WP table: %s','wp-db-backup'),$this->backquote($table)) . "\n");
- $this->stow("# --------------------------------------------------------\n");
- }
- // Close file
- $this->close($this->dbhandle);
- $this->log("Table $table: finishing file (${table_file_prefix}.gz)");
- rename($updraft_dir.'/'.$table_file_prefix.'.tmp.gz', $updraft_dir.'/'.$table_file_prefix.'.gz');
- }
- $stitch_files[] = $table_file_prefix;
- }
- // Race detection - with zip files now being resumable, these can more easily occur, with two running side-by-side
- $backup_final_file_name = $backup_file_base.'-db.gz';
- $time_now = time();
- $time_mod = (int)@filemtime($backup_final_file_name);
- if (file_exists($backup_final_file_name) && $time_mod>100 && ($time_now-$time_mod)<20) {
- $file_size = filesize($backup_final_file_name);
- $this->log("Terminate: the final database file ($backup_final_file_name) exists, and was modified within the last 20 seconds (time_mod=$time_mod, time_now=$time_now, diff=".($time_now-$time_mod).", size=$file_size). This likely means that another UpdraftPlus run is at work; so we will exit.");
- $this->increase_resume_and_reschedule(120);
- die;
- } elseif (file_exists($backup_final_file_name)) {
- $this->log("The final database file ($backup_final_file_name) exists, but was apparently not modified within the last 20 seconds (time_mod=$time_mod, time_now=$time_now, diff=".($time_now-$time_mod)."). Thus we assume that another UpdraftPlus terminated; thus we will continue.");
- }
- // Finally, stitch the files together
- $this->backup_db_open($backup_final_file_name, true);
- $this->backup_db_header();
- // We delay the unlinking because if two runs go concurrently and fail to detect each other (should not happen…
Large files files are truncated, but you can click here to view the full file