static function init()
 {
     $command = self::getCommand();
     if ($command) {
         WPAdm_Core::$cron = false;
         wpadm_class::$type = 'full';
         //$time_load = ini_get("max_execution_time");
         //WPAdm_Core::log('proccess is work ' . $time_load . 'sec');
         /*if ($time_load != 0) {
               self::run($time_load - 5);
           } else {
               self::run(90);
           } */
         self::run(30);
         if (self::checkLock()) {
             $core = new WPAdm_Core($command, 'full_backup_dropbox', DRBBACKUP_BASE_DIR);
             if ($result = $core->getResult()->toArray(true)) {
                 if ($result['result'] == 'success') {
                     self::delCommand($command['method']);
                     self::stop();
                     self::setCommandResultData($command['method'], $result);
                     self::init();
                 } elseif ($result['result'] == 'error') {
                     self::setCommandResultData($command['method'], $result);
                     self::stop();
                     self::init_params_default();
                 }
             }
         }
     }
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log(langWPADM::get('Start Backup process...', false));
     # create db dump
     if (in_array('db', $this->params['types'])) {
         WPAdm_Core::log(langWPADM::get('Creating Database Dump', false));
         $error = WPAdm_Core::mkdir(WPADM_DIR_BACKUP);
         if (!empty($error)) {
             $this->result->setError($error);
             $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
             return $this->result;
         }
         $mysql_dump_file = WPADM_DIR_BACKUP . '/mysqldump.sql';
         if (file_exists($mysql_dump_file)) {
             unlink($mysql_dump_file);
         }
         $wp_mysql_params = $this->getWpMysqlParams();
         if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
             WPAdm_Core::log(langWPADM::get('Optimize Database Tables', false));
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
             $this->queue->clear()->add($commandContext);
             unset($commandContext);
         }
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
         $res = $this->queue->add($commandContext)->save()->execute();
         if (!$res) {
             $log = langWPADM::get('Website "%d" returned an error during database dump creation: \'Dump of Database wasn\'t created: "%s"\'. To solve this problem, please check your database system logs or send to us your FTP access data. You can send to us support request using "Help" button on plugin page.', false, array('%d', '%s'), array(SITE_HOME, $this->queue->getError()));
             WPAdm_Core::log($log);
             $errors[] = $log;
         } elseif (0 == (int) filesize($mysql_dump_file)) {
             $log = langWPADM::get('Website "%d" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".', false, array('%d', '%dir'), array(SITE_HOME, WPADM_DIR_BACKUP));
             $errors[] = $log;
             WPAdm_Core::log($log);
         } else {
             $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
             $log = str_replace("%s", $size_dump, langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false));
             WPAdm_Core::log($log . $mysql_dump_file);
         }
         unset($commandContext);
     }
     if (count($errors) == 0) {
         if (in_array('files', $this->params['types'])) {
             WPAdm_Core::log(langWPADM::get('Create a list of files for Backup', false));
             $files = $this->createListFilesForArchive();
         }
         if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
             $files[] = $mysql_dump_file;
         }
         if (empty($files)) {
             $errors[] = langWPADM::get('Website "%d" returned an error during creation of the list of files for a backup: list of files for a backup is empty. To solve this problem, please check files and folders permissions for website "%d".', false, array('%d'), array(SITE_HOME));
         }
         // split the file list by 170kbayt lists, To break one big task into smaller
         $files2 = array();
         $files2[0] = array();
         $i = 0;
         $size = 0;
         foreach ($files as $f) {
             if ($size > 170000) {
                 //~170kbyte
                 $i++;
                 $size = 0;
                 $files2[$i] = array();
             }
             $f_size = (int) @filesize($f);
             if ($f_size == 0 || $f_size > 1000000) {
                 WPAdm_Core::log('File ' . $f . ' Size ' . $f_size);
             }
             $size += $f_size;
             $files2[$i][] = $f;
         }
         WPAdm_Core::log(langWPADM::get('List of Backup-Files was successfully created', false));
         $this->queue->clear();
         foreach ($files2 as $files) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
         WPAdm_Core::log(langWPADM::get('Backup of Files was started', false));
         $this->queue->save()->execute();
         WPAdm_Core::log(langWPADM::get('End of File Backup', false));
         $files = glob($this->dir . '/' . $this->name . '*');
         $urls = array();
         $totalSize = 0;
         foreach ($files as $file) {
             $urls[] = str_replace(ABSPATH, '', $file);
             $totalSize += @intval(filesize($file));
         }
         $this->result->setData($urls);
         $this->result->setSize($totalSize);
         $size = $totalSize / 1024 / 1024;
         /// MByte
         $size = round($size, 2);
         $log = str_replace("%s", $size, langWPADM::get('Backup Size %s Mb', false));
         WPAdm_Core::log($log);
         $remove_from_server = 0;
         #Removing TMP-files
         WPAdm_Core::rmdir($mysql_dump_file);
         #Removind old backups(if limit the number of stored backups)
         if ($this->params['limit'] != 0) {
             WPAdm_Core::log(langWPADM::get('Limits of Backups ', false) . $this->params['limit']);
             WPAdm_Core::log(langWPADM::get('Removing of old Backups was started', false));
             $files = glob(WPADM_DIR_BACKUP . '/*');
             if (count($files) > $this->params['limit']) {
                 $files2 = array();
                 foreach ($files as $f) {
                     $fa = explode('-', $f);
                     if (count($fa) != 3) {
                         continue;
                     }
                     $files2[$fa[2]] = $f;
                 }
                 ksort($files2);
                 $d = count($files2) - $this->params['limit'];
                 $del = array_slice($files2, 0, $d);
                 foreach ($del as $d) {
                     WPAdm_Core::rmdir($d);
                 }
             }
             WPAdm_Core::log(langWPADM::get('Removing of old Backups was Finished', false));
         }
     }
     wpadm_class::setBackup(1);
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         WPAdm_Core::rmdir($this->dir);
         wpadm_class::setStatus(0);
         wpadm_class::setErrors(implode(", ", $errors));
     } else {
         wpadm_class::setStatus(1);
         WPAdm_Core::log(langWPADM::get('Backup creation was complete successfully!', false));
     }
     wpadm_class::backupSend();
     return $this->result;
 }
