PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Backup / BackupConfig.php
backup / src / JetBackup / Backup Last commit date
.htaccess 1 year ago Backup.php 4 months ago BackupAccount.php 1 year ago BackupConfig.php 1 year ago index.html 1 year ago web.config 1 year ago
BackupConfig.php
169 lines
1 <?php
2
3 namespace JetBackup\Backup;
4
5 use JetBackup\Alert\Alert;
6 use JetBackup\BackupJob\BackupJob;
7 use JetBackup\Config\Config;
8 use JetBackup\Entities\Util;
9 use JetBackup\Factory;
10 use JetBackup\JetBackup;
11 use JetBackup\Queue\Queue;
12 use JetBackup\Queue\QueueItem;
13 use JetBackup\Snapshot\Snapshot;
14 use JetBackup\Snapshot\SnapshotItem;
15
16 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
17
18 class BackupConfig extends Backup {
19
20 const SKELETON_CONFIG_DIRNAME = 'config';
21 const SKELETON_DATABASE_DIRNAME = 'database';
22
23 public function execute():void {
24
25 try {
26 $this->getTask()->func([$this, '_createWorkspace']);
27 $this->getTask()->func([$this, '_archiveFiles'], [$this->getSnapshotDirectory()]);
28 $this->getTask()->func([$this, '_compressFiles']);
29 $this->getTask()->func([$this, '_transferToDestination']);
30
31 if($this->getQueueItem()->getStatus() < Queue::STATUS_DONE) {
32 $backup_destinations = sizeof($this->getBackupJob()->getDestinations());
33 $queue_destinations = sizeof($this->getQueueItemBackup()->getDestinations());
34
35 if($backup_destinations == $queue_destinations) $this->getQueueItem()->updateStatus(Queue::STATUS_DONE);
36 else $this->getQueueItem()->updateStatus(Queue::STATUS_PARTIALLY);
37 }
38
39 $this->getLogController()->logMessage('Completed!');
40
41 $this->getQueueItem()->updateProgress('Backup Completed! ' . '['.$this->getBackupJob()->getName().']', QueueItem::PROGRESS_LAST_STEP);
42
43 $this->getBackupJob()->calculateNextRun();
44 $this->getBackupJob()->setLastRun(time());
45 $this->getBackupJob()->save();
46
47 /*
48 * Case #853, users are getting confused by this email, replacing with internal alert for now
49 //Send notification
50 Notification::message()
51 ->addParam('backup_domain', Wordpress::getSiteDomain())
52 ->addParam('job_name', $this->getBackupJob()->getName())
53 ->addParam('backup_date', Util::date('Y-m-d H:i:s', $this->getBackupJob()->getLastRun()))
54 ->addParam('backup_status', Queue::STATUS_NAMES[$this->getQueueItem()->getStatus()])
55 ->send('JetBackup Completed', 'job_completed');
56 */
57
58 Alert::add('Internal Config Backup', "Internal config backup job is done", Alert::LEVEL_INFORMATION);
59
60 //Add retention cleanup to the queue after job is done;
61 //This has to run AFTER reindex because the data is based on reindex table
62 $this->_retentionCleanup();
63
64 //Add to queue backups that have 'After job is done'
65 $this->_calculateAfterJobDone();
66
67 } catch(\Exception $e) {
68 $this->getQueueItem()->updateStatus(Queue::STATUS_FAILED);
69 $this->getLogController()->logError($e->getMessage());
70 $this->getLogController()->logMessage('Failed!');
71
72 $progress = $this->getQueueItem()->getProgress();
73
74 $progress->setMessage('Backup Failed!');
75 $progress->setCurrentItem(7);
76 $this->getQueueItem()->save();
77
78 $this->getBackupJob()->calculateNextRun();
79 $this->getBackupJob()->setLastRun(time());
80 $this->getBackupJob()->save();
81 }
82
83 $this->getLogController()->logMessage('Total time: ' . $this->getTask()->getExecutionTimeElapsed());
84 }
85
86 public function _transferToDestination() {
87
88 $this->getLogController()->logMessage('Execution time: ' . $this->getTask()->getExecutionTimeElapsed());
89 $this->getLogController()->logMessage('TTL time: ' . $this->getTask()->getExecutionTimeLimit());
90
91 $this->getQueueItem()->updateStatus(Queue::STATUS_BACKUP_CONFIG_SEND_TO_DESTINATION);
92 $this->getQueueItem()->updateProgress('Transferring backup to destinations');
93
94 parent::_transferToDestination();
95 }
96
97 public function _compressFiles() {
98
99 if(!Factory::getSettingsPerformance()->isGzipCompressArchive()) {
100 $this->getLogController()->logMessage( 'GZIP Compression is disabled, skipping!' );
101 return;
102 }
103
104 $this->getLogController()->logMessage('Execution time: ' . $this->getTask()->getExecutionTimeElapsed());
105 $this->getLogController()->logMessage('TTL time: ' . $this->getTask()->getExecutionTimeLimit());
106
107 $this->getQueueItem()->updateStatus(Queue::STATUS_BACKUP_CONFIG_COMPRESSING);
108 $this->getQueueItem()->updateProgress('Compressing backup');
109
110 parent::_compressFiles();
111 }
112
113 public function _createWorkspace():void {
114 $this->getLogController()->logMessage('Execution time: ' . $this->getTask()->getExecutionTimeElapsed());
115 $this->getLogController()->logMessage('TTL time: ' . $this->getTask()->getExecutionTimeLimit());
116
117 $this->getQueueItem()->updateStatus(Queue::STATUS_PREPARING);
118 $this->getQueueItem()->updateProgress('Prepare workspace');
119
120 parent::_createWorkspace();
121 }
122
123 public function _archiveFiles($source): void {
124
125 $this->getLogController()->logMessage('Execution time: ' . $this->getTask()->getExecutionTimeElapsed());
126 $this->getLogController()->logMessage('TTL time: ' . $this->getTask()->getExecutionTimeLimit());
127
128 $this->getQueueItem()->updateStatus(Queue::STATUS_BACKUP_CONFIG_ARCHIVING);
129 $this->getQueueItem()->updateProgress('Archiving data');
130
131 Util::cp(Config::CONFIG_FILE, $source . JetBackup::SEP . Snapshot::SKELETON_CONFIG_DIRNAME . JetBackup::SEP . basename(Config::CONFIG_FILE));
132 Util::cp(Factory::getLocations()->getDatabaseDir(), $source . JetBackup::SEP . Snapshot::SKELETON_DATABASE_DIRNAME);
133
134 parent::_archiveFiles($source);
135
136 Util::rm($source . JetBackup::SEP . Snapshot::SKELETON_CONFIG_DIRNAME);
137 Util::rm($source . JetBackup::SEP . Snapshot::SKELETON_DATABASE_DIRNAME);
138 }
139
140 protected function getSnapshotItems(): array {
141
142 $output = [];
143
144 $path = self::SKELETON_DATABASE_DIRNAME . JetBackup::SEP . Snapshot::SKELETON_FILES_ARCHIVE_NAME . (Factory::getSettingsPerformance()->isGzipCompressArchive() ? '.gz' : '');
145 $homedir = $this->getSnapshotDirectory() . JetBackup::SEP . $path;
146 $size = file_exists($homedir) ? filesize($homedir) : 0;
147
148 // Full Item
149 $item = new SnapshotItem();
150 $item->setBackupType(BackupJob::TYPE_CONFIG);
151 $item->setBackupContains(BackupJob::BACKUP_CONFIG_CONTAINS_DATABASE);
152 $item->setCreated(time());
153 $item->setName('');
154 $item->setSize($size);
155 $item->setPath($path);
156 $output[] = $item;
157
158 $item = new SnapshotItem();
159 $item->setBackupType(BackupJob::TYPE_CONFIG);
160 $item->setBackupContains(BackupJob::BACKUP_CONFIG_CONTAINS_FULL);
161 $item->setCreated(time());
162 $item->setName('');
163 $item->setSize(0);
164 $item->setPath(BackupConfig::SKELETON_CONFIG_DIRNAME . JetBackup::SEP . Snapshot::SKELETON_FILES_ARCHIVE_NAME . (Factory::getSettingsPerformance()->isGzipCompressArchive() ? '.gz' : ''));
165 $output[] = $item;
166
167 return $output;
168 }
169 }