Пример #1
0
 protected function backupDB($fileName = '', $ext = 'zip')
 {
     $dirs = MainWP_Helper::getMainWPDir('backup');
     $dir = $dirs[0];
     $timestamp = time();
     if ('' !== $fileName) {
         $fileName .= '-';
     }
     $filepath_prefix = $dir . 'dbBackup-' . $fileName . $timestamp;
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
             if ('.' !== $file && '..' !== $file && preg_match('/dbBackup-(.*).sql(\\.zip|\\.tar|\\.tar\\.gz|\\.tar\\.bz2|\\.tmp)?$/', $file)) {
                 @unlink($dir . $file);
             }
         }
         closedir($dh);
     }
     $result = MainWP_Backup::get()->createBackupDB($filepath_prefix, $ext);
     MainWP_Helper::update_option('mainwp_child_last_db_backup_size', filesize($result['filepath']));
     return !$result ? false : array('timestamp' => $timestamp, 'file' => basename($result['filepath']), 'filesize' => filesize($result['filepath']));
 }