예제 #1
0
 function backup()
 {
     global $TPL;
     if (!is_dir(ATTACHMENTS_DIR . "backups" . DIRECTORY_SEPARATOR . "0")) {
         mkdir(ATTACHMENTS_DIR . "backups" . DIRECTORY_SEPARATOR . "0", 0777);
     }
     $archivename = "backup_" . date("Ymd_His") . ".zip";
     $zipfile = ATTACHMENTS_DIR . "backups" . DIRECTORY_SEPARATOR . "0" . DIRECTORY_SEPARATOR . $archivename;
     $dumpfile = ATTACHMENTS_DIR . "database.sql";
     is_file($dumpfile) && unlink($dumpfile);
     $archive = new PclZip($zipfile);
     $db = new db_alloc();
     $db->dump_db($dumpfile);
     if (!file_exists($dumpfile)) {
         alloc_error("Couldn't backup database to " . $dumpfile);
     } else {
         // database dump
         $files[] = $dumpfile;
         // load up all the attachment dirs
         foreach ($this->folders as $folder) {
             $files[] = ATTACHMENTS_DIR . $folder;
         }
         // add everything to the archive
         $archive->add($files, PCLZIP_OPT_REMOVE_PATH, ATTACHMENTS_DIR);
         // again, nuke leading path
         is_file($dumpfile) && unlink($dumpfile);
         $TPL["message_good"][] = "Backup created: " . $archivename;
     }
 }