PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.18.8
JetBackup – Backup, Restore & Migrate v3.1.18.8
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 / CLI / Command.php
backup / src / JetBackup / CLI Last commit date
.htaccess 5 months ago CLI.php 5 months ago Command.php 5 months ago index.html 5 months ago web.config 5 months ago
Command.php
1195 lines
1 <?php
2
3 namespace JetBackup\CLI;
4
5 use JetBackup\Ajax\iAjax;
6 use JetBackup\BackupJob\BackupJob;
7 use JetBackup\Destination\Destination;
8 use JetBackup\Exception\AjaxException;
9 use JetBackup\Factory;
10 use JetBackup\JetBackup;
11 use JetBackup\Schedule\Schedule;
12 use JetBackup\Settings\Integrations;
13 use WP_CLI;
14
15 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
16
17 /**
18 * All-in-one Website Backup Platform
19 *
20 * @when after_wp_load
21 */
22 class Command {
23
24 const FLAGS = [
25 'backup_path' => Destination::PATH,
26 'id' => JetBackup::ID_FIELD
27 ];
28 /**
29 * Add item to the queue
30 *
31 * ## OPTIONS
32 *
33 * --type=<type>
34 * : The queue type (1 = backup, 2 = restore, 4 = download, 8 = reindex, 64 = export, 128 = extract)
35 *
36 * [--id=<backup-job-id,snapshot-id,destination-id>]
37 * : The object id to add to queue (depend on the queue type, for backup - backup job id, for restore, download, export and extract - snapshot id, for reindex - destination id)
38 *
39 * [--snapshot_path=<absolute-path-to-snapshot>]
40 * : The snapshot path to import (restore from file)
41 *
42 * [--panel_type=<panel-type>]
43 * : The panel type to export to (1 = cPanel, 2 = DirectAdmin)
44 *
45 * ## EXAMPLES
46 *
47 * wp jetbackup addToQueue --type=2 --id=2
48 * wp jetbackup addToQueue --type=64 --id=5 --panel_type=1
49 * wp jetbackup addToQueue --type=2 --snapshot_path="/home/user/public_html/mybackup.tar.gz"
50 *
51 * @when after_wp_load
52 */
53
54 /**
55 * WordPress cli will not accept upper case flags (internal case #706)
56 * @param array $flags
57 *
58 * @return array
59 */
60 private static function _keyToUpper(array $flags): array {
61 $array = [];
62 foreach ($flags as $key => $value) {$array[strtoupper($key)] = $value;}
63 return $array;
64 }
65
66 private static function _argsToArray($args) {
67 if (preg_match('/^(?:\[.*]|\{.*})$/s', $args)) return json_decode($args, true);
68 return $args;
69 }
70 public function addToQueue($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
71
72 /**
73 * Delete backup job
74 *
75 * ## OPTIONS
76 *
77 * --id=<id>
78 * : The backup job id to delete
79 *
80 * ## EXAMPLES
81 *
82 * wp jetbackup deleteBackupJob --id=2
83 *
84 * @when after_wp_load
85 */
86 public function deleteBackupJob($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
87
88 /**
89 * Delete destination
90 *
91 * ## OPTIONS
92 *
93 * --id=<id>
94 * : The destination id to delete
95 *
96 * ## EXAMPLES
97 *
98 * wp jetbackup deleteDestination --id=2
99 *
100 * @when after_wp_load
101 */
102 public function deleteDestination($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
103
104 /**
105 * Abort queue item
106 *
107 * ## OPTIONS
108 *
109 * --id=<id>
110 * : The queue item id to delete
111 *
112 * ## EXAMPLES
113 *
114 * wp jetbackup abortQueueItem --id=2
115 *
116 * @when after_wp_load
117 */
118 public function abortQueueItem($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
119
120 /**
121 * Delete backup
122 *
123 * ## OPTIONS
124 *
125 * --id=<id>
126 * : The snapshot id to delete
127 *
128 * ## EXAMPLES
129 *
130 * wp jetbackup deleteSnapshot --id=2
131 *
132 * @when after_wp_load
133 */
134 public function deleteSnapshot($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
135
136 /**
137 * Delete download
138 *
139 * ## OPTIONS
140 *
141 * --id=<id>
142 * : The download id to delete
143 *
144 * ## EXAMPLES
145 *
146 * wp jetbackup deleteSnapshot --id=2
147 *
148 * @when after_wp_load
149 */
150 public function deleteDownload($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
151
152 /**
153 * Enable/Disable export config
154 *
155 * ## OPTIONS
156 *
157 * --id=<id>
158 * : the ID of the destination to configure.
159 *
160 * ## EXAMPLES
161 *
162 * wp jetbackup destinationSetExportConfig --id=2
163 *
164 * @when after_wp_load
165 */
166 public function destinationSetExportConfig($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
167
168 /**
169 * Duplicate backup job
170 *
171 * ## OPTIONS
172 *
173 * --id=<id>
174 * : Job id of the job to duplicate.
175 *
176 * ## EXAMPLES
177 *
178 * wp jetbackup duplicateBackupJob --id=2
179 *
180 * @when after_wp_load
181 */
182 public function duplicateBackupJob($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
183
184 /**
185 * Edit the notes of a backup.
186 *
187 * ## OPTIONS
188 *
189 * --id=<id>
190 * : The id of the backup whose notes you want to edit
191 *
192 * --notes=<notes>
193 * : The new notes to associate with the backup
194 *
195 * ## EXAMPLES
196 *
197 * wp jetbackup editBackupNotes --id=2 --notes="test"
198 *
199 * @when after_wp_load
200 */
201 public function editBackupNotes($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
202
203 /**
204 * Enable/Disable backup job (Toggle the backup job status: enable to disable or disable to enable with a single action)
205 *
206 * ## OPTIONS
207 *
208 * --id=<id>
209 * : The id of backup job enable/disable
210 *
211 * ## EXAMPLES
212 *
213 * wp jetbackup enableBackupJob --id=2
214 *
215 * @when after_wp_load
216 */
217 public function enableBackupJob($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
218
219 /**
220 * Enable/Disable destination (Toggle the destination status: enable to disable or disable to enable with a single action)
221 *
222 * ## OPTIONS
223 *
224 * --id=<id>
225 * : The id of Destination to enable/disable
226 *
227 * ## EXAMPLES
228 *
229 * wp jetbackup enableDestination --id=2
230 *
231 * @when after_wp_load
232 */
233 public function enableDestination($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
234
235 /**
236 * Retrieve a single backup
237 *
238 * ## OPTIONS
239 *
240 * --id=<snapshot-id>
241 * : The id of the backup to retrieve
242 *
243 * ## EXAMPLES
244 *
245 * wp jetbackup getBackup --id=2
246 *
247 * @when after_wp_load
248 */
249 public function getBackup($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
250 /**
251 * Retrieve a single backup job
252 *
253 * ## OPTIONS
254 *
255 * --id=<backup-job-id>
256 * : The id of the backup job to retrieve
257 *
258 * ## EXAMPLES
259 *
260 * wp jetbackup getBackupJob --id=2
261 *
262 * @when after_wp_load
263 */
264
265 public function getBackupJob($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
266
267 /**
268 * Retrieve a single destination
269 *
270 * ## OPTIONS
271 *
272 * --id=<destination-id>
273 * : The id of the destination to retrieve
274 *
275 * ## EXAMPLES
276 *
277 * wp jetbackup getDestination --id=2
278 *
279 * @when after_wp_load
280 */
281 public function getDestination($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
282
283 /**
284 * Retrieve a single queue item
285 *
286 * ## OPTIONS
287 *
288 * --id=<queue-item-id>
289 * : The id of the queue item to retrieve
290 *
291 * ## EXAMPLES
292 *
293 * wp jetbackup getQueueItem --id=2
294 *
295 * @when after_wp_load
296 */
297 public function getQueueItem($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
298 /**
299 * Retrieve a single schedule
300 *
301 * ## OPTIONS
302 *
303 * --id=<schedule-id>
304 * : The id of the schedule to retrieve
305 *
306 * ## EXAMPLES
307 *
308 * wp jetbackup getSchedule --id=2
309 *
310 * @when after_wp_load
311 */
312 public function getSchedule($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
313
314 /**
315 * Retrieve log data or full content from a queue item.
316 *
317 * ## OPTIONS
318 *
319 * --queue_item_id=<queue-item-id>
320 * : The ID of the queue item to fetch the log for.
321 *
322 * --content=<bool>
323 * : If set, the actual content of the log file will be returned.
324 *
325 * ## EXAMPLES
326 *
327 * wp jetbackup getLog --queue_item_id=123 --content=0
328 * wp jetbackup getLog --queue_item_id=123 --content=1
329 *
330 * @when after_wp_load
331 */
332 public function getLog($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
333
334 /**
335 * List all backup jobs
336 *
337 * ## OPTIONS
338 *
339 * --id=<snapshot-id>
340 * : The id of the snapshot item to retrieve (Must be homedir snapshot item indexed from JetBackup Linux integration)
341 *
342 * --location=<path>
343 * : The path location to browse (from WP public directory)
344 *
345 * [--limit=<limit>]
346 * : limit the result to the specified number (default to 99999)
347 *
348 * [--skip=<skip>]
349 * : skip the result to the specified number (default to 0)
350 *
351 * [--sort=<sort>]
352 * : sort the result (default to asc)
353 *
354 * ## EXAMPLES
355 *
356 * wp jetbackup listBackupJobs --limit=5 --sort=desc
357 *
358 * @when after_wp_load
359 */
360 public function fileManager($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
361
362 /**
363 * Retrieve automation settings
364 *
365 * ## EXAMPLES
366 *
367 * wp jetbackup getSettingsAutomation
368 *
369 * @when after_wp_load
370 */
371 public function getSettingsAutomation($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
372
373 /**
374 * Retrieve general settings
375 *
376 * ## EXAMPLES
377 *
378 * wp jetbackup getSettingsGeneral
379 *
380 * @when after_wp_load
381 */
382 public function getSettingsGeneral($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
383
384 /**
385 * Retrieve logging settings
386 *
387 *
388 * ## EXAMPLES
389 *
390 * wp jetbackup getSettingsLogging
391 *
392 * @when after_wp_load
393 */
394 public function getSettingsLogging($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
395
396 /**
397 * Retrieve maintenance settings
398 *
399 *
400 * ## EXAMPLES
401 *
402 * wp jetbackup getSettingsMaintenance
403 *
404 * @when after_wp_load
405 */
406 public function getSettingsMaintenance($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
407
408 /**
409 * Retrieve notifications settings
410 *
411 *
412 * ## EXAMPLES
413 *
414 * wp jetbackup getSettingsNotifications
415 *
416 * @when after_wp_load
417 */
418 public function getSettingsNotifications($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
419 /**
420 * Retrieve performance settings
421 *
422 *
423 * ## EXAMPLES
424 *
425 * wp jetbackup getSettingsPerformance
426 *
427 * @when after_wp_load
428 */
429 public function getSettingsPerformance($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
430
431 /**
432 * Retrieve restore settings
433 *
434 *
435 * ## EXAMPLES
436 *
437 * wp jetbackup getSettingsRestore
438 *
439 * @when after_wp_load
440 */
441 public function getSettingsRestore($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
442
443 /**
444 * Retrieve Integrations settings
445 *
446 *
447 * ## EXAMPLES
448 *
449 * wp jetbackup getSettingsIntegrations
450 *
451 * @when after_wp_load
452 */
453 public function getSettingsIntegrations($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
454
455 /**
456 * Retrieve security settings
457 *
458 *
459 * ## EXAMPLES
460 *
461 * wp jetbackup getSettingsSecurity
462 *
463 * @when after_wp_load
464 */
465 public function getSettingsSecurity($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
466
467 /**
468 * Retrieve updates settings
469 *
470 *
471 * ## EXAMPLES
472 *
473 * wp jetbackup getSettingsUpdates
474 *
475 * @when after_wp_load
476 */
477 public function getSettingsUpdates($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
478
479 /**
480 * List all system alerts
481 *
482 * ## OPTIONS
483 *
484 * [--limit=<limit>]
485 * : limit the result to the specified number (default to 99999)
486 *
487 * [--skip=<skip>]
488 * : skip the result to the specified number (default to 0)
489 *
490 * [--sort=<sort>]
491 * : sort the result (default to asc)
492 *
493 * ## EXAMPLES
494 *
495 * wp jetbackup listAlerts --limit=5 --sort=desc
496 *
497 * @when after_wp_load
498 */
499 public function listAlerts($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
500
501 /**
502 * List all backup jobs
503 *
504 * ## OPTIONS
505 *
506 * [--limit=<limit>]
507 * : limit the result to the specified number (default to 99999)
508 *
509 * [--skip=<skip>]
510 * : skip the result to the specified number (default to 0)
511 *
512 * [--sort=<sort>]
513 * : sort the result (default to asc)
514 *
515 * ## EXAMPLES
516 *
517 * wp jetbackup listBackupJobs --limit=5 --sort=desc
518 *
519 * @when after_wp_load
520 */
521 public function listBackupJobs($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
522
523 /**
524 * List all backups
525 *
526 * ## OPTIONS
527 *
528 * [--limit=<limit>]
529 * : limit the result to the specified number (default to 99999)
530 *
531 * [--skip=<skip>]
532 * : skip the result to the specified number (default to 0)
533 *
534 * [--sort=<sort>]
535 * : sort the result (default to asc)
536 *
537 * ## EXAMPLES
538 *
539 * wp jetbackup listBackups --limit=5 --sort=desc
540 *
541 * @when after_wp_load
542 */
543 public function listBackups($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
544 /**
545 * List all destinations
546 *
547 * ## OPTIONS
548 *
549 * [--limit=<limit>]
550 * : limit the result to the specified number (default to 99999)
551 *
552 * [--skip=<skip>]
553 * : skip the result to the specified number (default to 0)
554 *
555 * [--sort=<sort>]
556 * : sort the result (default to asc)
557 *
558 * ## EXAMPLES
559 *
560 * wp jetbackup listDestinations --limit=5 --sort=desc
561 *
562 * @when after_wp_load
563 */
564 public function listDestinations($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
565
566 /**
567 * List available Downloads
568 *
569 * ## OPTIONS
570 *
571 * [--limit=<limit>]
572 * : limit the result to the specified number (default to 99999)
573 *
574 * [--skip=<skip>]
575 * : skip the result to the specified number (default to 0)
576 *
577 * [--sort=<sort>]
578 * : sort the result (default to asc)
579 *
580 * ## EXAMPLES
581 *
582 * wp jetbackup listDownloads --limit=5 --sort=desc
583 *
584 * @when after_wp_load
585 */
586 public function listDownloads($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
587
588 /**
589 * List all queue items
590 *
591 * ## OPTIONS
592 *
593 * [--limit=<limit>]
594 * : limit the result to the specified number (default to 99999)
595 *
596 * [--skip=<skip>]
597 * : skip the result to the specified number (default to 0)
598 *
599 * [--sort=<sort>]
600 * : sort the result (default to asc)
601 *
602 * ## EXAMPLES
603 *
604 * wp jetbackup listQueueItems --limit=5 --sort=desc
605 *
606 * @when after_wp_load
607 */
608 public function listQueueItems($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
609
610 /**
611 * List all schedules
612 *
613 * ## OPTIONS
614 *
615 * [--limit=<limit>]
616 * : limit the result to the specified number (default to 99999)
617 *
618 * [--skip=<skip>]
619 * : skip the result to the specified number (default to 0)
620 *
621 * [--sort=<sort>]
622 * : sort the result (default to asc)
623 *
624 * ## EXAMPLES
625 *
626 * wp jetbackup listSchedules --limit=5 --sort=desc
627 *
628 * @when after_wp_load
629 */
630 public function listSchedules($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
631 /**
632 * lock snapshot of a backup
633 *
634 * ## OPTIONS
635 *
636 * --id=<id>
637 * : backup id
638 *
639 * ## EXAMPLES
640 *
641 * wp jetbackup lockSnapshot --id=5
642 *
643 * @when after_wp_load
644 */
645 public function lockSnapshot($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
646
647 /**
648 * Create or modify backup job
649 *
650 * ## OPTIONS
651 *
652 * [--id=<backup-job-id>]
653 * : The backup job id to modify.
654 *
655 * [--name=<backup-job-name>]
656 * : The backup job name.
657 *
658 * [--type=<backup-job-type>]
659 * : The backup job type (1 for Account, 2 for Config).
660 *
661 * [--backup_contains=<backup-contains>]
662 * : The backup contains type (Files backup only = 1,Database backup only = 2, Full backup = 3).
663 *
664 * [--destinations=<list-of-destination-ids>]
665 * : The backup job destinations (json format)
666 *
667 * [--excludes=<list-of-files-to-exclude>]
668 * : Exclude files from backup (json format)
669 *
670 * [--database_excludes=<list-of-database-tables-to-exclude>]
671 * : Exclude database tables from backup (json format)
672 *
673 * [--job_monitor=<days>]
674 * : Will notify you if the backup wasn't executed within the specified number of days
675 *
676 * [--schedule_time=<time>]
677 * : The time that you want to execute the backup job
678 *
679 * [--schedules=<list-of-schedules>]
680 * : The schedules that you want this backup job will be executed (json format)
681 *
682 * [--enabled=<enabled>]
683 * : Set backup job enabled or disabled
684 *
685 * ## EXAMPLES
686 *
687 * wp jetbackup manageBackupJob --id=24 --name="Daily Backup" --enabled=0
688 * wp jetbackup manageBackupJob --name="Weekly Backup" --type=1 --destinations='[2,4,5]' --schedules='[{"_id":1,"retain":10}]' --excludes='["/test","/test2"]' --schedule_time=13:00 --backup_contains=3
689 *
690 * @when after_wp_load
691 */
692 public function manageBackupJob($args, $flags) {
693 if (isset($flags[BackupJob::DESTINATIONS])) $flags[BackupJob::DESTINATIONS] = self::_argsToArray($flags[BackupJob::DESTINATIONS]);
694 if (isset($flags[BackupJob::SCHEDULES])) $flags[BackupJob::SCHEDULES] = self::_argsToArray($flags[BackupJob::SCHEDULES]);
695 if (isset($flags[BackupJob::EXCLUDES])) $flags[BackupJob::EXCLUDES] = self::_argsToArray($flags[BackupJob::EXCLUDES]);
696 self::_command(__FUNCTION__, $args, $flags);
697 }
698
699 /**
700 * Manage destination
701 *
702 * ## OPTIONS
703 *
704 * [--id=<destination-id>]
705 * : the id of destination to modify.
706 *
707 * [--name=<destination-name>]
708 * : the destination name
709 *
710 * [--type=<type>]
711 * : the destination type (e.g. Local,SFTP,GoogleDrive,S3,OneDrive,Dropbox,Box,pCloud)
712 *
713 * [--read_only=<read_only>]
714 * : Set read_only option , In a read-only destination you only will be able to restore and download existing backups. No write to this destination will be allowed
715 *
716 * [--chunk_size=<chunk_size>]
717 * : Set the default read/write chunk size. Smaller chunks suit small files or slow connections, while larger chunks are better for big files on fast, stable networks.
718 *
719 * [--notes=<notes>]
720 * : Add internal notes to help identify or describe this destination.
721 *
722 * [--free_disk=<free_disk>]
723 * : This option will check if destination disk space reached the specified limit before it performs the backup. If you enable this option and available disk space is less than the amount specified, the system will not perform the backup.
724 *
725 * [--backup_path=<path>]
726 * : Define the directory path on the remote server for storing backups. Make sure it’s writable and uniquely identifies the domain (e.g., /backups/domain.com/).
727 *
728 * [--enabled=<enabled>]
729 * : Set destination enabled or disabled
730 *
731 * [--export_config=<export_config>]
732 * : Set export config enabled or disabled
733 *
734 * [--options=<json-options>]
735 * : Provide connection details and other advanced options in JSON format.
736 * Example: '{"host":"sftp_host","username":"sftp_user","password":"sftp_pass","port":22,"timeout":60,"retries":5}'
737 *
738 * ## EXAMPLES
739 *
740 * wp jetbackup manageDestination --id=5 --name="sftp" --enabled=0 --export_config=0 --chunk_size=1 --free_disk=0 --backup_path=/foo/boo --notes="This is a note" --options='{"host":"sftp_host","username":"sftp_user","password":"sftp_pass","port":22,"timeout":60,"retries":5}'
741 * wp jetbackup manageDestination --id=5 --name="google" --type=GoogleDrive --backup_path=/foo/boo --options='{"access_code":"YOU_ACCESS_CODE_HERE"}'
742 *
743 * @when after_wp_load
744 */
745 public function manageDestination($args, $flags) {
746 if (isset($flags[Destination::OPTIONS])) $flags[Destination::OPTIONS] = self::_argsToArray($flags[Destination::OPTIONS]);
747
748 self::_command(__FUNCTION__, $args, $flags);
749 }
750
751 /**
752 * Manage schedule
753 *
754 * ## OPTIONS
755 *
756 * [--id=<schedule-id>]
757 * : the id of schedule to modify.
758 *
759 * [--name=<schedule-name>]
760 * : the schedule name
761 *
762 * [--backup_id=<backup-id>]
763 * : Use this option to specify the job ID when the type is set to "type = 6 ( after backup job done )"
764 *
765 * [--type=<type>]
766 * : the schedule type (for , hourly = 1, daily = 2 ,weekly = 3 , monthly = 4 , after backup job done = 6 ,manually = 5)
767 *
768 * [--intervals=<intervals>]
769 * : Set the intervals (array format)
770 *
771 * ## EXAMPLES
772 *
773 * wp jetbackup manageSchedule --name="hourly schedule" --id=3 --intervals=[1]
774 * wp jetbackup manageSchedule --name="after job done schedule" --type=6 --backup_id=1
775 *
776 * @when after_wp_load
777 */
778 public function manageSchedule($args, $flags) {
779 // If 'intervals' is provided, convert to json if type daily or monthly
780 if (isset($flags[Schedule::INTERVALS])) $flags[Schedule::INTERVALS] = self::_argsToArray($flags[Schedule::INTERVALS]);
781 self::_command(__FUNCTION__, $args, $flags);
782 }
783
784 /**
785 * Manage automation settings
786 *
787 * ## OPTIONS
788 *
789 * [--heartbeat=<heartbeat>]
790 * : Enable (1) or disable (0) the queued tasks by the admin AJAX heartbeat call.
791 *
792 * [--heartbeat_ttl=<heartbeat_ttl>]
793 * : set the heartbeat TTL interval (time-to-live in seconds).
794 *
795 * [--crons=<crons>]
796 * : Enable (1) or disable (0) the scheduled cron system.
797 *
798 *
799 * [--cron_status=<cron_status>]
800 * : Enable (1) or disable (0) the Crontab Automation (will try to register a crontab entry in your system).
801 *
802 * ## EXAMPLES
803 *
804 * wp jetbackup manageSettingsAutomation --heartbeat=1 --heartbeat_ttl=1 --crons=1 --cron_status=1
805 *
806 * @when after_wp_load
807 */
808
809 public function manageSettingsAutomation($args, $flags) {self::_command(__FUNCTION__, $args, self::_keyToUpper($flags));}
810 /**
811 * Manage general settings for jetbackup plugin
812 *
813 * ## OPTIONS
814 *
815 * [--license_key=<license-key>]
816 * : Enter your backup plugin license key here to activate premium features, including enhanced backup options and priority support. Ensure your license key is valid and active to maintain uninterrupted access to all benefits.
817 *
818 * [--timezone=<timezone>]
819 * : Set timezone for jetbackup plugin
820 *
821 * [--community_languages=<bool>]
822 * : Enable/Disable community languages delivered by our languages CDN.
823 *
824 * [--jetbackup_integration=<bool>]
825 * : Enable/Disable API to server level JetBackup (Restore backups generated by your hosting provider's JetBackup).
826 *
827 * [--admin_top_menu_integration=<bool>]
828 * : Enable/Disable Admin top menu bar integration.
829 *
830 * [--display_local_free_disk_space=<bool>]
831 * : Show available disk space in the system info page.
832 *
833 * [--manual_backups_retention=<int>]
834 * : This setting determines how many manual backups to keep per destination. Set to 0 to disable retention and never delete backups.
835 *
836 * [--alternate_wp_config_location=<path>]
837 * : Use this if your hosting provider uses a non-default wp-config location
838 *
839 * [--php_cli_location=<path>]
840 * : JetBackup relies on PHP CLI for background operations, here you can set specific path for php binary.
841 *
842 * [--mysql_default_port=<int>]
843 * : JetBackup will attempt to automatically detect the MySQL port from your system settings. If it cannot be determined, this value will be used as the default fallback.
844 *
845 * ## EXAMPLES
846 *
847 * wp jetbackup manageSettingsGeneral --license_key=xxxx --timezone=UTC --jetbackup_integration=1 --manual_backups_retention=0 --alternate_wp_config_location /home/user/config/wp-config.php --php_cli_location=/usr/bin/php --mysql_default_port=3306
848 *
849 * @when after_wp_load
850 */
851
852 public function manageSettingsGeneral($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
853
854 /**
855 * Manage log settings
856 *
857 * ## OPTIONS
858 *
859 * [--debug=<debug>]
860 * : enable or disable debug logging.
861 *
862 * [--log_rotate=<log_rotate>]
863 * : specify the number of days to retain log files. older logs beyond this duration will be automatically deleted. set this value to 0 to keep logs indefinitely.
864 *
865 * ## EXAMPLES
866 *
867 * wp jetbackup manageSettingsLogging --debug=1 --log_rotate=7
868 *
869 * @when after_wp_load
870 */
871 public function manageSettingsLogging($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
872
873
874 /**
875 * Manage maintenance settings
876 *
877 * ## OPTIONS
878 *
879 * [--maintenance_queue_hours_ttl=<maintenance_queue_hours_ttl>]
880 * : clear completed items from the queue table after a specified number of hours. set to 0 to disable.
881 *
882 * [--maintenance_download_items_ttl=<maintenance_download_items_ttl>]
883 * : After the specified number of hours, expired items will be automatically deleted. Enter a value in hours. set to 0 to disable.
884 *
885 * [--maintenance_download_limit=<maintenance_download_items_ttl>]
886 * : Sets the max active downloads. If the limit is reached, clear one to start a new download. set to 0 to disable.
887 *
888 * [--maintenance_queue_alerts_ttl=<maintenance_queue_alerts_ttl>]
889 * : clear system alerts after a specified number of hours. set to 0 to disable.
890 *
891 * [--config_export_rotate=<config_export_rotate>]
892 * : specify the number of exported config backups to keep. older exports will be deleted. set to 0 to keep indefinitely.
893 *
894 * ## EXAMPLES
895 *
896 * wp jetbackup manageSettingsMaintenance --maintenance_queue_hours_ttl=24 --maintenance_download_limit=5 --maintenance_download_items_ttl=72 --maintenance_queue_alerts_ttl=72 --config_export_rotate=2
897 *
898 * @when after_wp_load
899 */
900 public function manageSettingsMaintenance($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
901
902
903 /**
904 * Manage notification settings
905 *
906 * ## OPTIONS
907 *
908 * [--emails=<emails>]
909 * : enable or disable email notifications.
910 *
911 * [--alternate_email=<alternate_email>]
912 * : set an alternate email address for notifications instead of the default admin email.
913 *
914 * ## EXAMPLES
915 *
916 * wp jetbackup manageSettingsNotifications --emails=1 --alternate_email=youremail@gmail.com
917 *
918 * @when after_wp_load
919 */
920 public function manageSettingsNotifications($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
921
922
923 /**
924 * Manage performance settings
925 *
926 * ## OPTIONS
927 *
928 * [--read_chunk_size=<read_chunk_size>]
929 * : set the chunk size for file uploads. affects upload speed and stability.
930 *
931 * [--execution_time=<execution_time>]
932 * : define the maximum execution time (in seconds) for queued tasks. applies only to web-based tasks.
933 *
934 * [--sql_cleanup_revisions=<sql_cleanup_revisions>]
935 * : enable or disable cleaning up old revisions before dumping databases.
936 *
937 * [--use_default_excludes=<use_default_excludes>]
938 * : enable or disable the default file exclude list for backups.
939 *
940 * [--exclude_nested_sites=<exclude_nested_sites>]
941 * : exclude WordPress installations within the first subdirectory level.
942 *
943 * [--use_default_db_excludes=<use_default_db_excludes>]
944 * : exclude known temporary database tables.
945 *
946 * [--gzip_compress_archive=<gzip_compress_archive>]
947 * : enable or disable gzip compression for backup archives.
948 *
949 * [--gzip_compress_db=<gzip_compress_db>]
950 * : enable or disable gzip compression for database backups.
951 *
952 * ## EXAMPLES
953 *
954 * wp jetbackup manageSettingsPerformance --read_chunk_size=2097152 --execution_time=10 --sql_cleanup_revisions=1 --use_default_excludes=1 --gzip_compress_archive=1
955 *
956 * @when after_wp_load
957 */
958 public function manageSettingsPerformance($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
959
960
961 /**
962 * Manage restore settings
963 *
964 * ## OPTIONS
965 *
966 * [--restore_compatibility_check=<restore_compatibility_check>]
967 * : enable or disable checking system compatibility before restoring a backup.
968 *
969 * [--restore_allow_cross_domain=<bool>]
970 * : allow (1) or disallow (0) restoring backups across different domains.
971 *
972 * [--restore_alternate_path=<bool>]
973 * : enable (1) or disable (0) using alternate public restore path
974 *
975 * [--restore_wp_content_only=<bool>]
976 * : enable (1) or disable (0) limit restore to wp-content folder only
977 *
978 * ## EXAMPLES
979 *
980 * wp jetbackup manageSettingsRestore --restore_compatibility_check=1 --restore_allow_cross_domain=1 --restore_alternate_path=1 --restore_wp_content_only=1
981 *
982 * @when after_wp_load
983 */
984 public function manageSettingsRestore($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
985
986 /**
987 * Manage Integration settings
988 *
989 * ## OPTIONS
990 *
991 * [--integrations=<array>]
992 * : Enable integrations
993 *
994 * ## EXAMPLES
995 *
996 * wp jetbackup manageSettingsIntegrations --integrations='["Elementor","Supercache", "Woocommerce"]'
997 *
998 * @when after_wp_load
999 */
1000 public function manageSettingsIntegrations($args, $flags) {
1001 if (isset($flags[Integrations::INTEGRATIONS])) $flags[Integrations::INTEGRATIONS] = self::_argsToArray($flags[Integrations::INTEGRATIONS]);
1002 self::_command(__FUNCTION__, $args, $flags);
1003 }
1004
1005
1006 /**
1007 * Manage security settings
1008 *
1009 * ## OPTIONS
1010 *
1011 * [--mfa_enabled=<bool>]
1012 * : enable (1) or disable (0) two-factor authentication for additional security.
1013 *
1014 * [--alternate_data_folder=<alternate_data_folder>]
1015 * : specify a custom data directory for storing configuration and backup data.
1016 *
1017 * [--daily_checksum_check=<daily_checksum_check>]
1018 * : enable or disable daily checksum verification of WordPress core files.
1019 *
1020 * ## EXAMPLES
1021 *
1022 * wp jetbackup manageSettingsSecurity --mfa_enabled=1 --daily_checksum_check=1 --alternate_data_folder=/custom/path
1023 *
1024 * @when after_wp_load
1025 */
1026 public function manageSettingsSecurity($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
1027
1028
1029 /**
1030 * Manage update settings
1031 *
1032 * ## OPTIONS
1033 *
1034 * [--update_tier=<update_tier>]
1035 * : set the update tier (release, rc, edge, or alpha) to determine how frequently updates are received.
1036 *
1037 * ## EXAMPLES
1038 *
1039 * wp jetbackup manageSettingsUpdates --update_tier=release
1040 *
1041 * @when after_wp_load
1042 */
1043 public function manageSettingsUpdates($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
1044
1045 /**
1046 * Manage sendTestEmail settings
1047 *
1048 * ## OPTIONS
1049 *
1050 * --alternate_email=<alternate_email>
1051 * : Set alternate email (email notifications will be sent by default to the "Admin Email" (set in Settings > General), this will override this option)
1052 *
1053 * ## EXAMPLES
1054 *
1055 * wp jetbackup sendTestEmail --alternate_email=youremail@gmail.com
1056 *
1057 * @when after_wp_load
1058 */
1059 public function sendTestEmail($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1060
1061 /**
1062 * Start over queue item
1063 *
1064 * ## OPTIONS
1065 *
1066 * --id=<id>
1067 * : id of the queue item
1068 *
1069 * ## EXAMPLES
1070 *
1071 * wp jetbackup startOverQueueItem --id=5
1072 *
1073 * @when after_wp_load
1074 */
1075
1076 public function startOverQueueItem($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1077
1078 /**
1079 * Validate destination
1080 *
1081 * ## OPTIONS
1082 *
1083 * --id=<id>
1084 * : id of the destination to validate
1085 *
1086 * ## EXAMPLES
1087 *
1088 * wp jetbackup validateDestination --id=5
1089 *
1090 * @when after_wp_load
1091 */
1092 public function validateDestination($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1093
1094 /**
1095 * Execute JetBackup's internal cron scheduler
1096 *
1097 * ## OPTIONS
1098 *
1099 * [--debug]
1100 * : Add more debug verbosity to output
1101 *
1102 * ## EXAMPLES
1103 *
1104 * wp jetbackup executeCron --debug
1105 *
1106 * @when after_wp_load
1107 */
1108 public function executeCron($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1109
1110
1111 /**
1112 * Clears Complete queue items
1113 *
1114 * ## EXAMPLES
1115 *
1116 * wp jetbackup clearCompletedQueueItems
1117 *
1118 * @when after_wp_load
1119 */
1120 public function clearCompletedQueueItems($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1121
1122 /**
1123 * Clear All Alerts
1124 *
1125 * ## EXAMPLES
1126 *
1127 * wp jetbackup clearAlerts
1128 *
1129 * @when after_wp_load
1130 */
1131 public function clearAlerts($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1132
1133 // Some flags such as --path are taken by wpcli, so we need to use alternate names and translate back
1134 private static function translateFlags (array $flags) : array {
1135 if (empty($flags)) return [];
1136 foreach ($flags as $key => $value) {
1137 if (isset(self::FLAGS[$key])) {
1138 $flags[self::FLAGS[$key]] = $value;
1139 unset($flags[$key]);
1140 }
1141 }
1142 return $flags;
1143 }
1144
1145 private static function _command($func, $args, $flags) {
1146
1147 $method = "\JetBackup\Ajax\Calls\\" . ucfirst($func);
1148
1149 $output = isset($flags['output']) && in_array($flags['output'], CLI::OUTPUT_TYPES) ? $flags['output'] : CLI::OUTPUT_TYPE_TABLE;
1150 if(isset($flags['output'])) unset($flags['output']);
1151
1152 if(isset($flags['sort']) && $flags['sort'] == 'desc') $flags['sort'] = ['_id' => 'desc'];
1153 else $flags['sort'] = ['_id' => 'asc'];
1154
1155 $flags = self::translateFlags($flags);
1156
1157 /** @var iAjax $call */
1158 $call = new $method();
1159 $call->setData($flags);
1160 $call->setCLI(true);
1161
1162 try {
1163 if (Factory::getSettingsSecurity()->isMFAEnabled() && !Factory::getSettingsSecurity()->isMFAAllowCLI()) throw new AjaxException('CLI Mode is not available when MFA Enabled, you override this through the Settings -> Security');
1164 $call->execute();
1165 } catch (AjaxException $e) {
1166 $message = $e->getMessage();
1167 if($e->getData()) $message = vsprintf($message, $e->getData());
1168 self::error($message);
1169 }
1170
1171 if($call->getResponseMessage()) self::line($call->getResponseMessage());
1172 if($list = $call->getResponseData()) {
1173 if(!isset($list[0])) $list = [$list];
1174 self::output($list, array_keys($list[0]), $output);
1175 }
1176 }
1177
1178 private static function output($data, $headers, $type) {
1179 error_reporting(E_ALL & ~E_DEPRECATED); // issue 247
1180 WP_CLI\Utils\format_items($type, $data, $headers);
1181 }
1182
1183 private static function line($text) {
1184 WP_CLI::line($text);
1185 }
1186
1187 private static function error($text) {
1188 WP_CLI::error($text);
1189 }
1190
1191 private static function success($text) {
1192 WP_CLI::success($text);
1193 }
1194 }
1195