PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.9.2
JetBackup – Backup, Restore & Migrate v3.1.9.2
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 / Queue / Queue.php
backup / src / JetBackup / Queue Last commit date
.htaccess 1 year ago Progress.php 1 year ago Queue.php 1 year ago QueueItem.php 1 year ago QueueItemBackup.php 1 year ago QueueItemDownload.php 1 year ago QueueItemExport.php 1 year ago QueueItemExtract.php 1 year ago QueueItemReindex.php 1 year ago QueueItemRestore.php 1 year ago QueueItemRetentionCleanup.php 1 year ago QueueItemSystem.php 1 year ago aQueueItem.php 1 year ago index.html 1 year ago web.config 1 year ago
Queue.php
312 lines
1 <?php
2
3 namespace JetBackup\Queue;
4
5 use JetBackup\Exception\QueueException;
6 use JetBackup\JetBackup;
7 use SleekDB\Exceptions\InvalidArgumentException;
8 use SleekDB\Exceptions\IOException;
9
10 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
11
12 class Queue {
13
14 public const QUEUE_TYPE_BACKUP = 1;
15 public const QUEUE_TYPE_RESTORE = 2;
16 public const QUEUE_TYPE_DOWNLOAD = 4;
17 public const QUEUE_TYPE_DOWNLOAD_BACKUP_LOG = 5;
18 public const QUEUE_TYPE_REINDEX = 8;
19 public const QUEUE_TYPE_RETENTION_CLEANUP = 16;
20 public const QUEUE_TYPE_SYSTEM = 32;
21 public const QUEUE_TYPE_EXPORT = 64;
22 public const QUEUE_TYPE_EXTRACT = 128;
23
24 public const QUEUE_TYPES = [
25 self::QUEUE_TYPE_BACKUP,
26 self::QUEUE_TYPE_RESTORE,
27 self::QUEUE_TYPE_DOWNLOAD,
28 self::QUEUE_TYPE_DOWNLOAD_BACKUP_LOG,
29 self::QUEUE_TYPE_REINDEX,
30 self::QUEUE_TYPE_RETENTION_CLEANUP,
31 self::QUEUE_TYPE_SYSTEM,
32 self::QUEUE_TYPE_EXPORT,
33 self::QUEUE_TYPE_EXTRACT,
34 ];
35
36 public const QUEUE_STATUS_NAMES = [
37 self::QUEUE_TYPE_BACKUP => self::STATUS_BACKUP_ACCOUNT_NAMES,
38 self::QUEUE_TYPE_RESTORE => self::STATUS_PRE_RESTORE_NAMES,
39 self::QUEUE_TYPE_DOWNLOAD => self::STATUS_DOWNLOAD_NAMES,
40 self::QUEUE_TYPE_DOWNLOAD_BACKUP_LOG => self::STATUS_DOWNLOAD_LOG_NAMES,
41 self::QUEUE_TYPE_REINDEX => self::STATUS_REINDEX_NAMES,
42 self::QUEUE_TYPE_RETENTION_CLEANUP => self::STATUS_CLEANUP_NAMES,
43 self::QUEUE_TYPE_SYSTEM => self::STATUS_SYSTEM_NAMES,
44 self::QUEUE_TYPE_EXPORT => self::STATUS_EXPORT_NAMES,
45 self::QUEUE_TYPE_EXTRACT => self::STATUS_EXTRACT_NAMES,
46 ];
47
48 public const QUEUE_TYPES_NAMES = [
49 self::QUEUE_TYPE_BACKUP => 'Backup',
50 self::QUEUE_TYPE_RESTORE => 'Restore',
51 self::QUEUE_TYPE_DOWNLOAD => 'Download',
52 self::QUEUE_TYPE_DOWNLOAD_BACKUP_LOG => 'Download Backup Log',
53 self::QUEUE_TYPE_REINDEX => 'Reindex',
54 self::QUEUE_TYPE_RETENTION_CLEANUP => 'Retention Cleanup',
55 self::QUEUE_TYPE_SYSTEM => 'System',
56 self::QUEUE_TYPE_EXPORT => 'Export',
57 self::QUEUE_TYPE_EXTRACT => 'Extract',
58 ];
59
60 // Backup Account Statuses
61 public const STATUS_BACKUP_ACCOUNT_DUMPING_DB = 10;
62 public const STATUS_BACKUP_ACCOUNT_ARCHIVING = 20;
63 public const STATUS_BACKUP_ACCOUNT_COMPRESSING = 21;
64 public const STATUS_BACKUP_ACCOUNT_SEND_TO_DESTINATION = 30;
65 public const STATUS_BACKUP_ACCOUNT_NAMES = [
66 self::STATUS_BACKUP_ACCOUNT_DUMPING_DB => 'Dumping Database',
67 self::STATUS_BACKUP_ACCOUNT_ARCHIVING => 'Archiving',
68 self::STATUS_BACKUP_ACCOUNT_COMPRESSING => 'Compressing',
69 self::STATUS_BACKUP_ACCOUNT_SEND_TO_DESTINATION => 'Transferring to Destination',
70 ];
71
72 // Backup Config Statuses
73 public const STATUS_BACKUP_CONFIG_ARCHIVING = 20;
74 public const STATUS_BACKUP_CONFIG_COMPRESSING = 21;
75 public const STATUS_BACKUP_CONFIG_SEND_TO_DESTINATION = 30;
76 public const STATUS_BACKUP_CONFIG_NAMES = [
77 self::STATUS_BACKUP_CONFIG_ARCHIVING => 'Archiving',
78 self::STATUS_BACKUP_CONFIG_COMPRESSING => 'Compressing',
79 self::STATUS_BACKUP_CONFIG_SEND_TO_DESTINATION => 'Transferring to Destination',
80 ];
81
82 // Restore Statuses
83 public const STATUS_RESTORE_DOWNLOAD = 10;
84 public const STATUS_RESTORE_EXTRACT = 20;
85 public const STATUS_RESTORE_BUILD_URL = 30;
86 public const STATUS_RESTORE_WAITING_FOR_RESTORE = 40;
87 public const STATUS_RESTORE_DATABASE = 50;
88 public const STATUS_RESTORE_FILES = 55;
89 public const STATUS_RESTORE_POST_RESTORE_DB_PREFIX = 60;
90 public const STATUS_RESTORE_POST_RESTORE_DOMAIN_MIGRATION = 65;
91 public const STATUS_RESTORE_POST_RESTORE_PLUGIN_ACTIONS = 70;
92 public const STATUS_RESTORE_POST_RESTORE_HEALTH_CHECK = 75;
93
94 // Restore JB Linux Statuses
95 public const STATUS_RESTORE_JB_IMPORTING_DB = 55;
96 public const STATUS_RESTORE_JB_DATABASES = 60;
97 public const STATUS_RESTORE_JB_DATABASE_USERS = 65;
98 public const STATUS_RESTORE_JB_HOMEDIR = 70;
99 public const STATUS_RESTORE_JB_POST = 75;
100 public const STATUS_RESTORE_JB_PRE = 80;
101
102 public const STATUS_PRE_RESTORE_NAMES = [
103 self::STATUS_RESTORE_DOWNLOAD => 'Downloading',
104 self::STATUS_RESTORE_EXTRACT => 'Extracting',
105 self::STATUS_RESTORE_BUILD_URL => 'Building Restore URL',
106 self::STATUS_RESTORE_WAITING_FOR_RESTORE => 'Waiting for external restore',
107 ];
108
109 public const STATUS_RESTORE_NAMES = [
110 self::STATUS_RESTORE_DATABASE => 'Restoring Database',
111 self::STATUS_RESTORE_FILES => 'Restoring Files',
112 self::STATUS_RESTORE_POST_RESTORE_DB_PREFIX => 'Post Restore - DB Prefix',
113 self::STATUS_RESTORE_POST_RESTORE_DOMAIN_MIGRATION => 'Post Restore - Domain Migration',
114 self::STATUS_RESTORE_POST_RESTORE_PLUGIN_ACTIONS => 'Post Restore - Plugin Actions',
115 self::STATUS_RESTORE_POST_RESTORE_HEALTH_CHECK => 'Post Restore - Health Check',
116 ];
117
118 // Reindex Statuses
119 public const STATUS_REINDEX_MARKING_SNAPSHOTS = 10;
120 public const STATUS_REINDEX_INDEXING_SNAPSHOTS = 30;
121 public const STATUS_REINDEX_DELETE_SNAPSHOTS = 40;
122 public const STATUS_REINDEX_NAMES = [
123 self::STATUS_REINDEX_MARKING_SNAPSHOTS => 'Marking Snapshots for delete',
124 self::STATUS_REINDEX_INDEXING_SNAPSHOTS => 'Indexing Snapshots',
125 self::STATUS_REINDEX_DELETE_SNAPSHOTS => 'Deleting Snapshots',
126 ];
127
128 // Extract Statuses
129 public const STATUS_EXTRACT_DOWNLOAD = 10;
130 public const STATUS_EXTRACT_EXTRACT = 15;
131 public const STATUS_EXTRACT_LEGACY = 25;
132 public const STATUS_EXTRACT_NAMES = [
133 self::STATUS_EXTRACT_DOWNLOAD => 'Downloading',
134 self::STATUS_EXTRACT_EXTRACT => 'Extracting',
135 self::STATUS_EXTRACT_LEGACY => 'Extracting Legacy',
136 ];
137
138 // Export Statuses
139 public const STATUS_EXPORT_DOWNLOAD = 10;
140 public const STATUS_EXPORT_EXTRACT = 15;
141 public const STATUS_EXPORT_BUILD = 25;
142 public const STATUS_EXPORT_NAMES = [
143 self::STATUS_EXPORT_DOWNLOAD => 'Downloading',
144 self::STATUS_EXPORT_EXTRACT => 'Extracting',
145 self::STATUS_EXPORT_BUILD => 'Building',
146 ];
147
148 // Download Statuses
149 public const STATUS_DOWNLOAD_DOWNLOAD = 10;
150 public const STATUS_DOWNLOAD_ARCHIVE = 15;
151 public const STATUS_DOWNLOAD_COMPRESS = 20;
152 public const STATUS_DOWNLOAD_NAMES = [
153 self::STATUS_DOWNLOAD_DOWNLOAD => 'Downloading',
154 self::STATUS_DOWNLOAD_ARCHIVE => 'Archiving',
155 self::STATUS_DOWNLOAD_COMPRESS => 'Compressing',
156
157 ];
158
159 public const STATUS_DOWNLOAD_LOG_DOWNLOADING = 10;
160 public const STATUS_DOWNLOAD_LOG_NAMES = [
161 self::STATUS_DOWNLOAD_LOG_DOWNLOADING => 'Downloading',
162 ];
163
164 // Retention Cleanup Statuses
165 public const STATUS_CLEANUP_DELETING = 10;
166 public const STATUS_CLEANUP_NAMES = [
167 self::STATUS_CLEANUP_DELETING => 'Deleting',
168 ];
169
170 // System Statuses
171 public const STATUS_SYSTEM_JOB_MONITOR = 10;
172 public const STATUS_SYSTEM_DB_CLEANUP = 15;
173 public const STATUS_SYSTEM_UPLOAD_CLEANUP = 17;
174 public const STATUS_SYSTEM_SYSTEM_CLEANUP = 20;
175 public const STATUS_SYSTEM_LOGS_CLEANUP = 25;
176 public const STATUS_SYSTEM_VALIDATE_CHECKSUMS = 30;
177
178 public const STATUS_SYSTEM_DAILY_ALERTS = 35;
179 public const STATUS_SYSTEM_NAMES = [
180 self::STATUS_SYSTEM_JOB_MONITOR => 'Backup Job Monitoring',
181 self::STATUS_SYSTEM_DB_CLEANUP => 'Database Cleanup',
182 self::STATUS_SYSTEM_UPLOAD_CLEANUP => 'Uploads Cleanup',
183 self::STATUS_SYSTEM_SYSTEM_CLEANUP => 'System Cleanup',
184 self::STATUS_SYSTEM_LOGS_CLEANUP => 'Logs Cleanup',
185 self::STATUS_SYSTEM_VALIDATE_CHECKSUMS => 'Validating Checksums',
186 self::STATUS_SYSTEM_DAILY_ALERTS => 'Process Daily Alerts',
187 ];
188
189 public const STATUS_PENDING = 1;
190 public const STATUS_STARTED = 2;
191 public const STATUS_PREPARING = 3;
192 public const STATUS_DONE = 100;
193 public const STATUS_PARTIALLY = 101;
194 public const STATUS_FAILED = 102;
195 public const STATUS_ABORTED = 103;
196 public const STATUS_NEVER_FINISHED = 104;
197
198 public const STATUS_NAMES = [
199 self::STATUS_PENDING => 'Pending',
200 self::STATUS_STARTED => 'Started',
201 self::STATUS_PREPARING => 'Preparing',
202 self::STATUS_DONE => 'Completed',
203 self::STATUS_PARTIALLY => 'Partially Completed',
204 self::STATUS_FAILED => 'Failed',
205 self::STATUS_ABORTED => 'Aborted',
206 self::STATUS_NEVER_FINISHED => 'Never Finished',
207 ];
208
209
210 public function __construct() {}
211
212
213 public function getNext():?QueueItem {
214 $res = QueueItem::query()
215 ->select([JetBackup::ID_FIELD])
216 ->where([QueueItem::STATUS, '<', self::STATUS_DONE])
217 ->orderBy([QueueItem::STATUS => 'asc'])
218 ->limit(1)
219 ->getQuery()
220 ->first();
221
222 return $res ? new QueueItem($res[JetBackup::ID_FIELD]) : null;
223 }
224
225 public static function next():?QueueItem {
226 return (new Queue())->getNext();
227 }
228
229 /**
230 * @throws IOException
231 * @throws InvalidArgumentException
232 */
233 public static function inQueue($type, $_id=null):bool {
234 $query = QueueItem::query()
235 ->where([ QueueItem::TYPE, '=', $type ])
236 ->where([ QueueItem::STATUS, '<', self::STATUS_DONE ]);
237 if($_id) $query->where([ QueueItem::ITEM_ID, '=', $_id ]);
238 return !!$query->getQuery()->first();
239 }
240
241 /**
242 * @throws InvalidArgumentException
243 * @throws IOException
244 */
245 public static function getTotalActiveItems(): int {
246
247 return count(QueueItem::query()
248 ->select([JetBackup::ID_FIELD])
249 ->where([QueueItem::STATUS, '<', self::STATUS_DONE])
250 ->getQuery()
251 ->fetch());
252 }
253 /**
254 * @throws InvalidArgumentException
255 * @throws IOException
256 */
257 public static function getTotalPendingItems(): int {
258 return count(QueueItem::query()
259 ->select([JetBackup::ID_FIELD])
260 ->where([QueueItem::STATUS, '=', self::STATUS_PENDING])
261 ->getQuery()
262 ->fetch());
263 }
264
265 /**
266 * @throws InvalidArgumentException
267 * @throws IOException
268 */
269 public static function getTotalCompletedItems(): int {
270 return count(QueueItem::query()
271 ->select([JetBackup::ID_FIELD])
272 ->where([QueueItem::STATUS, '=', self::STATUS_DONE])
273 ->getQuery()
274 ->fetch());
275 }
276
277 /**
278 * @throws InvalidArgumentException
279 * @throws IOException
280 */
281 public static function getTotalAbortedItems(): int {
282 return count(QueueItem::query()
283 ->select([JetBackup::ID_FIELD])
284 ->where([QueueItem::STATUS, '=', self::STATUS_ABORTED])
285 ->getQuery()
286 ->fetch());
287 }
288
289 public static function clearCompleted(): void {
290
291 QueueItem::query()->select([JetBackup::ID_FIELD])
292 ->where([QueueItem::STATUS, '>=', self::STATUS_DONE])
293 ->getQuery()
294 ->delete();
295
296 }
297
298
299
300 /**
301 * @param QueueItem $item
302 *
303 * @return void
304 * @throws QueueException
305 * @throws IOException
306 * @throws InvalidArgumentException
307 */
308 public static function addToQueue(QueueItem $item):void {
309 if(self::inQueue($item->getType(), $item->getItemId())) throw new QueueException("Already in queue");
310 $item->save();
311 }
312 }