Esempio n. 3
0
 public static function wpadm_show_backup()
 {
     require_once DRBBACKUP_BASE_DIR . "/modules/dropbox.class.php";
     parent::$type = 'full';
     $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
     if ($dropbox_options) {
         $dropbox_options = unserialize(base64_decode($dropbox_options));
         if (isset($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && isset($dropbox_options['auth_token_secret'])) {
             $dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
             $folder_project = self::getNameProject();
             $backups = $dropbox->listing($folder_project);
             $n = count($backups['items']);
             $data['data'] = array();
             for ($i = 0; $i < $n; $i++) {
                 $backup = $dropbox->listing($folder_project . "/" . $backups['items'][$i]['name']);
                 $data['data'][$i]['name'] = $backups['items'][$i]['name'];
                 $data['data'][$i]['size'] = (double) $backup['size'] * 1024 * 1024;
                 $data['data'][$i]['dt'] = parent::getDateInName($backups['items'][$i]['name']);
                 $data['data'][$i]['count'] = count($backup['items']);
                 $data['data'][$i]['type'] = 'dropbox';
                 $k = $data['data'][$i]['count'];
                 $data['data'][$i]['files'] = '[';
                 for ($j = 0; $j < $k; $j++) {
                     $data['data'][$i]['files'] .= $backup['items'][$j]['name'] . ',';
                 }
             }
         }
     }
     if (isset($_GET['pay']) && $_GET['pay'] == 'success') {
         if (!file_exists(WPAdm_Core::getTmpDir() . "/pay_success")) {
             file_put_contents(WPAdm_Core::getTmpDir() . "/pay_success", 1);
             parent::setMessage(langWPADM::get('', false));
         }
     }
     if (isset($_GET['pay']) && $_GET['pay'] == 'cancel') {
         parent::setError(langWPADM::get('Checkout was canceled', false));
     }
     $data_local = parent::read_backups();
     if (isset($data['data'])) {
         $data['data'] = array_merge($data_local['data'], $data['data']);
         $data['md5'] = md5(print_r($data['data'], 1));
     } else {
         $data = $data_local;
     }
     if (file_exists(WPAdm_Core::getTmpDir() . "/pay_success")) {
         $plugin_info = get_plugins("/" . parent::$plugin_name);
         $plugin_version = isset($plugin_info[parent::$plugin_name . '.php']['Version']) ? $plugin_info[parent::$plugin_name . '.php']['Version'] : '';
         $data_server = parent::sendToServer(array('actApi' => "proBackupCheck", 'site' => home_url(), 'email' => get_option('admin_email'), 'plugin' => parent::$plugin_name, 'key' => '', 'plugin_version' => $plugin_version));
         if (isset($data_server['status']) && $data_server['status'] == 'success' && isset($data_server['key'])) {
             update_option(PREFIX_BACKUP_ . 'pro-key', $data_server['key']);
             if (isset($data_server['url']) && !empty($data_server['url'])) {
                 parent::setMessage(str_replace('&s', $data_server['url'], langWPADM::get('The "Dropbox backup & restore PRO" version can be downloaded here <a href="&s">download</a>', false)));
             }
         }
     }
     if (!function_exists('get_plugins')) {
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
     }
     $stars5 = file_exists(WPAdm_Core::getTmpDir() . "/notice-star");
     $plugin_data = array_values(get_plugins('/dropbox-backup'));
     $is_runnig = WPAdm_Running::is_running();
     $show = !get_option('wpadm_pub_key') && is_super_admin();
     $error = parent::getError(true);
     $msg = parent::getMessage(true);
     $base_path = DRBBACKUP_BASE_DIR;
     ob_start();
     require_once $base_path . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show_backup.php";
     echo ob_get_clean();
 }
Esempio n. 4
0
 public static function wpadm_show_backup()
 {
     require_once DRBBACKUP_BASE_DIR . "/modules/dropbox.class.php";
     parent::$type = 'full';
     $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
     if ($dropbox_options) {
         $dropbox_options = unserialize(base64_decode($dropbox_options));
         if (isset($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && isset($dropbox_options['auth_token_secret'])) {
             $dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
             $folder_project = self::getNameProject();
             $backups = $dropbox->listing($folder_project);
             $n = count($backups['items']);
             $data['data'] = array();
             for ($i = 0; $i < $n; $i++) {
                 $backup = $dropbox->listing($folder_project . "/" . $backups['items'][$i]['name']);
                 $data['data'][$i]['name'] = $backups['items'][$i]['name'];
                 $data['data'][$i]['size'] = (int) $backup['size'] * 1024 * 1024;
                 $data['data'][$i]['dt'] = parent::getDateInName($backups['items'][$i]['name']);
                 $data['data'][$i]['count'] = count($backup['items']);
                 $data['data'][$i]['type'] = 'dropbox';
                 $k = $data['data'][$i]['count'];
                 $data['data'][$i]['files'] = '[';
                 for ($j = 0; $j < $k; $j++) {
                     $data['data'][$i]['files'] .= $backup['items'][$i]['name'] . ',';
                 }
             }
         }
     }
     $data_local = parent::read_backups();
     if (isset($data['data'])) {
         $data['data'] = array_merge($data_local['data'], $data['data']);
         $data['md5'] = md5(print_r($data['data'], 1));
     } else {
         $data = $data_local;
     }
     $show = !get_option('wpadm_pub_key') && is_super_admin();
     $error = parent::getError(true);
     $msg = parent::getMessage(true);
     $base_path = DRBBACKUP_BASE_DIR;
     ob_start();
     require_once $base_path . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show_backup.php";
     echo ob_get_clean();
 }
Esempio n. 5
0
 public static function draw_menu()
 {
     $menu_position = '1.9998887771';
     parent::$plugin_name = 'database-backup-amazon-s3';
     if (parent::checkInstallWpadmPlugins()) {
         $page = add_menu_page('WPAdm', 'WPAdm', "read", 'wpadm_plugins', 'wpadm_plugins', plugins_url('/wpadm-logo.png', __FILE__), $menu_position);
         add_submenu_page('wpadm_plugins', "Amazon S3 Database Backup", "Amazon S3 Database Backup", 'read', 'wpadm_wp_db_backup_s3', array('wpadm_wp_db_backup_s3', 'wpadm_show_backup'));
     } else {
         add_submenu_page("wpadm_wp_db_backup_s3", "Database backup", "Database backup", "read", "wpadm_wp_db_backup_s3", array('wpadm_wp_db_backup_s3', 'wpadm_show_backup'));
         $page = add_menu_page('Amazon S3 Backup', 'Amazon S3 Backup', "read", 'wpadm_wp_db_backup_s3', array('wpadm_wp_db_backup_s3', 'wpadm_show_backup'), plugins_url('/wpadm-logo.png', __FILE__), $menu_position);
         add_submenu_page('wpadm_wp_db_backup_s3', "WPAdm", "WPAdm", 'read', 'wpadm_plugins', 'wpadm_plugins');
     }
 }
 public static function sendToServer($postdata = array(), $stat = false)
 {
     if (count($postdata) > 0) {
         if ($stat) {
             if ($counter_id = get_option(_PREFIX_STAT . 'counter_id')) {
                 $postdata['counter_id'] = $counter_id;
             }
         }
         $postdata = http_build_query($postdata, '', '&');
         $length = strlen($postdata);
         if (function_exists("curl_init") && function_exists("curl_setopt") && function_exists("curl_exec") && function_exists("curl_close")) {
             if ($stat) {
                 $url = SERVER_URL_VISIT_STAT . "/Api.php";
             } else {
                 $url = WPADM_URL_BASE . "api/";
             }
             $curl = curl_init($url);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($curl, CURLOPT_POST, true);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
             self::$result = curl_exec($curl);
             curl_close($curl);
             if ($stat) {
                 return unserialize(self::$result);
             } else {
                 return json_decode(self::$result, true);
             }
         } elseif (function_exists("fsockopen")) {
             if ($stat) {
                 $url = SERVER_URL_STAT;
                 $req = '/Api.php';
             } else {
                 $url = substr(WPADM_URL_BASE, 7);
                 $req = '/api/';
             }
             $out = "POST " . $req . " HTTP/1.1\r\n";
             $out .= "HOST: " . $url . "\r\n";
             $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
             $out .= "Content-Length: " . $length . "\r\n";
             $out .= "Connection:Close\r\n\r\n";
             $out .= $postdata . "\r\n\r\n";
             try {
                 $errno = '';
                 $errstr = '';
                 $socket = @fsockopen($url, 80, $errno, $errstr, 30);
                 if ($socket) {
                     if (!fwrite($socket, $out)) {
                         throw new Exception("unable to write fsockopen");
                     } else {
                         while ($in = @fgets($socket, 1024)) {
                             self::$result .= $in;
                         }
                     }
                     self::$result = explode("\r\n\r\n", self::$result);
                     if ($stat) {
                         return unserialize(self::$result);
                     } else {
                         return json_decode(self::$result, true);
                     }
                     throw new Exception("error in data");
                 } else {
                     throw new Exception("unable to create socket");
                 }
                 fclose($socket);
             } catch (exception $e) {
                 return false;
             }
         }
     }
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log(langWPADM::get('Start backup', false));
     # create db dump
     WPAdm_Core::log(langWPADM::get('Start create db dump', false));
     $error = WPAdm_Core::mkdir(WPADM_DIR_BACKUP);
     if (!empty($error)) {
         $this->result->setError($error);
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         return $this->result;
     }
     $mysql_dump_file = WPADM_DIR_BACKUP . '/mysqldump.sql';
     if (file_exists($mysql_dump_file)) {
         unlink($mysql_dump_file);
     }
     $wp_mysql_params = $this->getWpMysqlParams();
     if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
         WPAdm_Core::log(langWPADM::get('Table optimization', false));
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
         $this->queue->clear()->add($commandContext);
         unset($commandContext);
     }
     $commandContext = new WPAdm_Command_Context();
     $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
     $res = $this->queue->add($commandContext)->save()->execute();
     if (!$res) {
         $log = str_replace('%s', $this->queue->getError(), langWPADM::get('Error: Dump of Database wasn\'t created (%s)', false));
         WPAdm_Core::log($log);
         $errors[] = $log;
     } elseif (0 == (int) filesize($mysql_dump_file)) {
         $errors[] = langWPADM::get('MySQL Error: Database-Dump File is empty', false);
         WPAdm_Core::log(langWPADM::get('Dump of Database wasn\'t created (File of Database-Dump is empty!)', false));
     } else {
         $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
         $log = str_replace("%s", $size_dump, langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false));
         WPAdm_Core::log($log . $mysql_dump_file);
     }
     unset($commandContext);
     #ЗАРХИВИРУЕМ ФАЙЛЫ
     WPAdm_Core::log(langWPADM::get('Create a list of files for Backup', false));
     $files = $this->createListFilesForArchive();
     if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = langWPADM::get('Error: the list of Backup files is empty', false);
     }
     // split the file list by 170kbayt lists, To break one big task into smaller
     $files2 = array();
     $files2[0] = array();
     $i = 0;
     $size = 0;
     foreach ($files as $f) {
         if ($size > 170000) {
             //~170kbyte
             $i++;
             $size = 0;
             $files2[$i] = array();
         }
         $f_size = (int) filesize($f);
         if ($f_size == 0 || $f_size > 1000000) {
             WPAdm_Core::log('file ' . $f . ' size ' . $f_size);
         }
         $size += $f_size;
         $files2[$i][] = $f;
     }
     WPAdm_Core::log(langWPADM::get('List of Backup-Files was successfully created', false));
     $this->queue->clear();
     foreach ($files2 as $files) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     WPAdm_Core::log(langWPADM::get('Backup of Files was started', false));
     $this->queue->save()->execute();
     WPAdm_Core::log(langWPADM::get('End of File Backup', false));
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     $totalSize = 0;
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
         $totalSize += @intval(filesize($file));
     }
     $this->result->setData($urls);
     $this->result->setSize($totalSize);
     $remove_from_server = 0;
     if (isset($this->params['storage'])) {
         foreach ($this->params['storage'] as $storage) {
             if ($storage['type'] == 'ftp') {
                 WPAdm_Core::log(langWPADM::get('Begin copying files to FTP', false));
                 $this->queue->clear();
                 $files = glob($this->dir . '/' . $this->name . '*');
                 //$this->getResult()->setData($files);
                 $ad = $storage['access_details'];
                 $dir = isset($ad['dir']) ? $ad['dir'] : '/';
                 $dir = trim($dir, '/') . '/' . $this->name;
                 foreach ($files as $file) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'send_to_ftp')->addParam('file', $file)->addParam('host', $ad['host'])->addParam('port', isset($ad['port']) ? $ad['port'] : 21)->addParam('user', $ad['user'])->addParam('password', $ad['password'])->addParam('dir', $dir)->addParam('http_host', isset($ad['http_host']) ? $ad['http_host'] : '');
                     $this->queue->add($commandContext);
                     unset($commandContext);
                 }
                 $res = $this->queue->save()->execute();
                 if (!$res) {
                     $log = langWPADM::get('FTP: ', false);
                     WPAdm_Core::log($log . $this->queue->getError());
                     $errors[] = $log . $this->queue->getError();
                 }
                 WPAdm_Core::log(langWPADM::get('Finished copying files to FTP', false));
                 if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1) {
                     $remove_from_server = $storage['remove_from_server'];
                 }
             } elseif ($storage['type'] == 's3') {
                 WPAdm_Core::log(langWPADM::get('Begin coping files to S3', false));
                 $this->queue->clear();
                 $files = glob($this->dir . '/' . $this->name . '*');
                 //$this->getResult()->setData($files);
                 $ad = $storage['access_details'];
                 $dir = isset($ad['dir']) ? $ad['dir'] : '/';
                 $dir = trim($dir, '/') . '/' . $this->name;
                 foreach ($files as $file) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'send_to_s3')->addParam('file', $file)->addParam('bucket', $ad['bucket'])->addParam('AccessKeyId', $ad['AccessKeyId'])->addParam('SecretAccessKey', $ad['SecretAccessKey'])->addParam('SessionToken', $ad['SessionToken']);
                     $this->queue->add($commandContext);
                     unset($commandContext);
                 }
                 $res = $this->queue->save()->execute();
                 if (!$res) {
                     WPAdm_Core::log('S3: ' . $this->queue->getError());
                     $errors[] = 'S3: ' . $this->queue->getError();
                 }
                 WPAdm_Core::log(langWPADM::get('Finished copying files to S3', false));
                 if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1) {
                     $remove_from_server = $storage['remove_from_server'];
                 }
             }
         }
         if ($remove_from_server) {
             // удаляем файлы на сервере
             WPAdm_Core::log(langWPADM::get('Remove the backup server', false));
             WPAdm_Core::rmdir($this->dir);
         }
     }
     if (isset($this->params['gd']) && isset($this->params['gd']['key']) && isset($this->params['gd']['secret'])) {
         $this->queue->clear();
         $files = glob($this->dir . '/' . $this->name . '*');
         $files = array_merge_recursive(array($mysql_dump_file), $files);
         WPAdm_Core::log(langWPADM::get('files to google: ', false) . print_r($files, true));
         $n = count($files);
         for ($i = 0; $i < $n; $i++) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_google_drive')->addParam('key', $this->params['gd']['key'])->addParam('secret', $this->params['gd']['secret'])->addParam('token', $this->params['gd']['token'])->addParam('folder_project', $this->params['gd']['folder'])->addParam('folder', $this->name)->addParam('files', $files[$i]);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
         $res = $this->queue->save()->execute();
         if (!$res) {
             WPAdm_Core::log(langWPADM::get('Google drive: ', false) . $this->queue->getError());
         }
         //WPAdm_Core::log('google drive' . print_r($this->params, true));
     }
     if (isset($this->params['dropbox']) && isset($this->params['dropbox']['key']) && isset($this->params['dropbox']['secret'])) {
         $this->queue->clear();
         $files = glob($this->dir . '/' . $this->name . '*');
         $files = array_merge_recursive(array($mysql_dump_file), $files);
         WPAdm_Core::log(langWPADM::get('files to dropbox: ', false) . print_r($files, true));
         $n = count($files);
         for ($i = 0; $i < $n; $i++) {
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $this->params['dropbox']['key'])->addParam('secret', $this->params['dropbox']['secret'])->addParam('token', $this->params['dropbox']['token'])->addParam('folder_project', $this->params['dropbox']['folder'])->addParam('folder', $this->name)->addParam('files', $files[$i]);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
         $this->queue->save()->execute();
         if (!$res) {
             WPAdm_Core::log(langWPADM::get('Dropbox: ', false) . $this->queue->getError());
         }
     }
     #Removing TMP-files
     WPAdm_Core::rmdir(WPADM_DIR_BACKUP . '/mysqldump.sql');
     #Removind old backups(if limit the number of stored backups)
     WPAdm_Core::log(langWPADM::get('Start removing old backups', false));
     if ($this->params['limit'] != 0) {
         $files = glob(WPADM_DIR_BACKUP . '/*');
         if (count($files) > $this->params['limit']) {
             $files2 = array();
             foreach ($files as $f) {
                 $fa = explode('-', $f);
                 if (count($fa) != 3) {
                     continue;
                 }
                 $files2[$fa[2]] = $f;
             }
             ksort($files2);
             $d = count($files2) - $this->params['limit'];
             $del = array_slice($files2, 0, $d);
             foreach ($del as $d) {
                 WPAdm_Core::rmdir($d);
             }
         }
     }
     WPAdm_Core::log(langWPADM::get('Finished removing old backups', false));
     WPAdm_Core::log(langWPADM::get('Creating a backup is completed', false));
     wpadm_class::setBackup(2);
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         wpadm_class::setStatus(0);
         wpadm_class::setErrors(implode(", ", $errors));
     } else {
         wpadm_class::setStatus(1);
     }
     wpadm_class::backupSend();
     return $this->result;
 }
