blob: c4f976c4a78dfd4abcc24ad2fec5b8984d679735 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<?php
(function () {
if (date('w') !== '0' || (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, 60000);
if (!Taskmanager::isFinished($task) || !isset($task['data']['backupFile'])) {
EventLog::failure("Creating backup failed", print_r($task, true));
return;
}
if (!is_readable($task['data']['backupFile'])) {
EventLog::failure("Backup file '{$task['data']['backupFile']}' is not readable");
return;
}
Property::set('backup.last-time', time());
})();
|