summaryrefslogtreecommitdiffstats
path: root/modules-available/backup/hooks/cron.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/backup/hooks/cron.inc.php')
-rw-r--r--modules-available/backup/hooks/cron.inc.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/modules-available/backup/hooks/cron.inc.php b/modules-available/backup/hooks/cron.inc.php
new file mode 100644
index 00000000..c4a4b1dc
--- /dev/null
+++ b/modules-available/backup/hooks/cron.inc.php
@@ -0,0 +1,40 @@
+<?php
+
+(function () {
+ // Sunday midnight, between 0-4 minutes of hour
+ if (date('Hw') !== '000' || (int)date('i') >= 5)
+ return;
+ $mode = Property::get(BackupRestore::PROP_AUTO_BACKUP_MODE, BackupRestore::BACKUP_MODE_OFF);
+ if ($mode === BackupRestore::BACKUP_MODE_OFF)
+ return;
+ // DO IT
+ $password = trim(Property::get(BackupRestore::PROP_AUTO_BACKUP_PASS, ''));
+ if (empty($password)) {
+ $password = null;
+ }
+ if ($mode === BackupRestore::BACKUP_MODE_VMSTORE) {
+ if (file_exists('/srv/openslx/nfs/.notmounted')) {
+ EventLog::failure("Could not create automatic backup on VMstore as it's not mounted");
+ return;
+ }
+ $destination = '/srv/openslx/nfs/auto_backups/';
+ } else {
+ $destination = '/root/auto_backups/';
+ }
+ $destination .= 'sat-' . Property::getServerIp() . '-' . date('Y-m-d');
+ $task = Taskmanager::submit('BackupRestore', [
+ 'mode' => 'backup',
+ 'password' => $password,
+ 'destination' => $destination,
+ ]);
+ if (!isset($task['id'])) {
+ EventLog::failure("Could not create automatic backup, Taskmanager down");
+ return;
+ }
+ $task = Taskmanager::waitComplete($task, 90000);
+ if (!Taskmanager::isFinished($task) || Taskmanager::isFailed($task) || !isset($task['data']['backupFile'])) {
+ EventLog::failure("Creating backup failed", print_r($task, true));
+ return;
+ }
+ Property::set(BackupRestore::PROP_LAST_BACKUP, time());
+})(); \ No newline at end of file