/** * Handles the periodic start of the backup/restore utility to backup the database * @param string $discard */ function auto_backup_timer_handler($discard) { setOption('last_backup_run', time()); $curdir = getcwd(); $folder = SERVERPATH . "/" . BACKUPFOLDER; if (!is_dir($folder)) { mkdir($folder, CHMOD_VALUE); } chdir($folder); $filelist = safe_glob('*' . '.zdb'); $list = array(); foreach ($filelist as $file) { $list[$file] = filemtime($file); } chdir($curdir); asort($list); $list = array_flip($list); $keep = getOption('backups_to_keep'); while (count($list) >= $keep) { $file = array_shift($list); unlink(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file); } cron_starter(SERVERPATH . '/' . ZENFOLDER . '/' . UTILITIES_FOLDER . '/backup_restore.php', array('backup' => 1, 'compress' => sprintf('%u', getOption('backup_compression')), 'XSRFTag' => 'backup')); return $discard; }
/** * Handles the periodic start of the backup/restore utility to backup the database * @param string $discard */ static function timer_handler($discard) { global $_backupMutex; $_backupMutex->lock(); if (getOption('last_backup_run') + getOption('backup_interval') * 86400 < time()) { // maybe a race condition? Only need one execution $curdir = getcwd(); $folder = SERVERPATH . "/" . BACKUPFOLDER; if (!is_dir($folder)) { mkdir($folder, FOLDER_MOD); } chdir($folder); $filelist = safe_glob('*' . '.zdb'); $list = array(); foreach ($filelist as $file) { $list[$file] = filemtime($file); } chdir($curdir); asort($list); $list = array_flip($list); $keep = getOption('backups_to_keep'); while (!empty($list) && count($list) >= $keep) { $file = array_shift($list); @chmod(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file, 0777); unlink(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file); } cron_starter(SERVERPATH . '/' . ZENFOLDER . '/' . UTILITIES_FOLDER . '/backup_restore.php', array('backup' => 1, 'autobackup' => 1, 'compress' => sprintf('%u', getOption('backup_compression')), 'XSRFTag' => 'backup'), 3); setOption('last_backup_run', time()); } $_backupMutex->unlock(); return $discard; }