PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.11.1
JetBackup – Backup, Restore & Migrate v3.1.11.1
3.1.23.6 3.1.23.5 3.1.23.3 3.1.22.4 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 year ago index.html 1 year ago web.config 1 year ago
Command.php
1191 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 * [--enable_rest_api_scheduler=<enable_rest_api_scheduler>]
799 * : Enable (1) or disable (0) the REST API scheduler.
800 *
801 * [--cron_status=<cron_status>]
802 * : Enable (1) or disable (0) the REST API cron status.
803 *
804 * ## EXAMPLES
805 *
806 * wp jetbackup manageSettingsAutomation --heartbeat=1 --heartbeat_ttl=1 --crons=1 --enable_rest_api_scheduler=1 --cron_status=1
807 *
808 * @when after_wp_load
809 */
810
811 public function manageSettingsAutomation($args, $flags) {self::_command(__FUNCTION__, $args, self::_keyToUpper($flags));}
812 /**
813 * Manage general settings for jetbackup plugin
814 *
815 * ## OPTIONS
816 *
817 * [--license_key=<license-key>]
818 * : 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.
819 *
820 * [--timezone=<timezone>]
821 * : Set timezone for jetbackup plugin
822 *
823 * [--community_languages=<bool>]
824 * : Enable/Disable community languages delivered by our languages CDN.
825 *
826 * [--jetbackup_integration=<bool>]
827 * : Enable/Disable API to server level JetBackup (Restore backups generated by your hosting provider's JetBackup).
828 *
829 * [--admin_top_menu_integration=<bool>]
830 * : Enable/Disable Admin top menu bar integration.).
831 *
832 * [--manual_backups_retention=<int>]
833 * : This setting determines how many manual backups to keep per destination. Set to 0 to disable retention and never delete backups.
834 *
835 * [--php_cli_location=<path>]
836 * : JetBackup relies on PHP CLI for background operations, here you can set specific path for php binary.
837 *
838 * [--mysql_default_port=<int>]
839 * : 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.
840 *
841 * ## EXAMPLES
842 *
843 * wp jetbackup manageSettingsGeneral --license_key=xxxx --timezone=UTC --jetbackup_integration=1 --manual_backups_retention=0 --php_cli_location=/usr/bin/php --mysql_default_port=3306
844 *
845 * @when after_wp_load
846 */
847
848 public function manageSettingsGeneral($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
849
850 /**
851 * Manage log settings
852 *
853 * ## OPTIONS
854 *
855 * [--debug=<debug>]
856 * : enable or disable debug logging.
857 *
858 * [--log_rotate=<log_rotate>]
859 * : 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.
860 *
861 * ## EXAMPLES
862 *
863 * wp jetbackup manageSettingsLogging --debug=1 --log_rotate=7
864 *
865 * @when after_wp_load
866 */
867 public function manageSettingsLogging($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
868
869
870 /**
871 * Manage maintenance settings
872 *
873 * ## OPTIONS
874 *
875 * [--maintenance_queue_hours_ttl=<maintenance_queue_hours_ttl>]
876 * : clear completed items from the queue table after a specified number of hours. set to 0 to disable.
877 *
878 * [--maintenance_download_items_ttl=<maintenance_download_items_ttl>]
879 * : After the specified number of hours, expired items will be automatically deleted. Enter a value in hours. set to 0 to disable.
880 *
881 * [--maintenance_download_limit=<maintenance_download_items_ttl>]
882 * : Sets the max active downloads. If the limit is reached, clear one to start a new download. set to 0 to disable.
883 *
884 * [--maintenance_queue_alerts_ttl=<maintenance_queue_alerts_ttl>]
885 * : clear system alerts after a specified number of hours. set to 0 to disable.
886 *
887 * [--config_export_rotate=<config_export_rotate>]
888 * : specify the number of exported config backups to keep. older exports will be deleted. set to 0 to keep indefinitely.
889 *
890 * ## EXAMPLES
891 *
892 * 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
893 *
894 * @when after_wp_load
895 */
896 public function manageSettingsMaintenance($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
897
898
899 /**
900 * Manage notification settings
901 *
902 * ## OPTIONS
903 *
904 * [--emails=<emails>]
905 * : enable or disable email notifications.
906 *
907 * [--alternate_email=<alternate_email>]
908 * : set an alternate email address for notifications instead of the default admin email.
909 *
910 * ## EXAMPLES
911 *
912 * wp jetbackup manageSettingsNotifications --emails=1 --alternate_email=youremail@gmail.com
913 *
914 * @when after_wp_load
915 */
916 public function manageSettingsNotifications($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
917
918
919 /**
920 * Manage performance settings
921 *
922 * ## OPTIONS
923 *
924 * [--read_chunk_size=<read_chunk_size>]
925 * : set the chunk size for file uploads. affects upload speed and stability.
926 *
927 * [--execution_time=<execution_time>]
928 * : define the maximum execution time (in seconds) for queued tasks. applies only to web-based tasks.
929 *
930 * [--sql_cleanup_revisions=<sql_cleanup_revisions>]
931 * : enable or disable cleaning up old revisions before dumping databases.
932 *
933 * [--use_default_excludes=<use_default_excludes>]
934 * : enable or disable the default file exclude list for backups.
935 *
936 * [--exclude_nested_sites=<exclude_nested_sites>]
937 * : exclude WordPress installations within the first subdirectory level.
938 *
939 * [--use_default_db_excludes=<use_default_db_excludes>]
940 * : exclude known temporary database tables.
941 *
942 * [--gzip_compress_archive=<gzip_compress_archive>]
943 * : enable or disable gzip compression for backup archives.
944 *
945 * [--gzip_compress_db=<gzip_compress_db>]
946 * : enable or disable gzip compression for database backups.
947 *
948 * ## EXAMPLES
949 *
950 * wp jetbackup manageSettingsPerformance --read_chunk_size=2097152 --execution_time=10 --sql_cleanup_revisions=1 --use_default_excludes=1 --gzip_compress_archive=1
951 *
952 * @when after_wp_load
953 */
954 public function manageSettingsPerformance($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
955
956
957 /**
958 * Manage restore settings
959 *
960 * ## OPTIONS
961 *
962 * [--restore_compatibility_check=<restore_compatibility_check>]
963 * : enable or disable checking system compatibility before restoring a backup.
964 *
965 * [--restore_allow_cross_domain=<bool>]
966 * : allow (1) or disallow (0) restoring backups across different domains.
967 *
968 * [--restore_alternate_path=<bool>]
969 * : enable (1) or disable (0) using alternate public restore path
970 *
971 * [--restore_wp_content_only=<bool>]
972 * : enable (1) or disable (0) limit restore to wp-content folder only
973 *
974 * ## EXAMPLES
975 *
976 * wp jetbackup manageSettingsRestore --restore_compatibility_check=1 --restore_allow_cross_domain=1 --restore_alternate_path=1 --restore_wp_content_only=1
977 *
978 * @when after_wp_load
979 */
980 public function manageSettingsRestore($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
981
982 /**
983 * Manage Integration settings
984 *
985 * ## OPTIONS
986 *
987 * [--integrations=<array>]
988 * : Enable integrations
989 *
990 * ## EXAMPLES
991 *
992 * wp jetbackup manageSettingsIntegrations --integrations='["Elementor","Supercache", "Woocommerce"]'
993 *
994 * @when after_wp_load
995 */
996 public function manageSettingsIntegrations($args, $flags) {
997 if (isset($flags[Integrations::INTEGRATIONS])) $flags[Integrations::INTEGRATIONS] = self::_argsToArray($flags[Integrations::INTEGRATIONS]);
998 self::_command(__FUNCTION__, $args, $flags);
999 }
1000
1001
1002 /**
1003 * Manage security settings
1004 *
1005 * ## OPTIONS
1006 *
1007 * [--mfa_enabled=<bool>]
1008 * : enable (1) or disable (0) two-factor authentication for additional security.
1009 *
1010 * [--alternate_data_folder=<alternate_data_folder>]
1011 * : specify a custom data directory for storing configuration and backup data.
1012 *
1013 * [--daily_checksum_check=<daily_checksum_check>]
1014 * : enable or disable daily checksum verification of WordPress core files.
1015 *
1016 * ## EXAMPLES
1017 *
1018 * wp jetbackup manageSettingsSecurity --mfa_enabled=1 --daily_checksum_check=1 --alternate_data_folder=/custom/path
1019 *
1020 * @when after_wp_load
1021 */
1022 public function manageSettingsSecurity($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
1023
1024
1025 /**
1026 * Manage update settings
1027 *
1028 * ## OPTIONS
1029 *
1030 * [--update_tier=<update_tier>]
1031 * : set the update tier (release, rc, edge, or alpha) to determine how frequently updates are received.
1032 *
1033 * ## EXAMPLES
1034 *
1035 * wp jetbackup manageSettingsUpdates --update_tier=release
1036 *
1037 * @when after_wp_load
1038 */
1039 public function manageSettingsUpdates($args, $flags) { self::_command(__FUNCTION__, $args, self::_keyToUpper($flags)); }
1040
1041 /**
1042 * Manage sendTestEmail settings
1043 *
1044 * ## OPTIONS
1045 *
1046 * --alternate_email=<alternate_email>
1047 * : Set alternate email (email notifications will be sent by default to the "Admin Email" (set in Settings > General), this will override this option)
1048 *
1049 * ## EXAMPLES
1050 *
1051 * wp jetbackup sendTestEmail --alternate_email=youremail@gmail.com
1052 *
1053 * @when after_wp_load
1054 */
1055 public function sendTestEmail($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1056
1057 /**
1058 * Start over queue item
1059 *
1060 * ## OPTIONS
1061 *
1062 * --id=<id>
1063 * : id of the queue item
1064 *
1065 * ## EXAMPLES
1066 *
1067 * wp jetbackup startOverQueueItem --id=5
1068 *
1069 * @when after_wp_load
1070 */
1071
1072 public function startOverQueueItem($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1073
1074 /**
1075 * Validate destination
1076 *
1077 * ## OPTIONS
1078 *
1079 * --id=<id>
1080 * : id of the destination to validate
1081 *
1082 * ## EXAMPLES
1083 *
1084 * wp jetbackup validateDestination --id=5
1085 *
1086 * @when after_wp_load
1087 */
1088 public function validateDestination($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1089
1090 /**
1091 * Execute JetBackup's internal cron scheduler
1092 *
1093 * ## OPTIONS
1094 *
1095 * [--debug]
1096 * : Add more debug verbosity to output
1097 *
1098 * ## EXAMPLES
1099 *
1100 * wp jetbackup executeCron --debug
1101 *
1102 * @when after_wp_load
1103 */
1104 public function executeCron($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1105
1106
1107 /**
1108 * Clears Complete queue items
1109 *
1110 * ## EXAMPLES
1111 *
1112 * wp jetbackup clearCompletedQueueItems
1113 *
1114 * @when after_wp_load
1115 */
1116 public function clearCompletedQueueItems($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1117
1118 /**
1119 * Clear All Alerts
1120 *
1121 * ## EXAMPLES
1122 *
1123 * wp jetbackup clearAlerts
1124 *
1125 * @when after_wp_load
1126 */
1127 public function clearAlerts($args, $flags) { self::_command(__FUNCTION__, $args, $flags); }
1128
1129 // Some flags such as --path are taken by wpcli, so we need to use alternate names and translate back
1130 private static function translateFlags (array $flags) : array {
1131 if (empty($flags)) return [];
1132 foreach ($flags as $key => $value) {
1133 if (isset(self::FLAGS[$key])) {
1134 $flags[self::FLAGS[$key]] = $value;
1135 unset($flags[$key]);
1136 }
1137 }
1138 return $flags;
1139 }
1140
1141 private static function _command($func, $args, $flags) {
1142
1143 $method = "\JetBackup\Ajax\Calls\\" . ucfirst($func);
1144
1145 $output = isset($flags['output']) && in_array($flags['output'], CLI::OUTPUT_TYPES) ? $flags['output'] : CLI::OUTPUT_TYPE_TABLE;
1146 if(isset($flags['output'])) unset($flags['output']);
1147
1148 if(isset($flags['sort']) && $flags['sort'] == 'desc') $flags['sort'] = ['_id' => 'desc'];
1149 else $flags['sort'] = ['_id' => 'asc'];
1150
1151 $flags = self::translateFlags($flags);
1152
1153 /** @var iAjax $call */
1154 $call = new $method();
1155 $call->setData($flags);
1156 $call->setCLI(true);
1157
1158 try {
1159 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');
1160 $call->execute();
1161 } catch (AjaxException $e) {
1162 $message = $e->getMessage();
1163 if($e->getData()) $message = vsprintf($message, $e->getData());
1164 self::error($message);
1165 }
1166
1167 if($call->getResponseMessage()) self::line($call->getResponseMessage());
1168 if($list = $call->getResponseData()) {
1169 if(!isset($list[0])) $list = [$list];
1170 self::output($list, array_keys($list[0]), $output);
1171 }
1172 }
1173
1174 private static function output($data, $headers, $type) {
1175 error_reporting(E_ALL & ~E_DEPRECATED); // issue 247
1176 WP_CLI\Utils\format_items($type, $data, $headers);
1177 }
1178
1179 private static function line($text) {
1180 WP_CLI::line($text);
1181 }
1182
1183 private static function error($text) {
1184 WP_CLI::error($text);
1185 }
1186
1187 private static function success($text) {
1188 WP_CLI::success($text);
1189 }
1190 }
1191