Esempio n. 8
0
 public static function checkInstallWpadmPlugins()
 {
     $return = false;
     $i = 1;
     foreach (parent::$plugins as $plugin => $version) {
         if (parent::check_plugin($plugin)) {
             $i++;
         }
     }
     if ($i > 2) {
         $return = true;
     }
     return $return;
 }
 public function getResult()
 {
     if ($this->start === false) {
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         $this->result->setError('Backup process was started, please, wait a few minutes...');
         return $this->result;
     }
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     WPAdm_Core::log('Start Backup process...');
     # create db dump
     if (in_array('db', $this->params['types'])) {
         WPAdm_Core::log('Creating Database Dump');
         WPAdm_Core::mkdir(ABSPATH . 'wpadm_backup');
         $mysql_dump_file = ABSPATH . 'wpadm_backup/mysqldump.sql';
         if (file_exists($mysql_dump_file)) {
             unlink($mysql_dump_file);
         }
         $wp_mysql_params = $this->getWpMysqlParams();
         if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
             WPAdm_Core::log('Optimize Database Tables');
             $commandContext = new WPAdm_Command_Context();
             $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']);
             $this->queue->clear()->add($commandContext);
             unset($commandContext);
         }
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file);
         $res = $this->queue->add($commandContext)->save()->execute();
         if (!$res) {
             WPAdm_Core::log('Error: Dump of Database wasn\'t created(' . $this->queue->getError() . ')');
             $errors[] = 'MySQL Error: ' . $this->queue->getError();
         } elseif (0 == (int) filesize($mysql_dump_file)) {
             $errors[] = 'MySQL Error: Database-Dump File is empty';
             WPAdm_Core::log('Dump of Database wasn\'t created (File of Database-Dump is empty!)');
         } else {
             $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
             WPAdm_Core::log('Database Dump was successfully created(' . $size_dump . 'Mb):' . $mysql_dump_file);
         }
         unset($commandContext);
     }
     $files = array();
     if (in_array('files', $this->params['types'])) {
         WPAdm_Core::log('Create a list of files for Backup');
         $files = $this->createListFilesForArchive();
     }
     if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = 'Error: the list of Backup files is empty';
     }
     // split the file list by 170kbayt lists, To break one big task into smaller
     $files2 = array();
     $files2[0] = array();
     $i = 0;
     $size = 0;
     foreach ($files as $f) {
         if ($size > 170000) {
             //~170kbyte
             $i++;
             $size = 0;
             $files2[$i] = array();
         }
         $f_size = (int) @filesize($f);
         if ($f_size == 0 || $f_size > 1000000) {
             WPAdm_Core::log('File ' . $f . ' Size ' . $f_size);
         }
         $size += $f_size;
         $files2[$i][] = $f;
     }
     WPAdm_Core::log('List of Backup-Files was successfully created');
     $this->queue->clear();
     foreach ($files2 as $files) {
         $commandContext = new WPAdm_Command_Context();
         $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH);
         $this->queue->add($commandContext);
         unset($commandContext);
     }
     WPAdm_Core::log('Backup of Files was started');
     $this->queue->save()->execute();
     WPAdm_Core::log('End of File Backup');
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     $totalSize = 0;
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
         $totalSize += @intval(filesize($file));
     }
     $this->result->setData($urls);
     $this->result->setSize($totalSize);
     $size = $totalSize / 1024 / 1024;
     /// MByte
     $size = round($size, 2);
     WPAdm_Core::log('Backup Size ' . $size . " Mb");
     $remove_from_server = 0;
     #Removing TMP-files
     WPAdm_Core::rmdir(ABSPATH . 'wpadm_backup');
     #Removind old backups(if limit the number of stored backups)
     if ($this->params['limit'] != 0) {
         WPAdm_Core::log('Limits of Backups ' . $this->params['limit']);
         WPAdm_Core::log('Removing of old Backups was started');
         $files = glob(ABSPATH . 'wpadm_backups/*');
         if (count($files) > $this->params['limit']) {
             $files2 = array();
             foreach ($files as $f) {
                 $fa = explode('-', $f);
                 if (count($fa) != 3) {
                     continue;
                 }
                 $files2[$fa[2]] = $f;
             }
             ksort($files2);
             $d = count($files2) - $this->params['limit'];
             $del = array_slice($files2, 0, $d);
             foreach ($del as $d) {
                 WPAdm_Core::rmdir($d);
             }
         }
         WPAdm_Core::log('Removing of old Backups was Finished');
     }
     wpadm_class::setBackup(1);
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
         wpadm_class::setStatus(0);
         wpadm_class::setErrors(implode(", ", $errors));
     } else {
         wpadm_class::setStatus(1);
         WPAdm_Core::log('Backup creating is completed successfully!');
     }
     wpadm_class::backupSend();
     return $this->result;
 }