public function getResult() { $backups_dir = realpath(WPADM_DIR_BACKUP . '/' . $this->params['name']); if (strpos($backups_dir, DIRECTORY_SEPARATOR . 'wpadm_backups' . DIRECTORY_SEPARATOR) === false || !is_dir($backups_dir)) { $this->result->setResult = WPAdm_result::WPADM_RESULT_ERROR; $this->result->setError('Wrong name backup'); } else { if (is_dir($backups_dir)) { WPAdm_Core::rmdir($backups_dir); if (!is_dir($backups_dir)) { $this->result->setResult = WPAdm_result::WPADM_RESULT_SUCCESS; } else { $this->result->setResult = WPAdm_result::WPADM_RESULT_ERROR; $this->result->setError('Failed to remove backup'); } } } return $this->result; }
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; }
public function getResult() { $errors = array(); $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS); $this->result->setError(''); @unlink(dirname(__FILE__) . '/../tmp/log.log'); WPAdm_Core::log('Start backup create'); WPAdm_Core::log('Create dump Data Base'); $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('optimization Database'); $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 . ' ' . str_replace(ABSPATH, '', $mysql_dump_file)); } unset($commandContext); WPAdm_Core::log('Start Created List Files'); if ($this->type == 'full') { $files = $this->createListFilesForArchive(); } else { $files = array(); } if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) { $files[] = $mysql_dump_file; } if (empty($files)) { $errors[] = 'Empty list files'; } $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('Сreated List Files is successfully'); $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('Start archived files'); // сохраним и выполним $this->queue->save()->execute(); WPAdm_Core::log('End archived files'); $files = glob($this->dir . '/' . $this->name . '*'); $urls = array(); foreach ($files as $file) { $urls[] = str_replace(ABSPATH, '', $file); } $this->result->setData($urls); WPAdm_Core::rmdir(WPADM_DIR_BACKUP . '/mysqldump.sql'); if ($this->params['limit'] != 0) { WPAdm_Core::log('Start deleted old backup'); $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('Finish deleted old backups'); } WPAdm_Core::log('Finish create'); if (!empty($errors)) { $this->result->setError(implode("\n", $errors)); $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR); } return $this->result; }
public static function dropbox_backup_create() { require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php"; @session_write_close(); $log = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir); if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) { @unlink(WPAdm_Core::getTmpDir() . "/logs2"); } if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) { file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", ''); } if (WPAdm_Core::dir_writeble(DROPBOX_BACKUP_DIR_BACKUP) && !file_exists(WPAdm_Core::getTmpDir() . "/create-backup")) { file_put_contents(WPAdm_Core::getTmpDir() . "/create-backup", 1); $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting'); $send_to_dropbox = true; if ($dropbox_options) { $dropbox_options = unserialize(base64_decode($dropbox_options)); if (!isset($dropbox_options['app_key'])) { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "App Key" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME)); $send_to_dropbox = false; } if (!isset($dropbox_options['app_secret'])) { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "App Secret" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME)); $send_to_dropbox = false; } if (!isset($dropbox_options['oauth_token'])) { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during file sending to Dropbox: "Auth Token not exist. Files cannot be sent to Dropbox cloud. Please, check your Dropbox settings."', false, '%d', SITE_HOME)); $send_to_dropbox = false; } } else { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "app key" and "app secret" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME)); $res['type'] = 'local'; $send_to_dropbox = false; } if ($send_to_dropbox) { parent::$type = 'full'; WPAdm_Running::init_params_default(); WPAdm_Running::delCommandResultData("local_backup"); $dropbox_options = self::getSettings(); $optimization = isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1 || !isset($dropbox_options['is_optimization']) ? 1 : 0; $backup_local = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files'))), 'full_backup_dropbox', WPAdm_Core::$pl_dir); $res = array(); if (WPAdm_Core::$cron === false) { $res = $backup->getResult()->toArray(); $res['md5_data'] = md5(print_r($res, 1)); $res['name'] = $backup->name; $res['time'] = $backup->time; $res['type'] = 'dropbox'; $res['counts'] = count($res['data']); } unset($backup_local); $folder_project = self::getNameProject(); WPAdm_Running::delCommandResultData("send-to-dropbox"); $backup = new WPAdm_Core(array('method' => "send-to-dropbox", 'params' => array('files' => isset($res['data']) ? $res['data'] : '', 'local' => true, 'access_details' => array('key' => $dropbox_options['app_key'], 'secret' => $dropbox_options['app_secret'], 'token' => $dropbox_options['auth_token_secret'], 'dir' => isset($res['name']) ? $res['name'] : '', 'folder' => $folder_project))), 'full_backup_dropbox', WPAdm_Core::$pl_dir); if (WPAdm_Core::$cron === false) { $result_send = $backup->getResult()->toArray(); if ($result_send['result'] == 'error') { $res = array(); $res['error'] = $result_send['error']; $res['result'] = 'error'; @rename(WPAdm_Core::getTmpDir() . "/logs2", WPAdm_Core::getTmpDir() . "/logs_error_" . $backup_local->time); } WPAdm_Core::rmdir(DROPBOX_BACKUP_DIR_BACKUP . "/{$res['name']}"); } else { set_transient('running_command', 'send-to-dropbox', 0); $res['result'] = 'work'; $res['error'] = ''; $res['data'] = array(); $res['size'] = 0; } if (file_exists(WPAdm_Core::getTmpDir() . "/create-backup")) { @unlink(WPAdm_Core::getTmpDir() . "/create-backup"); } } } else { $res['result'] = 'error'; $res['error'] = langWPADM::get('Website "%domain" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir-backup".', false, array('%domain', '%dir-backup'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP)); $res['data'] = array(); $res['size'] = 0; } @session_start(); echo json_encode($res); wp_die(); }
private function deleteCommands() { $files = glob(WPAdm_Core::getTmpDir() . "/wpadm_method_*"); if (!empty($files)) { for ($i = 0; $i < $n; $i++) { WPAdm_Core::rmdir($files[$i]); } } }
public static function delete_backup() { if (isset($_POST['backup-type'])) { if ($_POST['backup-type'] == 'local') { require_once dirname(__FILE__) . "/class-wpadm-core.php"; $dir = ABSPATH . 'wpadm_backups/' . $_POST['backup-name']; if (is_dir($dir)) { WPAdm_Core::rmdir($dir); } } elseif ($_POST['backup-type'] == 's3') { $amazon_option = self::getAmazonOptions(); if ($amazon_option) { require_once dirname(__FILE__) . '/modules/aws-autoloader.php'; $credentials = new Aws\Common\Credentials\Credentials($amazon_option['access_key_id'], $amazon_option['secret_access_key']); $client = Aws\S3\S3Client::factory(array('credentials' => $credentials)); try { $keys = $client->listObjects(array('Bucket' => $amazon_option['bucket'], 'Prefix' => $_POST['backup-name']))->getIterator(); if (isset($keys['Contents'])) { $n = count($keys['Contents']); for ($i = 0; $i < $n; $i++) { $client->deleteObject(array('Bucket' => $amazon_option['bucket'], 'Key' => $keys['Contents'][$i]['Key'])); } } } catch (Exception $e) { $_SESSION['errorMsgWpadmDB'] = $e->getMessage(); } catch (S3Exception $e) { $_SESSION['errorMsgWpadmDB'] = $e->getMessage(); } } } } header("Location: " . admin_url("admin.php?page=wpadm_wp_db_backup_s3")); }
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; }
public function getResult() { $errors = array(); $this->id = uniqid('wpadm_method_send_to_dropbox_'); $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS); $this->result->setError(''); if (isset($this->params['local']) && $this->params['local']) { $params_data_cron = WPAdm_Running::getCommandResultData('local_backup'); $this->params['files'] = $params_data_cron['data']; $this->params['access_details']['dir'] = $params_data_cron['name']; WPAdm_Core::log(langWPADM::get('', false)); } $this->queue = new WPAdm_Queue($this->id); $ad = $this->params['access_details']; $this->queue->clear(); $files = $this->params['files']; //$this->getResult()->setData($files); $dir = isset($ad['dir']) ? $ad['dir'] : '/'; //$dir = trim($dir, '/') . '/' . $this->name; if (is_array($files)) { $send = false; foreach ($files as $file) { if (isset($this->params['local']) && $this->params['local']) { $data_command = WPAdm_Running::getCommandResultData('command_dropbox'); $data_error_command = WPAdm_Running::getCommandResultData('errors_sending'); if (isset($data_error_command[ABSPATH . $file]) && $data_error_command[ABSPATH . $file]['count'] > WPADM_COUNT_LIMIT_SEND_TO_DROPBOX) { $msg = langWPADM::get('Not perhaps sending file: "%file%". If you wish make upload file, increase execution time code or speed internet provider is small for upload file.', false, '%file%', $file); WPAdm_Core::log($msg); $errors[] = $msg; break; } if (!empty($data_command) && in_array(ABSPATH . $file, $data_command)) { continue; } } $commandContext = new WPAdm_Command_Context(); $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $ad['key'])->addParam('secret', $ad['secret'])->addParam('token', $ad['token'])->addParam('folder_project', $ad['folder'])->addParam('folder', $dir)->addParam('files', ABSPATH . $file); if (isset($this->params['local']) && $this->params['local']) { $commandContext->addParam('local', true); } $this->queue->add($commandContext); unset($commandContext); $send = true; } } if ($send) { WPAdm_Core::log(langWPADM::get('Start copy to Dropbox Cloud', false)); $res = $this->queue->save()->execute(); WPAdm_Core::log(langWPADM::get('End Copy Files to Dropbox', false)); } if (isset($res) && !$res) { WPAdm_Core::log(langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError()); $errors[] = langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError(); } if (count($errors) > 0) { $this->result->setError(implode("\n", $errors)); $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR); } else { if (class_exists('wpadm_wp_full_backup_dropbox') && !file_exists(WPAdm_Core::getTmpDir() . "/notice-star")) { wpadm_wp_full_backup_dropbox::setFlagToTmp('notice-star', time() . "_1d"); } if (isset($this->params['local']) && $this->params['local'] && isset($params_data_cron)) { $this->result->setData($this->params['files']); $this->result->setSize($params_data_cron['size']); $this->result->setValue('md5_data', md5(print_r($this->result->toArray(), 1))); $this->result->setValue('name', $params_data_cron['name']); $this->result->setValue('time', $params_data_cron['time']); $this->result->setValue('type', 'dropbox'); $this->result->setValue('counts', $params_data_cron['counts']); WPAdm_Core::rmdir(DROPBOX_BACKUP_DIR_BACKUP . "/{$params_data_cron['name']}"); } } return $this->result; }
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; }
public function getResult() { $errors = array(); $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS); $this->result->setError(''); WPAdm_Core::log('Start backup'); 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('Database dump was not created(' . $this->queue->getError() . ')'); $errors[] = 'MySQL error: ' . $this->queue->getError(); } elseif (0 == (int) filesize($mysql_dump_file)) { $errors[] = 'MySQL error: empty dump-file'; WPAdm_Core::log('Database dump was not created(empty file)'); } else { WPAdm_Core::log('Database dump created(' . filesize($mysql_dump_file) . 'b):' . $mysql_dump_file); } unset($commandContext); WPAdm_Core::log('Start preparing a list of files'); $files = array(); if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) { $files[] = $mysql_dump_file; } if (empty($files)) { $errors[] = 'Empty list files'; } // Divide the list of files on the lists from 170 kbytes 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 files prepared'); $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('Getting back up files'); $this->queue->save()->execute(); WPAdm_Core::log('Ended up files'); $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'] == 's3') { WPAdm_Core::log('Begin coping files to S3'); $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']); if (isset($ad['mkdir_for_backup']) && $ad['mkdir_for_backup'] == 1) { $commandContext->addParam('dir', $this->name); } $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('Finished copying files to S3'); 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('Remove the backup server'); WPAdm_Core::rmdir($this->dir); } } # delete tmpf-files WPAdm_Core::rmdir(ABSPATH . 'wpadm_backup'); #Remove old archives (over limit) WPAdm_Core::log('Start removing old files'); if ($this->params['limit'] != 0) { $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('Finished delete the old files'); WPAdm_Core::log('backup completed'); if (!empty($errors)) { $this->result->setError(implode("\n", $errors)); $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR); } return $this->result; }
static function delCommandResultData($command) { $path = WPAdm_Core::getTmpDir(); if (!empty($path)) { WPAdm_Core::rmdir($path . "/{$command}"); } }