Exemplo n.º 1
0
 public function execute()
 {
     $manager = WP_Backup_Extension_Manager::construct();
     $logger = WP_Backup_Registry::logger();
     $this->config->set_time_limit();
     $this->config->set_memory_limit();
     try {
         if (!$this->dropbox->is_authorized()) {
             $logger->log(__('Your Dropbox account is not authorized yet.', 'wpbtd'));
             return;
         }
         if ($this->output->start()) {
             //Create the SQL backups
             if (!$this->db_core->exists() || !$this->db_plugins->exists()) {
                 $logger->log(__('Creating SQL backup.', 'wpbtd'));
                 $this->db_core->execute();
                 $this->db_plugins->execute();
                 $logger->log(__('SQL backup complete. Starting file backup.', 'wpbtd'));
             }
             //Backup the content dir first
             $processed_files = $this->backup_path(WP_CONTENT_DIR, dirname(WP_CONTENT_DIR), array($this->db_core->get_file(), $this->db_plugins->get_file()));
             //Now backup the blog root
             $processed_files += $this->backup_path(get_sanitized_home_path());
             //End any output extensions
             $this->output->end();
             //Record the number of files processed to make the progress meter more accurate
             $this->config->set_option('total_file_count', $processed_files);
         }
         $manager->complete();
         //Update log file with stats
         $logger->log(__('Backup complete.', 'wpbtd'));
         $logger->log(sprintf(__('A total of %s files were processed.', 'wpbtd'), $processed_files));
         $logger->log(sprintf(__('A total of %dMB of memory was used to complete this backup.', 'wpbtd'), memory_get_usage(true) / 1048576));
         $this->output->clean_up();
         //Process the log file using the default backup output
         $root = false;
         if (get_class($this->output) != 'WP_Backup_Output') {
             $this->output = new WP_Backup_Output();
             $root = true;
         }
         $this->output->set_root($root)->out(get_sanitized_home_path(), $logger->get_log_file());
         $this->config->complete()->log_finished_time();
     } catch (Exception $e) {
         if ($e->getMessage() == 'Unauthorized') {
             $logger->log(__('The plugin is no longer authorized with Dropbox.', 'wpbtd'));
         } else {
             $logger->log(__('A fatal error occured: ', 'wpbtd') . $e->getMessage());
         }
         $manager->failure();
         $this->stop();
     }
     $this->clean_up();
 }
 public static function setLogger($logger)
 {
     self::$logger = $logger;
 }
 public function track_upload($file, $upload_id, $offset)
 {
     WP_Backup_Registry::config()->die_if_stopped();
     $this->processed_files->update_file($file, $upload_id, $offset);
     WP_Backup_Registry::logger()->log(sprintf(__("Uploaded %sMB of %sMB", 'wpbtd'), round($offset / 1048576, 1), round(filesize($file) / 1048576, 1)));
 }
 *          (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, USA.
 */
$config = WP_Backup_Registry::config();
if (!$config->get_option('in_progress')) {
    spawn_cron();
}
$log = WP_Backup_Registry::logger()->get_log();
if (empty($log)) {
    ?>
	<p><?php 
    _e('You have not run a backup yet. When you do you will see a log of it here.');
    ?>
</p>
<?php 
} else {
    ?>
	<ul>
		<?php 
    foreach (array_reverse($log) as $log_item) {
        ?>
			<li>
			<?php 
 public function die_if_stopped()
 {
     $in_progress = $this->db->get_var("SELECT value FROM {$this->db->prefix}wpb2d_options WHERE name = 'in_progress'");
     if (!$in_progress) {
         $msg = __('Backup stopped by user.', 'wpbtd');
         WP_Backup_Registry::logger()->log($msg);
         die($msg);
     }
 }
 protected function write_db_dump_header()
 {
     $this->handle = fopen($this->get_file(), 'w+');
     if (!$this->handle) {
         throw new Exception(__('Error creating sql dump file.', 'wpbtd'));
     }
     $dump_location = $this->config->get_backup_dir();
     if (!is_writable($dump_location)) {
         $msg = sprintf(__("A database backup cannot be created because WordPress does not have write access to '%s', please ensure this directory has write access.", 'wpbtd'), $dump_location);
         WP_Backup_Registry::logger()->log($msg);
         return false;
     }
     $blog_time = strtotime(current_time('mysql'));
     $this->write_to_file("-- WordPress Backup to Dropbox SQL Dump\n");
     $this->write_to_file("-- Version " . BACKUP_TO_DROPBOX_VERSION . "\n");
     $this->write_to_file("-- http://wpb2d.com\n");
     $this->write_to_file("-- Generation Time: " . date("F j, Y", $blog_time) . " at " . date("H:i", $blog_time) . "\n\n");
     $this->write_to_file('SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";' . "\n\n");
     //I got this out of the phpMyAdmin database dump to make sure charset is correct
     $this->write_to_file("/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n");
     $this->write_to_file("/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n");
     $this->write_to_file("/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n");
     $this->write_to_file("/*!40101 SET NAMES utf8 */;\n\n");
     $this->write_to_file("--\n-- Create and use the backed up database\n--\n\n");
     $this->write_to_file("CREATE DATABASE IF NOT EXISTS " . DB_NAME . ";\n");
     $this->write_to_file("USE " . DB_NAME . ";\n\n");
 }