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 / Queue / Queue.php
backup / src / JetBackup / Queue Last commit date
.htaccess 1 year ago Progress.php 1 year ago Queue.php 5 months ago QueueItem.php 1 day ago QueueItemBackup.php 5 months 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
318 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 REQUIRES_CLEANUP = [
199 self::STATUS_FAILED,
200 self::STATUS_ABORTED,
201 self::STATUS_NEVER_FINISHED,
202 ];
203
204 public const STATUS_NAMES = [
205 self::STATUS_PENDING => 'Pending',
206 self::STATUS_STARTED => 'Started',
207 self::STATUS_PREPARING => 'Preparing',
208 self::STATUS_DONE => 'Completed',
209 self::STATUS_PARTIALLY => 'Partially Completed',
210 self::STATUS_FAILED => 'Failed',
211 self::STATUS_ABORTED => 'Aborted',
212 self::STATUS_NEVER_FINISHED => 'Never Finished',
213 ];
214
215
216 public function __construct() {}
217
218
219 public function getNext():?QueueItem {
220 $res = QueueItem::query()
221 ->select([JetBackup::ID_FIELD])
222 ->where([QueueItem::STATUS, '<', self::STATUS_DONE])
223 ->orderBy([QueueItem::STATUS => 'asc'])
224 ->limit(1)
225 ->getQuery()
226 ->first();
227
228 return $res ? new QueueItem($res[JetBackup::ID_FIELD]) : null;
229 }
230
231 public static function next():?QueueItem {
232 return (new Queue())->getNext();
233 }
234
235 /**
236 * @throws IOException
237 * @throws InvalidArgumentException
238 */
239 public static function inQueue($type, $_id=null):bool {
240 $query = QueueItem::query()
241 ->where([ QueueItem::TYPE, '=', $type ])
242 ->where([ QueueItem::STATUS, '<', self::STATUS_DONE ]);
243 if ($_id !== null) $query->where([ QueueItem::ITEM_ID, '=', $_id ]);
244 return !!$query->getQuery()->first();
245 }
246
247 /**
248 * @throws InvalidArgumentException
249 * @throws IOException
250 */
251 public static function getTotalActiveItems(): int {
252
253 return count(QueueItem::query()
254 ->select([JetBackup::ID_FIELD])
255 ->where([QueueItem::STATUS, '<', self::STATUS_DONE])
256 ->getQuery()
257 ->fetch());
258 }
259 /**
260 * @throws InvalidArgumentException
261 * @throws IOException
262 */
263 public static function getTotalPendingItems(): int {
264 return count(QueueItem::query()
265 ->select([JetBackup::ID_FIELD])
266 ->where([QueueItem::STATUS, '=', self::STATUS_PENDING])
267 ->getQuery()
268 ->fetch());
269 }
270
271 /**
272 * @throws InvalidArgumentException
273 * @throws IOException
274 */
275 public static function getTotalCompletedItems(): int {
276 return count(QueueItem::query()
277 ->select([JetBackup::ID_FIELD])
278 ->where([QueueItem::STATUS, '=', self::STATUS_DONE])
279 ->getQuery()
280 ->fetch());
281 }
282
283 /**
284 * @throws InvalidArgumentException
285 * @throws IOException
286 */
287 public static function getTotalAbortedItems(): int {
288 return count(QueueItem::query()
289 ->select([JetBackup::ID_FIELD])
290 ->where([QueueItem::STATUS, '=', self::STATUS_ABORTED])
291 ->getQuery()
292 ->fetch());
293 }
294
295 public static function clearCompleted(): void {
296
297 QueueItem::query()->select([JetBackup::ID_FIELD])
298 ->where([QueueItem::STATUS, '>=', self::STATUS_DONE])
299 ->getQuery()
300 ->delete();
301
302 }
303
304
305
306 /**
307 * @param QueueItem $item
308 *
309 * @return void
310 * @throws QueueException
311 * @throws IOException
312 * @throws InvalidArgumentException
313 */
314 public static function addToQueue(QueueItem $item):void {
315 if(self::inQueue($item->getType(), $item->getItemId())) throw new QueueException("Already in queue");
316 $item->save();
317 }
318 }