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 / CLI / Command.php
backup / src / JetBackup / CLI Last commit date
.htaccess 1 year ago CLI.php 1 year ago Command.php 1 day ago index.html 1 year ago web.config 1 year ago
Command.php
1225 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 * [--options=<json-options>]
729 * : Provide connection details and other advanced options in JSON format.
730 * Example: '{"host":"sftp_host","username":"sftp_user","password":"sftp_pass","port":22,"timeout":60,"retries":5}'
731 *
732 * ## EXAMPLES
733 *
734 * wp jetbackup manageDestination --id=5 --name="sftp"--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}'
735 * wp jetbackup manageDestination --id=5 --name="google" --type=GoogleDrive --backup_path=/foo/boo --options='{"access_code":"YOU_ACCESS_CODE_HERE"}'
736 *
737 * @when after_wp_load
738 */
739 public function manageDestination($args, $flags) {
740 if (isset($flags[Destination::OPTIONS])) $flags[Destination::OPTIONS] = self::_argsToArray($flags[Destination::OPTIONS]);
741
742 self::_command(__FUNCTION__, $args, $flags);
743 }
744
745 /**
746 * Manage schedule
747 *
748 * ## OPTIONS
749 *
750 * [--id=<schedule-id>]
751 * : the id of schedule to modify.
752 *
753 * [--name=<schedule-name>]
754 * : the schedule name
755 *
756 * [--backup_id=<backup-id>]
757 * : Use this option to specify the job ID when the type is set to "type = 6 ( after backup job done )"
758 *
759 * [--type=<type>]
760 * : the schedule type (for , hourly = 1, daily = 2 ,weekly = 3 , monthly = 4 , after backup job done = 6 ,manually = 5)
761 *
762 * [--intervals=<intervals>]
763 * : Set the intervals (array format)
764 *
765 * ## EXAMPLES
766 *
767 * wp jetbackup manageSchedule --name="hourly schedule" --id=3 --intervals=[1]
768 * wp jetbackup manageSchedule --name="after job done schedule" --type=6 --backup_id=1
769 *
770 * @when after_wp_load
771 */
772 public function manageSchedule($args, $flags) {
773 // If 'intervals' is provided, convert to json if type daily or monthly
774 if (isset($flags[Schedule::INTERVALS])) $flags[Schedule::INTERVALS] = self::_argsToArray($flags[Schedule::INTERVALS]);
775 self::_command(__FUNCTION__, $args, $flags);
776 }
777
778 /**
779 * Manage automation settings
780 *
781 * ## OPTIONS
782 *
783 * [--heartbeat=<heartbeat>]
784 * : Enable (1) or disable (0) the queued tasks by the admin AJAX heartbeat call.
785 *
786 * [--heartbeat_ttl=<heartbeat_ttl>]
787 * : set the heartbeat TTL interval (time-to-live in seconds).
788 *
789 * [--crons=<crons>]
790 * : Enable (1) or disable (0) the scheduled cron system.
791 *
792 *
793 * [--cron_status=<cron_status>]
794 * : Enable (1) or disable (0) the Crontab Automation (will try to register a crontab entry in your system).
795 *
796 * ## EXAMPLES
797 *
798 * wp jetbackup manageSettingsAutomation --heartbeat=1 --heartbeat_ttl=1 --crons=1 --cron_status=1
799 *
800 * @when after_wp_load
801 */
802
803 public function manageSettingsAutomation($args, $flags) {self::_command(__FUNCTION__, $args, self::_keyToUpper($flags));}
804 /**
805 * Manage general settings for jetbackup plugin
806 *
807 * ## OPTIONS
808 *
809 * [--license_key=<license-key>]
810 * : 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.
811 *
812 * [--timezone=<timezone>]
813 * : Set timezone for jetbackup plugin
814 *
815 * [--community_languages=<bool>]
816 * : Enable/Disable community languages delivered by our languages CDN.
817 *
818 * [--jetbackup_integration=<bool>]
819 * : Enable/Disable API to server level JetBackup (Restore backups generated by your hosting provider's JetBackup).
820 *
821 * [--admin_top_menu_integration=<bool>]
822 * : Enable/Disable Admin top menu bar integration.
823 *
824 * [--display_local_free_disk_space=<bool>]
825 * : Show available disk space in the system info page.
826 *
827 * [--manual_backups_retention=<int>]
828 * : This setting determines how many manual backups to keep per destination. Set to 0 to disable retention and never delete backups.
829 *
830 * [--imported_backups_retention=<int>]
831 * : This setting determines how many imported backups to keep. Set to 0 to disable retention and never delete imported backups. Default: 10.
832 *
833 * [--alternate_wp_config_location=<path>]
834 * : Use this if your hosting provider uses a non-default wp-config location
835 *
836 * [--php_cli_location=<path>]
837 * : JetBackup relies on PHP CLI for background operations, here you can set specific path for php binary.
838 *
839 * [--mysql_default_port=<int>]
840 * : 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.
841 *
842 * ## EXAMPLES
843 *
844 * wp jetbackup manageSettingsGeneral --license_key=xxxx --timezone=UTC --jetbackup_integration=1 --manual_backups_retention=0 --imported_backups_retention=10 --alternate_wp_config_location /home/user/config/wp-config.php --php_cli_location=/usr/bin/php --mysql_default_port=3306
845 *
846 * @when after_wp_load
847 */
848
849 public function manageSettingsGeneral($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
850
851 /**
852 * Manage log settings
853 *
854 * ## OPTIONS
855 *
856 * [--debug_log=<debug_log>]
857 * : enable or disable debug logging.
858 *
859 * [--log_rotate=<bool>]
860 * : 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.
861 *
862 * ## EXAMPLES
863 *
864 * wp jetbackup manageSettingsLogging --debug2=1 --log_rotate=7
865 *
866 * @when after_wp_load
867 */
868 public function manageSettingsLogging($args, $flags) {
869 // 'debug' is reserved by WP-CLI, so we cannot use it directly as a flag.
870 //// Map our custom 'debug_log' flag to 'debug' internally.
871 $flags['debug'] = $flags['debug_log'] ?? 0; // fallback to 0 if not set
872 self::_command(__FUNCTION__, $args, self::_keyToUpper($flags));
873
874 }
875
876
877 /**
878 * Manage maintenance settings
879 *
880 * ## OPTIONS
881 *
882 * [--maintenance_queue_hours_ttl=<maintenance_queue_hours_ttl>]
883 * : clear completed items from the queue table after a specified number of hours. set to 0 to disable.
884 *
885 * [--maintenance_download_items_ttl=<maintenance_download_items_ttl>]
886 * : After the specified number of hours, expired items will be automatically deleted. Enter a value in hours. set to 0 to disable.
887 *
888 * [--maintenance_download_limit=<maintenance_download_items_ttl>]
889 * : Sets the max active downloads. If the limit is reached, clear one to start a new download. set to 0 to disable.
890 *
891 * [--maintenance_queue_alerts_ttl=<maintenance_queue_alerts_ttl>]
892 * : clear system alerts after a specified number of hours. set to 0 to disable.
893 *
894 * [--config_export_rotate=<config_export_rotate>]
895 * : specify the number of exported config backups to keep. older exports will be deleted. set to 0 to keep indefinitely.
896 *
897 * ## EXAMPLES
898 *
899 * 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
900 *
901 * @when after_wp_load
902 */
903 public function manageSettingsMaintenance($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
904
905
906 /**
907 * Manage notification settings
908 *
909 * ## OPTIONS
910 *
911 * [--emails=<emails>]
912 * : enable or disable email notifications.
913 *
914 * [--alternate_email=<alternate_email>]
915 * : set an alternate email address for notifications instead of the default admin email.
916 *
917 * [--notification_levels_frequency=<notification_levels_frequency>]
918 * : JSON string for notification levels frequency.
919 * Levels:
920 * 1 = Information
921 * 2 = Warning
922 * 4 = Error
923 *
924 * Frequency:
925 * 0 = Disabled
926 * 1 = Real Time
927 * 2 = Once a day
928 * Example: '{"1":2,"2":0,"4":2}'
929 *
930 * ## EXAMPLES
931 *
932 * wp jetbackup manageSettingsNotifications --emails=1 --alternate_email=youremail@gmail.com
933 *
934 * @when after_wp_load
935 */
936 public function manageSettingsNotifications($args, $flags) {
937 if (isset($flags['notification_levels_frequency'])) {
938 $decoded = json_decode($flags['notification_levels_frequency'], true);
939 $flags['notification_levels_frequency'] = $decoded;
940 }
941 self::_command(__FUNCTION__, $args, self::_keyToUpper($flags));
942
943 }
944
945
946 /**
947 * Manage performance settings
948 *
949 * ## OPTIONS
950 *
951 * [--read_chunk_size=<read_chunk_size>]
952 * : set the chunk size for file uploads. affects upload speed and stability.
953 *
954 * [--performance_execution_time=<performance_execution_time>]
955 * : define the maximum execution time (in seconds) for queued tasks. applies only to web-based tasks.
956 *
957 * [--sql_cleanup_revisions=<sql_cleanup_revisions>]
958 * : enable or disable cleaning up old revisions before dumping databases.
959 *
960 * [--use_default_excludes=<use_default_excludes>]
961 * : enable or disable the default file exclude list for backups.
962 *
963 * [--exclude_nested_sites=<exclude_nested_sites>]
964 * : exclude WordPress installations within the first subdirectory level.
965 *
966 * [--use_default_db_excludes=<use_default_db_excludes>]
967 * : exclude known temporary database tables.
968 *
969 * [--gzip_compress_archive=<gzip_compress_archive>]
970 * : enable or disable gzip compression for backup archives.
971 *
972 * [--gzip_compress_db=<gzip_compress_db>]
973 * : enable or disable gzip compression for database backups.
974 *
975 * ## EXAMPLES
976 *
977 * wp jetbackup manageSettingsPerformance --read_chunk_size=2097152 --performance_execution_time=10 --sql_cleanup_revisions=1 --use_default_excludes=1 --gzip_compress_archive=1
978 *
979 * @when after_wp_load
980 */
981 public function manageSettingsPerformance($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
982
983
984 /**
985 * Manage restore settings
986 *
987 * ## OPTIONS
988 *
989 * [--restore_compatibility_check=<restore_compatibility_check>]
990 * : enable or disable checking system compatibility before restoring a backup.
991 *
992 * [--restore_allow_cross_domain=<bool>]
993 * : allow (1) or disallow (0) restoring backups across different domains.
994 *
995 * [--restore_alternate_path=<bool>]
996 * : enable (1) or disable (0) using alternate public restore path
997 *
998 * [--restore_wp_content_only=<bool>]
999 * : enable (1) or disable (0) limit restore to wp-content folder only
1000 *
1001 * ## EXAMPLES
1002 *
1003 * wp jetbackup manageSettingsRestore --restore_compatibility_check=1 --restore_allow_cross_domain=1 --restore_alternate_path=1 --restore_wp_content_only=1
1004 *
1005 * @when after_wp_load
1006 */
1007 public function manageSettingsRestore($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
1008
1009 /**
1010 * Manage Integration settings
1011 *
1012 * ## OPTIONS
1013 *
1014 * [--integrations=<array>]
1015 * : Enable integrations
1016 *
1017 * ## EXAMPLES
1018 *
1019 * wp jetbackup manageSettingsIntegrations --integrations='["Elementor","Supercache", "Woocommerce"]'
1020 *
1021 * @when after_wp_load
1022 */
1023 public function manageSettingsIntegrations($args, $flags) {
1024 if (isset($flags[Integrations::INTEGRATIONS])) $flags[Integrations::INTEGRATIONS] = self::_argsToArray($flags[Integrations::INTEGRATIONS]);
1025 self::_command(__FUNCTION__, $args, $flags);
1026 }
1027
1028
1029 /**
1030 * Manage security settings
1031 *
1032 * ## OPTIONS
1033 *
1034 * [--mfa_enabled=<bool>]
1035 * : enable (1) or disable (0) two-factor authentication for additional security.
1036 *
1037 * [--abilities_enabled=<bool>]
1038 * : enable (1) or disable (0) the read-only WordPress Abilities API surface (WordPress 6.9+).
1039 *
1040 * [--mfa_allow_abilities=<bool>]
1041 * : enable (1) or disable (0) Abilities API access while two-factor authentication is enabled.
1042 *
1043 * [--alternate_data_folder=<alternate_data_folder>]
1044 * : specify a custom data directory for storing configuration and backup data.
1045 *
1046 * [--daily_checksum_check=<daily_checksum_check>]
1047 * : enable or disable daily checksum verification of WordPress core files.
1048 *
1049 * ## EXAMPLES
1050 *
1051 * wp jetbackup manageSettingsSecurity --mfa_enabled=1 --daily_checksum_check=1 --alternate_data_folder=/custom/path
1052 * wp jetbackup manageSettingsSecurity --abilities_enabled=1 --mfa_allow_abilities=0
1053 *
1054 * @when after_wp_load
1055 */
1056 public function manageSettingsSecurity($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
1057
1058
1059 /**
1060 * Manage update settings
1061 *
1062 * ## OPTIONS
1063 *
1064 * [--update_tier=<update_tier>]
1065 * : set the update tier (release, rc, edge, or alpha) to determine how frequently updates are received.
1066 *
1067 * ## EXAMPLES
1068 *
1069 * wp jetbackup manageSettingsUpdates --update_tier=release
1070 *
1071 * @when after_wp_load
1072 */
1073 public function manageSettingsUpdates($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
1074
1075 /**
1076 * Manage sendTestEmail settings
1077 *
1078 * ## OPTIONS
1079 *
1080 * --alternate_email=<alternate_email>
1081 * : Set alternate email (email notifications will be sent by default to the "Admin Email" (set in Settings > General), this will override this option)
1082 *
1083 * ## EXAMPLES
1084 *
1085 * wp jetbackup sendTestEmail --alternate_email=youremail@gmail.com
1086 *
1087 * @when after_wp_load
1088 */
1089 public function sendTestEmail($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1090
1091 /**
1092 * Start over queue item
1093 *
1094 * ## OPTIONS
1095 *
1096 * --id=<id>
1097 * : id of the queue item
1098 *
1099 * ## EXAMPLES
1100 *
1101 * wp jetbackup startOverQueueItem --id=5
1102 *
1103 * @when after_wp_load
1104 */
1105
1106 public function startOverQueueItem($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1107
1108 /**
1109 * Validate destination
1110 *
1111 * ## OPTIONS
1112 *
1113 * --id=<id>
1114 * : id of the destination to validate
1115 *
1116 * ## EXAMPLES
1117 *
1118 * wp jetbackup validateDestination --id=5
1119 *
1120 * @when after_wp_load
1121 */
1122 public function validateDestination($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1123
1124 /**
1125 * Execute JetBackup's internal cron scheduler
1126 *
1127 * ## OPTIONS
1128 *
1129 * [--debug]
1130 * : Add more debug verbosity to output
1131 *
1132 * ## EXAMPLES
1133 *
1134 * wp jetbackup executeCron --debug
1135 *
1136 * @when after_wp_load
1137 */
1138 public function executeCron($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1139
1140
1141 /**
1142 * Clears Complete queue items
1143 *
1144 * ## EXAMPLES
1145 *
1146 * wp jetbackup clearCompletedQueueItems
1147 *
1148 * @when after_wp_load
1149 */
1150 public function clearCompletedQueueItems($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1151
1152 /**
1153 * Clear All Alerts
1154 *
1155 * ## EXAMPLES
1156 *
1157 * wp jetbackup clearAlerts
1158 *
1159 * @when after_wp_load
1160 */
1161 public function clearAlerts($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1162
1163 // Some flags such as --path are taken by wpcli, so we need to use alternate names and translate back
1164 private static function translateFlags (array $flags) : array {
1165 if (empty($flags)) return [];
1166 foreach ($flags as $key => $value) {
1167 if (isset(self::FLAGS[$key])) {
1168 $flags[self::FLAGS[$key]] = $value;
1169 unset($flags[$key]);
1170 }
1171 }
1172 return $flags;
1173 }
1174
1175 private static function _command($func, $args, $flags) {
1176
1177 $method = "\JetBackup\Ajax\Calls\\" . ucfirst($func);
1178
1179 $output = isset($flags['output']) && in_array($flags['output'], CLI::OUTPUT_TYPES) ? $flags['output'] : CLI::OUTPUT_TYPE_TABLE;
1180 if(isset($flags['output'])) unset($flags['output']);
1181
1182 if(isset($flags['sort']) && $flags['sort'] == 'desc') $flags['sort'] = ['_id' => 'desc'];
1183 else $flags['sort'] = ['_id' => 'asc'];
1184
1185 $flags = self::translateFlags($flags);
1186
1187 /** @var iAjax $call */
1188 $call = new $method();
1189 $call->setData($flags);
1190 $call->setCLI(true);
1191
1192 try {
1193 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');
1194 $call->execute();
1195 } catch (AjaxException $e) {
1196 $message = $e->getMessage();
1197 if($e->getData()) $message = vsprintf($message, $e->getData());
1198 self::error($message);
1199 }
1200
1201 if($call->getResponseMessage()) self::line($call->getResponseMessage());
1202 if($list = $call->getResponseData()) {
1203 if(!isset($list[0])) $list = [$list];
1204 self::output($list, array_keys($list[0]), $output);
1205 }
1206 }
1207
1208 private static function output($data, $headers, $type) {
1209 error_reporting(E_ALL & ~E_DEPRECATED); // issue 247
1210 WP_CLI\Utils\format_items($type, $data, $headers);
1211 }
1212
1213 private static function line($text) {
1214 WP_CLI::line($text);
1215 }
1216
1217 private static function error($text) {
1218 WP_CLI::error($text);
1219 }
1220
1221 private static function success($text) {
1222 WP_CLI::success($text);
1223 }
1224 }
1225