Beispiel #1
0
 public function run()
 {
     try {
         main::log(lang::get('Start Backup process...', false));
         $this->init();
         $db_param = $this->getDBParams();
         $mysql = $this->incMysql();
         if (isset($this->params['optimize'])) {
             main::log(lang::get('Optimize Database Tables', false));
             $mysql->optimize();
         }
         $mysql->backup($this->db_file);
         if (filesize($this->db_file) == 0) {
             throw new Exception(lang::get('Error in create dump Database: Chance of a lack of rights for the backup.', fale));
         } else {
             $size_dump = round(filesize($this->db_file) / 1024 / 1024, 2);
             main::log(str_replace('%s', $size_dump, lang::get('Database Dump was successfully created( %s Mb):', false)) . str_replace(ABSPATH, '', $this->db_file));
         }
         $files = $this->createListFiles();
         $files[] = $this->db_file;
         if (($n = count($files)) > 0) {
             include main::getPluginDir() . "/libs/pclzip.lib.php";
             $archive = $this->dir_backup . '/' . $this->getArchive($this->name);
             $zip = new PclZip($archive);
             main::log(lang::get('Add files to Backup', false));
             main::log(lang::get('Create part ', false) . basename($archive));
             for ($i = 0; $i < $n; $i++) {
                 if (file_exists($archive) && filesize($archive) > $this->max_size_archive) {
                     unset($zip);
                     $archive = $this->dir_backup . '/' . $this->getNextArchive($this->name);
                     main::log(lang::get('Create part ', false) . basename($archive));
                     $zip = new PclZip($archive);
                 }
                 $zip->add($files[$i], PCLZIP_OPT_REMOVE_PATH, ABSPATH);
                 $this->saveMd5($files[$i], $archive);
             }
             // delete dump db
             main::log(lang::get('Remove dump Database with folder', false));
             main::remove($this->db_file);
             $dirs = readDirectrory($this->dir_backup, array('.zip', '.md5'));
             $size = 0;
             if (($n = count($dirs)) > 0) {
                 for ($i = 0; $i < $n; $i++) {
                     $size += filesize($dirs[$i]);
                     $dirs[$i] = basename($dirs[$i]);
                 }
             }
             $sizeMb = round($size / 1024 / 1024, 2);
             // MB
             main::log(str_replace('%s', $sizeMb, lang::get('Backup created is finish ( %s Mb)', false)));
             $this->dirs = $dirs;
             $this->size = $size;
         }
     } catch (Exception $e) {
         $this->setError($e->message);
     }
 }
Beispiel #2
0
 private function local()
 {
     $this->files = readDirectrory(BACKUP_DIR . '/' . $this->params['name'], array('.zip'));
     include main::getPluginDir() . '/libs/pclzip.lib.php';
     if (($n = count($this->files)) > 0) {
         for ($i = 0; $i < $n; $i++) {
             main::log(str_replace('%s', basename($this->files[$i]), lang::get("Data decompression: %s", false)));
             $this->archive = new PclZip($this->files[$i]);
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
         }
         if (file_exists(BACKUP_DIR . '/' . $this->params['name'] . '/mysqldump.sql')) {
             main::log(lang::get("Run process restore Database", false));
             $mysql = $this->incMysql();
             $mysql->restore(BACKUP_DIR . '/' . $this->params['name'] . '/mysqldump.sql');
             main::log(lang::get("Stopped process restore Database", false));
             main::remove(BACKUP_DIR . '/' . $this->params['name'] . '/mysqldump.sql');
         }
     }
 }