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 / Cron / Task / DownloadBackupLog.php
backup / src / JetBackup / Cron / Task Last commit date
.htaccess 1 year ago Backup.php 1 year ago Download.php 1 year ago DownloadBackupLog.php 1 year ago Export.php 1 year ago Extract.php 1 year ago PreRestore.php 5 months ago Reindex.php 1 month ago Restore.php 5 months ago RetentionCleanup.php 4 months ago System.php 5 months ago Task.php 4 months ago index.html 1 year ago web.config 1 year ago
DownloadBackupLog.php
144 lines
1 <?php
2
3 namespace JetBackup\Cron\Task;
4
5 use JetBackup\Archive\Archive;
6 use JetBackup\Archive\Gzip;
7 use JetBackup\Destination\Destination;
8 use JetBackup\Exception\DBException;
9 use JetBackup\Exception\GzipException;
10 use JetBackup\Exception\TaskException;
11 use JetBackup\JetBackup;
12 use JetBackup\License\License;
13 use JetBackup\Queue\Queue;
14 use JetBackup\Queue\QueueItem;
15 use JetBackup\Queue\QueueItemDownload;
16 use JetBackup\Snapshot\Snapshot;
17 use JetBackup\Snapshot\SnapshotDownload;
18 use SleekDB\Exceptions\InvalidArgumentException;
19 use SleekDB\Exceptions\IOException;
20
21 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
22 class DownloadBackupLog extends Task
23 {
24
25 const LOG_FILENAME = 'download';
26
27 private Snapshot $_snapshot;
28 private QueueItemDownload $_queue_item_download;
29 private string $_target;
30
31 public function __construct() {
32 parent::__construct(self::LOG_FILENAME);
33 }
34
35 /**
36 * @return void
37 * @throws IOException
38 * @throws InvalidArgumentException
39 * @throws DBException
40 * @throws TaskException
41 */
42 public function execute():void {
43 parent::execute();
44
45 $this->_queue_item_download = $this->getQueueItem()->getItemData();
46 $this->_snapshot = new Snapshot($this->_queue_item_download->getSnapshotId());
47
48 $destination = new Destination($this->_snapshot->getDestinationId());
49
50 if(!License::isValid() && !in_array($destination->getType(), Destination::LICENSE_EXCLUDED)) {
51 $this->getLogController()->logError("You can't download backup log from {$destination->getType()} destination without a license");
52 $this->getQueueItem()->updateStatus(Queue::STATUS_ABORTED);
53 $this->getQueueItem()->updateProgress('Download Aborted!', QueueItem::PROGRESS_LAST_STEP);
54 return;
55 }
56
57 if($this->getQueueItem()->getStatus() == Queue::STATUS_PENDING) {
58 $this->getLogController()->logMessage('Starting Download Task');
59
60 $this->getQueueItem()->getProgress()->setTotalItems(count(Queue::STATUS_DOWNLOAD_LOG_NAMES));
61 $this->getQueueItem()->save();
62
63 $this->getQueueItem()->updateProgress('Starting Download Task');
64 } elseif($this->getQueueItem()->getStatus() > Queue::STATUS_PENDING) {
65 $this->getLogController()->logMessage('Resumed Download Task');
66 }
67
68
69 try {
70 $this->func([$this, '_download']);
71 $this->func([$this, '_decompress']);
72 if($this->getQueueItem()->getStatus() < Queue::STATUS_DONE && !$this->getQueueItem()->getErrors()) $this->getQueueItem()->updateStatus(Queue::STATUS_DONE);
73 else $this->getQueueItem()->updateStatus(Queue::STATUS_PARTIALLY);
74 $this->getLogController()->logMessage('Completed!');
75 } catch(\Exception $e) {
76 $this->getQueueItem()->updateStatus(Queue::STATUS_FAILED);
77 $this->getLogController()->logError($e->getMessage());
78 $this->getLogController()->logMessage('Failed!');
79 }
80
81 $this->getQueueItem()->updateProgress(
82 $this->getQueueItem()->getStatus() == Queue::STATUS_DONE
83 ? 'Download Backup Log Completed!'
84 : ($this->getQueueItem()->getStatus() == Queue::STATUS_PARTIALLY
85 ? 'Completed with errors (see logs)'
86 : 'Download Logs Failed!'),
87 QueueItem::PROGRESS_LAST_STEP
88 );
89
90 $this->getLogController()->logMessage('Total time: ' . $this->getExecutionTimeElapsed());
91 }
92
93 /**
94 * @return void
95 * @throws IOException
96 * @throws InvalidArgumentException
97 * @throws \JetBackup\Exception\IOException
98 * @throws \Exception
99 */
100 public function _download() {
101
102 $queue_item = $this->getQueueItem();
103
104 $this->getLogController()->logMessage('Execution time: ' . $this->getExecutionTimeElapsed());
105 $this->getLogController()->logMessage('TTL time: ' . $this->getExecutionTimeLimit());
106
107 $queue_item->updateStatus(Queue::STATUS_DOWNLOAD_DOWNLOAD);
108 $queue_item->updateProgress('Downloading backup log file');
109 $this->getLogController()->logMessage('Downloading backup log file');
110
111 $download = new SnapshotDownload($this->_snapshot, $this->getQueueItem()->getWorkspace());
112 $download->setLogController($this->getLogController());
113 $download->setQueueItem($this->getQueueItem());
114 $download->setTask($this);
115 $download->downloadLog();
116
117 // done downloading, reset sub process bar
118 $queue_item->getProgress()->resetSub();
119 $queue_item->save();
120 }
121
122 /**
123 * @return void
124 * @throws IOException
125 * @throws InvalidArgumentException
126 * @throws GzipException
127 */
128 public function _decompress(){
129
130 $log_file = $this->getQueueItem()->getWorkspace(). JetBackup::SEP . Snapshot::SKELETON_LOG_DIRNAME . JetBackup::SEP .Snapshot::SKELETON_LOG_FILENAME;
131
132 if(Archive::isGzCompressed($log_file)) {
133 if(file_exists($log_file)) {
134 $this->getLogController()->logMessage("\tDecompressing $log_file");
135 Gzip::decompress($log_file);
136 }
137 $log_file = substr($log_file, 0, -3);
138
139 }
140 $this->getQueueItem()->setLogFile($log_file);
141 $this->getQueueItem()->save();
142
143 }
144 }