.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 | } |