Version Description
- New Feature: Add support request to plugin
- New Feature: Add large backup support
- New Feature: Add drag and drop uploads
- New Feature: Split backup into separate archives(database,plugins,themes,uploads)
- New Feature: Add download popup to allow user to selectively download backup archives
- Updates: Security Enhancements
- Updates: Miscellaneous User Experience Improvements
- Updates: Significant Performance Improvements
Download this release
Release Info
Developer | cssimmon |
Plugin | Backup and Restore WordPress – WPBackItUp Backup Plugin |
Version | 1.10.0 |
Comparing to | |
See all releases |
Code changes from version 1.9.2 to 1.10.0
- js/wpbackitup_admin.js +420 -118
- lib/includes/class-backup.php +319 -317
- lib/includes/class-filesystem.php +87 -3
- lib/includes/class-job.php +147 -51
- lib/includes/class-logger.php +11 -0
- lib/includes/class-restore.php +1050 -6
- lib/includes/class-sql.php +25 -7
- lib/includes/class-utility.php +10 -5
- lib/includes/class-wpbackitup-admin.php +387 -82
- lib/includes/class-zip.php +1 -1
- lib/includes/download_backup.php +0 -48
- lib/includes/handler_download.php +100 -0
- lib/includes/handler_upload.php +176 -0
- lib/includes/{viewlog.php → handler_viewlog.php} +12 -8
- lib/includes/job_backup.php +270 -172
- lib/includes/job_cleanup.php +33 -13
- lib/includes/job_restore.php +640 -767
- lib/includes/listlogs.php +0 -71
- lib/includes/upload.php +0 -113
- readme.txt +12 -2
- views/backup.php +157 -100
- views/restore.php +114 -55
- views/support.php +85 -0
- wp-backitup.php +11 -4
js/wpbackitup_admin.js
CHANGED
@@ -23,6 +23,13 @@
|
|
23 |
action: wpbackitup_get_action_name('backup_status_reader')
|
24 |
};
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
$( "#scheduled-backups-accordian" ).click(function() {
|
27 |
|
28 |
scheduled_backups=$("#scheduled-backups");
|
@@ -40,6 +47,23 @@
|
|
40 |
|
41 |
});
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
//binds to onchange event of the upload file input field
|
44 |
$('#wpbackitup-zip').bind('change', function() {
|
45 |
|
@@ -67,7 +91,7 @@
|
|
67 |
function wpbackitup_add_viewlog_onclick(){
|
68 |
$(".viewloglink").click(function(){
|
69 |
var href = $(this).attr("href");
|
70 |
-
$("#
|
71 |
$("#viewlog").submit();
|
72 |
return false;
|
73 |
});
|
@@ -76,7 +100,7 @@
|
|
76 |
function wpbackitup_add_downloadbackup_onclick(){
|
77 |
$(".downloadbackuplink").click(function(){
|
78 |
var href = $(this).attr("href");
|
79 |
-
$("#
|
80 |
$("#download_backup").submit();
|
81 |
return false;
|
82 |
});
|
@@ -508,101 +532,215 @@
|
|
508 |
}
|
509 |
|
510 |
/*Upload form button*/
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
606 |
|
607 |
// DELETE file action
|
608 |
$('#datatable').on('click', 'a.deleteRow', function(e) {
|
@@ -634,6 +772,123 @@
|
|
634 |
}
|
635 |
});
|
636 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
|
638 |
function wpbackitup_processRow_backup(data)
|
639 |
{
|
@@ -656,15 +911,15 @@
|
|
656 |
|
657 |
var viewColumn = '<td> </td>\n';
|
658 |
if (typeof data.logFileExists !== 'undefined' && data.logFileExists==true) {
|
659 |
-
viewColumn = '<td><a class="viewloglink" href="' + data.
|
660 |
}
|
661 |
|
662 |
var newRow =
|
663 |
'<tr ' + css_class + ' id="row' + cur_row + '">\n\
|
664 |
<td>New Backup!</td>\n\
|
665 |
-
<td><a class="
|
666 |
newRow +=viewColumn;
|
667 |
-
newRow +='<td><a href="#" title="' + data.
|
668 |
newRow +='</tr>';
|
669 |
|
670 |
if ($('#nofiles'))
|
@@ -722,24 +977,6 @@
|
|
722 |
}
|
723 |
}
|
724 |
|
725 |
-
function wpbackitup_upload_errors()
|
726 |
-
{
|
727 |
-
if ($('#wpbackitup-zip').val() == '')
|
728 |
-
{
|
729 |
-
alert('No file(s) selected. Please choose a backup file to upload.');
|
730 |
-
return true;
|
731 |
-
}
|
732 |
-
if ($('#wpbackitup-zip').val() != '')
|
733 |
-
{
|
734 |
-
var ext = $('#wpbackitup-zip').val().split('.').pop().toLowerCase();
|
735 |
-
if($.inArray(ext, ['zip']) == -1)
|
736 |
-
{
|
737 |
-
alert('Invalid file type. Please choose a ZIP file to upload.');
|
738 |
-
return true;
|
739 |
-
}
|
740 |
-
}
|
741 |
-
return false;
|
742 |
-
}
|
743 |
|
744 |
function wpbackitup_get_action_name(action) {
|
745 |
return namespace + '_' + action;
|
@@ -775,6 +1012,71 @@
|
|
775 |
}
|
776 |
|
777 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
778 |
//**TEST METHODS**//
|
779 |
|
780 |
//wpbackitup_show_restore();
|
23 |
action: wpbackitup_get_action_name('backup_status_reader')
|
24 |
};
|
25 |
|
26 |
+
//UPLOADS
|
27 |
+
try {
|
28 |
+
plupload_init(wpbackitup_plupload_config);
|
29 |
+
} catch (err) {
|
30 |
+
console.log(err);
|
31 |
+
}
|
32 |
+
|
33 |
$( "#scheduled-backups-accordian" ).click(function() {
|
34 |
|
35 |
scheduled_backups=$("#scheduled-backups");
|
47 |
|
48 |
});
|
49 |
|
50 |
+
$( "#upload-backups-accordian" ).click(function() {
|
51 |
+
|
52 |
+
upload_backups=$("#wpbackitup-plupload-modal");
|
53 |
+
upload_backups_button = $( "#upload-backups-accordian");
|
54 |
+
|
55 |
+
if ($(this).is(".fa-angle-double-down")){
|
56 |
+
upload_backups.fadeIn( "slow" )
|
57 |
+
upload_backups_button.toggleClass( "fa-angle-double-down", false);
|
58 |
+
upload_backups_button.toggleClass( "fa-angle-double-up", true);
|
59 |
+
} else{
|
60 |
+
upload_backups_button.toggleClass( "fa-angle-double-down", true);
|
61 |
+
upload_backups_button.toggleClass( "fa-angle-double-up", false);
|
62 |
+
upload_backups.fadeOut( "slow" )
|
63 |
+
}
|
64 |
+
|
65 |
+
});
|
66 |
+
|
67 |
//binds to onchange event of the upload file input field
|
68 |
$('#wpbackitup-zip').bind('change', function() {
|
69 |
|
91 |
function wpbackitup_add_viewlog_onclick(){
|
92 |
$(".viewloglink").click(function(){
|
93 |
var href = $(this).attr("href");
|
94 |
+
$("#backup_name").val(href);
|
95 |
$("#viewlog").submit();
|
96 |
return false;
|
97 |
});
|
100 |
function wpbackitup_add_downloadbackup_onclick(){
|
101 |
$(".downloadbackuplink").click(function(){
|
102 |
var href = $(this).attr("href");
|
103 |
+
$("#backup_file").val(href);
|
104 |
$("#download_backup").submit();
|
105 |
return false;
|
106 |
});
|
532 |
}
|
533 |
|
534 |
/*Upload form button*/
|
535 |
+
//$("#upload-form").submit(function(e) {
|
536 |
+
//
|
537 |
+
// e.preventDefault();
|
538 |
+
//
|
539 |
+
// //CHECK ERRORS ON USER SIDE, IF TRUE, END OPERATIONS.
|
540 |
+
// if (wpbackitup_upload_errors()){
|
541 |
+
// return false;
|
542 |
+
// }
|
543 |
+
//
|
544 |
+
// var formData = new FormData();
|
545 |
+
// formData.append('action', wpbackitup_get_action_name('upload'));
|
546 |
+
// formData.append('_wpnonce', $('#_wpnonce').val());
|
547 |
+
// formData.append('_wp_http_referer',$("[name='_wp_http_referer']").val());
|
548 |
+
// formData.append('upload_ids',$('#upload_ids').val());
|
549 |
+
//
|
550 |
+
// jQuery.ajax({
|
551 |
+
// url: ajaxurl,
|
552 |
+
// type: 'POST',
|
553 |
+
// cache: false,
|
554 |
+
// contentType: false,
|
555 |
+
// processData: false,
|
556 |
+
// dataType: "json",
|
557 |
+
//
|
558 |
+
// //MODIFIED - From ajaxData to formData
|
559 |
+
// data: formData,
|
560 |
+
//
|
561 |
+
// beforeSend: function(jqXHR, settings){
|
562 |
+
// //console.log("Haven't entered server side yet.");
|
563 |
+
// /* display processing icon */
|
564 |
+
// $('.upload-icon').css('visibility', 'visible');
|
565 |
+
//
|
566 |
+
// /* hide default message, backup status and backup errors */
|
567 |
+
// $('.default-status, .restore-status, .restore-errors').hide();
|
568 |
+
// $("ul.restore-status").children().children().hide();
|
569 |
+
// $(".restore-errors").children().children().hide();
|
570 |
+
// $(".restore-success").children().children().hide();
|
571 |
+
//
|
572 |
+
// /* show restore status messages */
|
573 |
+
// $('.upload-status').toggle();
|
574 |
+
//
|
575 |
+
// $("#wpbackitup-zip").attr("disabled", "disabled"); //Disable upload
|
576 |
+
// $("#upload-button").attr("disabled", "disabled"); //Disable upload
|
577 |
+
//
|
578 |
+
// },
|
579 |
+
// dataFilter: function(data, type){
|
580 |
+
// //Check the response before sending to success
|
581 |
+
// //Possible that is isnt json so just forward it to success in a json object
|
582 |
+
// try {
|
583 |
+
// $("#php").html(data);
|
584 |
+
// var response = $.parseJSON(data);
|
585 |
+
// console.log("JSON string echoed back from server side:" + response);
|
586 |
+
// return data;
|
587 |
+
// } catch (e) {
|
588 |
+
// console.log("NON JSON string echoed back from server side:" + type + ':' + data);
|
589 |
+
// var rtnData = new Object();
|
590 |
+
// rtnData.success = "";
|
591 |
+
// rtnData.error = data;
|
592 |
+
// return JSON.stringify(rtnData)
|
593 |
+
// }
|
594 |
+
//
|
595 |
+
//
|
596 |
+
// },
|
597 |
+
// success: function(data, textStatus, jqXHR){
|
598 |
+
// console.log("Back from server-side:" + data);
|
599 |
+
// //Checking errors that may have been caught on the server side that
|
600 |
+
// // normally wouldn't display in the error Ajax function.
|
601 |
+
//
|
602 |
+
// if (data.msg == 'success')
|
603 |
+
// {
|
604 |
+
// status_message=data.file + ' file was uploaded successfully...';
|
605 |
+
// wpbackitup_processRow_restore(data);
|
606 |
+
// $('.upload-status').addClass("isa_success");
|
607 |
+
// }else{
|
608 |
+
// status_message='Error: ' + data.error;
|
609 |
+
// $('.upload-status').addClass("isa_error");
|
610 |
+
// }
|
611 |
+
//
|
612 |
+
// $('.upload-icon').fadeOut(1000);
|
613 |
+
// $('.upload-status').show();
|
614 |
+
// $('.upload-status').html(status_message);
|
615 |
+
//
|
616 |
+
// },
|
617 |
+
// error: function(jqXHR, textStatus, errorThrown){
|
618 |
+
// console.log("A JS error has occurred." + textStatus +':' +errorThrown);
|
619 |
+
// },
|
620 |
+
// complete: function(jqXHR, textStatus){
|
621 |
+
// console.log("Ajax is finished.");
|
622 |
+
// }
|
623 |
+
// });
|
624 |
+
//
|
625 |
+
// return false;
|
626 |
+
//});
|
627 |
+
//
|
628 |
+
//function wpbackitup_upload_errors()
|
629 |
+
//{
|
630 |
+
// var selected_files = $('#upload_ids').val();
|
631 |
+
// if (selected_files == '')
|
632 |
+
// {
|
633 |
+
// alert('No file(s) selected. Please choose a backup file.');
|
634 |
+
// return true;
|
635 |
+
// }
|
636 |
+
//
|
637 |
+
// //if ($('#upload_files').val() != '')
|
638 |
+
// //{
|
639 |
+
// // var ext = $('#upload_files').val().split('.').pop().toLowerCase();
|
640 |
+
// // if($.inArray(ext, ['zip']) == -1)
|
641 |
+
// // {
|
642 |
+
// // alert('Invalid file type. Please choose a ZIP file to upload.');
|
643 |
+
// // return true;
|
644 |
+
// // }
|
645 |
+
// //}
|
646 |
+
// return false;
|
647 |
+
//}
|
648 |
+
//
|
649 |
+
///*Upload form button*/
|
650 |
+
//$("#upload-form_OLD").submit(function() {
|
651 |
+
//
|
652 |
+
// //e.preventDefault();
|
653 |
+
//
|
654 |
+
// //CHECK ERRORS ON USER SIDE, IF TRUE, END OPERATIONS.
|
655 |
+
// if (wpbackitup_upload_errors()){
|
656 |
+
// return false;
|
657 |
+
// }
|
658 |
+
//
|
659 |
+
// var formData = new FormData();
|
660 |
+
// jQuery.each($('#wpbackitup-zip')[0].files, function(i, file) {
|
661 |
+
// formData.append('uploadFile-'+i, file);
|
662 |
+
// });
|
663 |
+
// formData.append('action', wpbackitup_get_action_name('upload'));
|
664 |
+
// formData.append('_wpnonce', $('#_wpnonce').val());
|
665 |
+
// formData.append('_wp_http_referer',$("[name='_wp_http_referer']").val());
|
666 |
+
//
|
667 |
+
// jQuery.ajax({
|
668 |
+
// url: ajaxurl,
|
669 |
+
// type: 'POST',
|
670 |
+
// cache: false,
|
671 |
+
// contentType: false,
|
672 |
+
// processData: false,
|
673 |
+
// dataType: "json",
|
674 |
+
//
|
675 |
+
// //MODIFIED - From ajaxData to formData
|
676 |
+
// data: formData,
|
677 |
+
//
|
678 |
+
// beforeSend: function(jqXHR, settings){
|
679 |
+
// //console.log("Haven't entered server side yet.");
|
680 |
+
// /* display processing icon */
|
681 |
+
// $('.upload-icon').css('visibility', 'visible');
|
682 |
+
//
|
683 |
+
// /* hide default message, backup status and backup errors */
|
684 |
+
// $('.default-status, .restore-status, .restore-errors').hide();
|
685 |
+
// $("ul.restore-status").children().children().hide();
|
686 |
+
// $(".restore-errors").children().children().hide();
|
687 |
+
// $(".restore-success").children().children().hide();
|
688 |
+
//
|
689 |
+
// /* show restore status messages */
|
690 |
+
// $('.upload-status').toggle();
|
691 |
+
//
|
692 |
+
// $("#wpbackitup-zip").attr("disabled", "disabled"); //Disable upload
|
693 |
+
// $("#upload-button").attr("disabled", "disabled"); //Disable upload
|
694 |
+
//
|
695 |
+
// },
|
696 |
+
// dataFilter: function(data, type){
|
697 |
+
// //Check the response before sending to success
|
698 |
+
// //Possible that is isnt json so just forward it to success in a json object
|
699 |
+
// try {
|
700 |
+
// $("#php").html(data);
|
701 |
+
// var response = $.parseJSON(data);
|
702 |
+
// console.log("JSON string echoed back from server side:" + response);
|
703 |
+
// return data;
|
704 |
+
// } catch (e) {
|
705 |
+
// console.log("NON JSON string echoed back from server side:" + type + ':' + data);
|
706 |
+
// var rtnData = new Object();
|
707 |
+
// rtnData.success = "";
|
708 |
+
// rtnData.error = data;
|
709 |
+
// return JSON.stringify(rtnData)
|
710 |
+
// }
|
711 |
+
//
|
712 |
+
//
|
713 |
+
// },
|
714 |
+
// success: function(data, textStatus, jqXHR){
|
715 |
+
// console.log("Back from server-side:" + data);
|
716 |
+
// //Checking errors that may have been caught on the server side that
|
717 |
+
// // normally wouldn't display in the error Ajax function.
|
718 |
+
//
|
719 |
+
// if (data.msg == 'success')
|
720 |
+
// {
|
721 |
+
// status_message=data.file + ' file was uploaded successfully...';
|
722 |
+
// wpbackitup_processRow_restore(data);
|
723 |
+
// $('.upload-status').addClass("isa_success");
|
724 |
+
// }else{
|
725 |
+
// status_message='Error: ' + data.error;
|
726 |
+
// $('.upload-status').addClass("isa_error");
|
727 |
+
// }
|
728 |
+
//
|
729 |
+
// $('.upload-icon').fadeOut(1000);
|
730 |
+
// $('.upload-status').show();
|
731 |
+
// $('.upload-status').html(status_message);
|
732 |
+
//
|
733 |
+
// },
|
734 |
+
// error: function(jqXHR, textStatus, errorThrown){
|
735 |
+
// console.log("A JS error has occurred." + textStatus +':' +errorThrown);
|
736 |
+
// },
|
737 |
+
// complete: function(jqXHR, textStatus){
|
738 |
+
// console.log("Ajax is finished.");
|
739 |
+
// }
|
740 |
+
// });
|
741 |
+
//
|
742 |
+
// return false;
|
743 |
+
//});
|
744 |
|
745 |
// DELETE file action
|
746 |
$('#datatable').on('click', 'a.deleteRow', function(e) {
|
772 |
}
|
773 |
});
|
774 |
|
775 |
+
//UPLOADS
|
776 |
+
//http://www.plupload.com/example_events.php
|
777 |
+
function plupload_init(plupload_config) {
|
778 |
+
|
779 |
+
var uploader = new plupload.Uploader(plupload_config);
|
780 |
+
uploader.init();
|
781 |
+
|
782 |
+
//File Added event
|
783 |
+
uploader.bind('FilesAdded', function(up, files){
|
784 |
+
plupload.each(files, function(file){
|
785 |
+
//add some file name validation here?
|
786 |
+
$('#filelist').append(
|
787 |
+
'<div id="media-item-' + file.id + '" class="media-item child-of-0">' +
|
788 |
+
'<img class="pinkynail" alt="" src="' + site_url + '/wp-includes/images/media/archive.png">' +
|
789 |
+
'<div class="filename new" id="' + file.id + '">' +
|
790 |
+
file.name + ' (<span>' + plupload.formatSize(0) + '</span> of ' + plupload.formatSize(file.size) + ') ' +
|
791 |
+
'<div class="progress" style="width: 0%;"></div></div></div>');
|
792 |
+
});
|
793 |
+
|
794 |
+
up.refresh();
|
795 |
+
up.start();
|
796 |
+
});
|
797 |
+
|
798 |
+
//File Progress Event
|
799 |
+
uploader.bind('UploadProgress', function(up, file) {
|
800 |
+
$('#' + file.id + " .progress").width((file.percent *.15 )+ "%");
|
801 |
+
$('#' + file.id + " span").html(plupload.formatSize(parseInt(file.size * file.percent / 100)));
|
802 |
+
});
|
803 |
+
|
804 |
+
//Chunked upload
|
805 |
+
uploader.bind(' ChunkUploaded', function(up, file,info) {
|
806 |
+
console.log('Chunk Uploaded:');
|
807 |
+
console.log(info);
|
808 |
+
|
809 |
+
if (is_plupload_error(info,up,file)){
|
810 |
+
console.log('chunk error');
|
811 |
+
}
|
812 |
+
|
813 |
+
});
|
814 |
+
|
815 |
+
//Error Event
|
816 |
+
uploader.bind('Error', function(up, error) {
|
817 |
+
console.log('PlUpload Error:');
|
818 |
+
console.log(error);
|
819 |
+
|
820 |
+
var error_div = "error-item-"+ error.file.id;
|
821 |
+
|
822 |
+
//If error div NOT exists then add it
|
823 |
+
//Chunk and file uploaded both will call this routine
|
824 |
+
if (! $('#'+ error_div).length){
|
825 |
+
$('#filelist').append(
|
826 |
+
'<div class="error-div error" id="' + error_div + '" >' +
|
827 |
+
'<strong>' + error.file.name + ' has failed to upload due to error: </strong> <span>' + error.message + '</span> ' +
|
828 |
+
'</div>'
|
829 |
+
);
|
830 |
+
}
|
831 |
+
|
832 |
+
|
833 |
+
});
|
834 |
+
|
835 |
+
|
836 |
+
// a file was uploaded
|
837 |
+
uploader.bind('FileUploaded', function(up, file, response) {
|
838 |
+
console.log('File Uploaded');
|
839 |
+
console.log(response);
|
840 |
+
|
841 |
+
|
842 |
+
if (is_plupload_error(response,up,file)){
|
843 |
+
console.log('uploaded error')
|
844 |
+
}else{
|
845 |
+
console.log('uploaded success')
|
846 |
+
$('#' + file.id + " .progress").css("background-color", "green");
|
847 |
+
}
|
848 |
+
|
849 |
+
});
|
850 |
+
}
|
851 |
+
|
852 |
+
function is_plupload_error(response,uploader,file){
|
853 |
+
if (response.status == '200') {
|
854 |
+
try {
|
855 |
+
response_json = jQuery.parseJSON(response.response);
|
856 |
+
|
857 |
+
if (response_json.error) {
|
858 |
+
plupload_error (uploader,file, 100, response_json.error)
|
859 |
+
return true;
|
860 |
+
}
|
861 |
+
|
862 |
+
//success
|
863 |
+
return false;
|
864 |
+
|
865 |
+
|
866 |
+
} catch (err) {
|
867 |
+
console.log('Unexpected JSON Error' + err);
|
868 |
+
plupload_error (uploader,file, 998, response.response)
|
869 |
+
return true;
|
870 |
+
}
|
871 |
+
|
872 |
+
} else {
|
873 |
+
alert('Unknown server response status: '+response.code);
|
874 |
+
console.log(response);
|
875 |
+
plupload_error (uploader,file, 999, response.response)
|
876 |
+
return true;
|
877 |
+
}
|
878 |
+
|
879 |
+
}
|
880 |
+
function plupload_error (uploader,file, code, error_message){
|
881 |
+
|
882 |
+
file.status = plupload.FAILED;
|
883 |
+
uploader.trigger("Error", {
|
884 |
+
code: code,
|
885 |
+
message: error_message,
|
886 |
+
file: file
|
887 |
+
});
|
888 |
+
|
889 |
+
//remove upload from list
|
890 |
+
$('#media-item-' + file.id).hide();
|
891 |
+
}
|
892 |
|
893 |
function wpbackitup_processRow_backup(data)
|
894 |
{
|
911 |
|
912 |
var viewColumn = '<td> </td>\n';
|
913 |
if (typeof data.logFileExists !== 'undefined' && data.logFileExists==true) {
|
914 |
+
viewColumn = '<td><a class="viewloglink" href="' + data.backupName + '">View Log</a></td>\n';
|
915 |
}
|
916 |
|
917 |
var newRow =
|
918 |
'<tr ' + css_class + ' id="row' + cur_row + '">\n\
|
919 |
<td>New Backup!</td>\n\
|
920 |
+
<td><a href="#TB_inline?width=600&height=550&inlineId=new_backup" class="thickbox" title="' + data.backupName + '">Download</a></td>\n';
|
921 |
newRow +=viewColumn;
|
922 |
+
newRow +='<td><a href="#" title="' + data.backupName + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n';
|
923 |
newRow +='</tr>';
|
924 |
|
925 |
if ($('#nofiles'))
|
977 |
}
|
978 |
}
|
979 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
980 |
|
981 |
function wpbackitup_get_action_name(action) {
|
982 |
return namespace + '_' + action;
|
1012 |
}
|
1013 |
|
1014 |
|
1015 |
+
|
1016 |
+
|
1017 |
+
// Uploading files
|
1018 |
+
//jQuery(document).ready(function($){
|
1019 |
+
// var custom_uploader;
|
1020 |
+
// $('#upload_backup_button').click(function(e) {
|
1021 |
+
//
|
1022 |
+
// e.preventDefault();
|
1023 |
+
//
|
1024 |
+
// //If the uploader object has already been created, reopen the dialog
|
1025 |
+
// if (custom_uploader) {
|
1026 |
+
// custom_uploader.open();
|
1027 |
+
// return;
|
1028 |
+
// }
|
1029 |
+
//
|
1030 |
+
// //Extend the wp.media object (wp-includes/js/media-views.js)
|
1031 |
+
// custom_uploader = wp.media.frames.file_frame = wp.media({
|
1032 |
+
// //id:'wpbackitup-library',
|
1033 |
+
// library: {
|
1034 |
+
// type: "application/zip"
|
1035 |
+
// },
|
1036 |
+
// title: 'Select Backup Files',
|
1037 |
+
// button: {
|
1038 |
+
// text: 'Select Backup Files'
|
1039 |
+
// },
|
1040 |
+
// //searchable:false,
|
1041 |
+
// //editing:false,
|
1042 |
+
// //frame: 'post',
|
1043 |
+
// multiple: true
|
1044 |
+
// });
|
1045 |
+
//
|
1046 |
+
// //When a file is selected, grab the URL and set it as the text field's value
|
1047 |
+
// custom_uploader.on('select', function() {
|
1048 |
+
//
|
1049 |
+
// //attachment = custom_uploader.state().get('selection').first().toJSON();
|
1050 |
+
// //$('#upload_backup').val(attachment.filename);
|
1051 |
+
//
|
1052 |
+
// var attachments_string='';
|
1053 |
+
// var selected_file_ids=[];
|
1054 |
+
// var selection = custom_uploader.state().get('selection');
|
1055 |
+
// selection.map( function( attachment ) {
|
1056 |
+
// attachment = attachment.toJSON();
|
1057 |
+
//
|
1058 |
+
// //Probably need to add this to a hidden form field
|
1059 |
+
// selected_file_ids.push(attachment.id);
|
1060 |
+
// attachments_string+=attachment.filename +",";
|
1061 |
+
// // Do something with attachment.id and/or attachment.url here
|
1062 |
+
// });
|
1063 |
+
//
|
1064 |
+
// var ids_json = JSON.stringify(selected_file_ids);
|
1065 |
+
// $('#upload_ids').val(ids_json);
|
1066 |
+
// $('#upload_files').val(attachments_string);
|
1067 |
+
// $('#upload_backup').val(attachments_string);
|
1068 |
+
//
|
1069 |
+
// });
|
1070 |
+
//
|
1071 |
+
//
|
1072 |
+
// //Open the uploader dialog
|
1073 |
+
// custom_uploader.open();
|
1074 |
+
//
|
1075 |
+
// });
|
1076 |
+
//
|
1077 |
+
//
|
1078 |
+
//});
|
1079 |
+
|
1080 |
//**TEST METHODS**//
|
1081 |
|
1082 |
//wpbackitup_show_restore();
|
lib/includes/class-backup.php
CHANGED
@@ -57,7 +57,7 @@ class WPBackItUp_Backup {
|
|
57 |
$this->backup_name=$backup_name;
|
58 |
$this->backup_filename=$backup_name . '.tmp';
|
59 |
|
60 |
-
$backup_project_path = WPBACKITUP__BACKUP_PATH .'/'. $backup_name .'/';
|
61 |
|
62 |
$backup_folder_root =WPBACKITUP__BACKUP_PATH .'/';
|
63 |
$restore_folder_root = WPBACKITUP__RESTORE_FOLDER;
|
@@ -147,7 +147,36 @@ class WPBackItUp_Backup {
|
|
147 |
return true;
|
148 |
}
|
149 |
|
150 |
-
public function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
$dir=$this->backup_folder_root;
|
152 |
$this->logger->log_info(__METHOD__,'Begin:'.$dir);
|
153 |
$ignore = array('cgi-bin','.','..','._');
|
@@ -176,15 +205,34 @@ class WPBackItUp_Backup {
|
|
176 |
$this->logger->log_info(__METHOD__, 'Begin - Cleanup Backup Folder:' . $path);
|
177 |
|
178 |
$fileSystem = new WPBackItUp_FileSystem($this->logger);
|
179 |
-
|
180 |
-
|
|
|
|
|
181 |
return false;
|
182 |
}
|
183 |
|
184 |
-
$this->logger->log_info(__METHOD__,'End -
|
185 |
return true;
|
186 |
}
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
public function purge_old_files(){
|
189 |
$this->logger->log_info(__METHOD__,'Begin');
|
190 |
$fileSystem = new WPBackItUp_FileSystem( $this->logger);
|
@@ -204,22 +252,28 @@ class WPBackItUp_Backup {
|
|
204 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'/logs/';
|
205 |
|
206 |
//Purge logs in logs older than 5 days
|
207 |
-
$fileSystem->purge_files($logs_path,'
|
208 |
-
|
209 |
-
|
210 |
-
$fileSystem->purge_files($logs_path,'
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
//Purge
|
216 |
-
$fileSystem->purge_files($logs_path,'*
|
217 |
-
|
218 |
-
//Purge
|
219 |
-
$fileSystem->purge_files($logs_path,'
|
220 |
-
|
221 |
-
//Purge
|
222 |
-
$fileSystem->purge_files($logs_path,'*
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
$this->logger->log_info(__METHOD__,'End');
|
225 |
|
@@ -317,6 +371,8 @@ class WPBackItUp_Backup {
|
|
317 |
return false;
|
318 |
}
|
319 |
|
|
|
|
|
320 |
//Write Site URL
|
321 |
$entry = site_url( '/' ) ."\n";
|
322 |
fwrite($handle, $entry);
|
@@ -328,8 +384,14 @@ class WPBackItUp_Backup {
|
|
328 |
//write WP version
|
329 |
$entry =get_bloginfo( 'version')."\n" ;
|
330 |
fwrite($handle, $entry);
|
|
|
|
|
|
|
|
|
|
|
331 |
fclose($handle);
|
332 |
|
|
|
333 |
if (file_exists($siteinfo)){
|
334 |
$this->logger->log_info(__METHOD__,'File created successfully.');
|
335 |
return true;
|
@@ -343,351 +405,215 @@ class WPBackItUp_Backup {
|
|
343 |
return false;
|
344 |
}
|
345 |
|
346 |
-
|
347 |
-
|
348 |
-
$this->logger->log_info(__METHOD__,'Begin');
|
349 |
|
350 |
-
$
|
351 |
-
$
|
352 |
-
$
|
353 |
-
$zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
|
354 |
|
355 |
-
|
356 |
-
|
357 |
-
$backup_item_count=0;
|
358 |
-
foreach(glob($plugins_root_path. '*',GLOB_ONLYDIR ) as $dir){
|
359 |
-
$source_plugin_folder=$dir .'/';
|
360 |
-
//This is the root target - needs to be hardcoded because we need to know where to find it on the restore.
|
361 |
-
$target_plugin_folder =$target_plugin_root . '/' .basename($dir);
|
362 |
-
|
363 |
-
//If target plugin doesnt exist backitup
|
364 |
-
if (!$zip->folder_exists($target_plugin_folder)) {
|
365 |
-
//If a plugin has already been backed up then this means there is more
|
366 |
-
if ($plugin_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
|
367 |
-
|
368 |
-
$this->logger->log_info(__METHOD__,'Backing up plugin:' .$target_plugin_folder);
|
369 |
-
|
370 |
-
//Backup the plugin folder
|
371 |
-
if (!$zip->compress_folder($source_plugin_folder,$target_plugin_folder)) {
|
372 |
-
$this->logger->log_error(__METHOD__,'Plugin NOT backed up successfully.');
|
373 |
-
return 'error';
|
374 |
-
}else{
|
375 |
-
$backup_item_count++;
|
376 |
-
$this->logger->log_info(__METHOD__,'Plugin backed up successfully:' .$backup_item_count);
|
377 |
-
$plugin_copied=true;
|
378 |
-
}
|
379 |
-
}
|
380 |
-
}
|
381 |
|
|
|
|
|
382 |
|
383 |
-
|
384 |
-
$
|
385 |
-
$
|
386 |
-
|
387 |
-
$this->logger->log_info(__METHOD__,'Backup file:' . $file);
|
388 |
-
if (!$zip->zip_file($file,$target_plugin_root)){
|
389 |
-
$this->logger->log_error(__METHOD__,'Plugin NOT backed up successfully.');
|
390 |
-
return 'error';
|
391 |
-
}
|
392 |
-
}
|
393 |
|
394 |
-
$
|
395 |
-
return 'complete';
|
396 |
}
|
397 |
|
398 |
-
|
399 |
-
|
400 |
-
$this->logger->log_info(__METHOD__,'Begin');
|
401 |
|
402 |
-
|
403 |
-
|
404 |
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
//Get a list of files/folders in the themes root
|
409 |
-
$theme_copied=false;
|
410 |
-
$backup_item_count=0;
|
411 |
-
foreach(glob($themes_root_path. '*',GLOB_ONLYDIR ) as $dir){
|
412 |
-
$source_theme_folder=$dir .'/';
|
413 |
-
$target_theme_folder = $target_theme_root . '/' .basename($dir);
|
414 |
-
|
415 |
-
//If target theme doesnt exist backitup
|
416 |
-
if (!$zip->folder_exists($target_theme_folder)){
|
417 |
-
//If a theme has already been backed up then this means there is more
|
418 |
-
if ($theme_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
|
419 |
-
|
420 |
-
$this->logger->log_info(__METHOD__,'Backing up theme:' .$target_theme_folder);
|
421 |
-
|
422 |
-
if (!$zip->compress_folder($source_theme_folder,$target_theme_folder)) {
|
423 |
-
$this->logger->log_error(__METHOD__,'Theme NOT backed up successfully.');
|
424 |
-
return 'error';
|
425 |
-
}else{
|
426 |
-
$backup_item_count++;
|
427 |
-
$this->logger->log_info(__METHOD__,'Theme backed up successfully:' .$backup_item_count);
|
428 |
-
$theme_copied=true;
|
429 |
-
}
|
430 |
-
}
|
431 |
-
}
|
432 |
|
|
|
|
|
433 |
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
}
|
443 |
-
}
|
444 |
-
|
445 |
|
446 |
-
|
447 |
-
|
448 |
-
|
|
|
|
|
449 |
|
|
|
450 |
|
451 |
-
|
452 |
-
|
453 |
-
$this->logger->log_info(__METHOD__,'Begin');
|
454 |
|
455 |
-
|
456 |
-
|
457 |
|
458 |
-
|
459 |
-
$zip_file_path = $this->backup_folder_root . $this->backup_filename;
|
460 |
-
$zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
|
461 |
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
foreach(glob($uploads_root_path. '*',GLOB_ONLYDIR ) as $dir){
|
467 |
-
$source_upload_folder=$dir .'/';
|
468 |
-
$target_upload_folder = $target_uploads_root .'/' .basename($dir);
|
469 |
-
|
470 |
-
//If target upload doesnt exist backitup
|
471 |
-
if (!$zip->folder_exists($target_upload_folder)) {
|
472 |
-
//If an upload has already been backed up then this means there is more
|
473 |
-
if ($upload_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
|
474 |
-
|
475 |
-
$this->logger->log_info(__METHOD__,'Backing up upload:' .$target_upload_folder);
|
476 |
-
|
477 |
-
if (!$zip->compress_folder($source_upload_folder,$target_upload_folder)) {
|
478 |
-
$this->logger->log_error(__METHOD__,'Upload NOT backed up successfully.');
|
479 |
-
return 'error';
|
480 |
-
}else{
|
481 |
-
$backup_item_count++;
|
482 |
-
$this->logger->log_info(__METHOD__,'Upload backed up successfully:'.$backup_item_count);
|
483 |
-
$upload_copied=true;
|
484 |
-
}
|
485 |
-
}
|
486 |
-
}
|
487 |
|
|
|
|
|
|
|
|
|
488 |
|
489 |
-
|
490 |
-
$this->logger->log_info(__METHOD__,'Backup all files in upload root');
|
491 |
-
$files = array_filter(glob($uploads_root_path. '*'), 'is_file');
|
492 |
-
foreach ($files as $file){
|
493 |
-
$this->logger->log_info(__METHOD__,'Backup file:' . $file);
|
494 |
-
if (!$zip->zip_file($file,$target_uploads_root)){
|
495 |
-
$this->logger->log_error(__METHOD__,'Upload NOT backed up successfully.');
|
496 |
-
return 'error';
|
497 |
-
}
|
498 |
-
}
|
499 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
500 |
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
|
|
|
|
|
|
|
|
|
|
|
505 |
|
506 |
-
|
507 |
-
|
508 |
-
$this->logger->log_info(__METHOD__,'Begin');
|
509 |
|
510 |
-
|
511 |
-
$upload_array = wp_upload_dir();
|
512 |
-
$uploads_folder = basename ($upload_array['basedir']);
|
513 |
-
$themes_folder = basename (WPBACKITUP__THEMES_ROOT_PATH);
|
514 |
-
$plugins_folder = basename (WPBACKITUP__PLUGINS_ROOT_PATH);
|
515 |
|
516 |
-
|
|
|
517 |
|
518 |
-
$wpback_ignore = explode(',',WPBACKITUP__BACKUP_IGNORE_LIST);
|
519 |
-
$wpcontent_ignore=array($uploads_folder, $themes_folder, $plugins_folder);
|
520 |
-
$ignore = array_merge($wpback_ignore,$wpcontent_ignore);
|
521 |
|
522 |
-
|
523 |
-
|
|
|
524 |
|
525 |
-
$zip_file_path = $this->
|
526 |
$zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
|
527 |
|
528 |
-
$
|
529 |
-
$backup_item_count=0;
|
530 |
-
$this->logger->log_info(__METHOD__,'Content Root Path:' .$wpcontent_path);
|
531 |
-
foreach(glob($wpcontent_path. '*',GLOB_ONLYDIR ) as $dir){
|
532 |
-
$source_other_folder=$dir .'/';
|
533 |
-
$target_other_folder = $target_other_root .'/' .basename($dir);
|
534 |
-
|
535 |
-
//If target other doesnt exist backitup
|
536 |
-
if( !$zip->folder_exists($target_other_folder) && !in_array(basename($dir), $ignore) ) {
|
537 |
-
//If a other has already been backed up then this means there is more
|
538 |
-
if ($other_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
|
539 |
-
|
540 |
-
$this->logger->log_info(__METHOD__,'Backing up other:' .$target_other_folder);
|
541 |
-
|
542 |
-
if (!$zip->compress_folder($source_other_folder,$target_other_folder)) {
|
543 |
-
$this->logger->log_error(__METHOD__,'Other NOT backed up successfully.');
|
544 |
-
return 'error';
|
545 |
-
}else{
|
546 |
-
$backup_item_count++;
|
547 |
-
$this->logger->log_info(__METHOD__,'Other backed up successfully:' .$backup_item_count);
|
548 |
-
$other_copied=true;
|
549 |
-
}
|
550 |
-
}
|
551 |
-
}
|
552 |
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
$this->logger->log_error(__METHOD__,'Other NOT backed up successfully.');
|
560 |
-
return 'error';
|
561 |
-
}
|
562 |
-
}
|
563 |
|
564 |
-
|
565 |
-
|
566 |
-
|
|
|
|
|
|
|
567 |
|
568 |
-
//backup all files in the site-data folder
|
569 |
-
public function backup_site_data(){
|
570 |
-
$this->logger->log_info(__METHOD__, 'Begin - Compress backup folder items:'.$this->backup_project_path);
|
571 |
|
572 |
-
|
|
|
|
|
|
|
|
|
|
|
573 |
|
574 |
-
|
575 |
-
|
576 |
|
577 |
-
|
578 |
-
$files = array_filter(glob($this->backup_project_path. '*'), 'is_file');
|
579 |
-
foreach ($files as $file){
|
580 |
-
$this->logger->log_info(__METHOD__,'Backup file:' . $file);
|
581 |
-
if (!$zip->zip_file($file,$target_other_root)){
|
582 |
-
return false;
|
583 |
-
}
|
584 |
-
}
|
585 |
|
|
|
|
|
|
|
586 |
|
587 |
-
|
588 |
-
|
589 |
-
|
|
|
|
|
|
|
|
|
|
|
590 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
|
592 |
-
public function validate_backup(){
|
593 |
-
$this->logger->log_info(__METHOD__,'Begin - Validate backup');
|
594 |
|
595 |
-
|
596 |
-
$
|
597 |
|
598 |
-
|
599 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
|
|
|
|
|
|
|
601 |
|
602 |
|
603 |
-
|
604 |
-
|
605 |
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
|
|
614 |
}
|
615 |
-
|
616 |
-
//Validate Themes
|
617 |
-
$themes_root_path = WPBACKITUP__THEMES_ROOT_PATH .'/';
|
618 |
-
$target_theme_root = 'wp-content-themes';
|
619 |
-
if(! $zip->validate_folder($themes_root_path, $target_theme_root)) {
|
620 |
-
$this->logger->log_error(__METHOD__,'Themes Validation:FAIL');
|
621 |
-
}else{
|
622 |
-
$this->logger->log_info(__METHOD__,'Themes Validation:SUCCESS');
|
623 |
-
}
|
624 |
-
|
625 |
-
//Validate Uploads
|
626 |
-
$upload_array = wp_upload_dir();
|
627 |
-
$uploads_root_path = $upload_array['basedir'] .'/';
|
628 |
-
$target_uploads_root = 'wp-content-uploads';
|
629 |
-
if(! $zip->validate_folder($uploads_root_path, $target_uploads_root)) {
|
630 |
-
$this->logger->log_error(__METHOD__,'Uploads Validation:FAIL');
|
631 |
-
}else{
|
632 |
-
$this->logger->log_info(__METHOD__,'Uploads Validation:SUCCESS');
|
633 |
-
}
|
634 |
-
|
635 |
-
//Validate everything on the that was in the backup temp folder
|
636 |
-
$site_data_root_path = $this->backup_project_path .'/';
|
637 |
-
$target_site_data_root = 'site-data';
|
638 |
-
if(! $zip->validate_folder($site_data_root_path, $target_site_data_root)) {
|
639 |
-
$this->logger->log_error(__METHOD__,'Site Data Validation:FAIL');
|
640 |
-
}else{
|
641 |
-
$this->logger->log_info(__METHOD__,'Site Data Validation:SUCCESS');
|
642 |
-
}
|
643 |
-
|
644 |
-
//Validate Other
|
645 |
-
$wpback_ignore = explode(',',WPBACKITUP__BACKUP_IGNORE_LIST);
|
646 |
-
$wpcontent_ignore=array(basename($uploads_root_path), basename($themes_root_path), basename($plugins_root_path));
|
647 |
-
$ignore = array_merge($wpback_ignore,$wpcontent_ignore);
|
648 |
-
|
649 |
-
$wpcontent_path = WPBACKITUP__CONTENT_PATH .'/';
|
650 |
-
$target_other_root = 'wp-content-other';
|
651 |
-
|
652 |
-
$this->logger->log_info(__METHOD__,'IGNORE:');
|
653 |
-
$this->logger->log($ignore);
|
654 |
-
|
655 |
-
//Validate the other folders
|
656 |
-
foreach(glob($wpcontent_path. '*',GLOB_ONLYDIR ) as $dir){
|
657 |
-
if( ! in_array(basename($dir), $ignore)){
|
658 |
-
$source_other_folder = $dir . '/';
|
659 |
-
$target_other_folder = $target_other_root . '/' . basename( $dir );
|
660 |
-
|
661 |
-
if(! $zip->validate_folder($source_other_folder, $target_other_folder)) {
|
662 |
-
$this->logger->log_error(__METHOD__,'Other Validation:FAIL - ' .basename( $dir ));
|
663 |
-
}else{
|
664 |
-
$this->logger->log_info(__METHOD__,'Other Validation:SUCCESS - '.basename( $dir ));
|
665 |
-
}
|
666 |
-
}
|
667 |
-
}
|
668 |
-
|
669 |
-
//Validate the other files
|
670 |
-
$files = array_filter(glob($wpcontent_path. '*'), 'is_file');
|
671 |
-
$file_validation=true;
|
672 |
-
foreach ($files as $file){
|
673 |
-
$target_other_file = $target_other_root . '/' . basename( $file );
|
674 |
-
if (false===$zip->validate_file($target_other_file)){
|
675 |
-
$this->logger->log_error(__METHOD__,'DIFF File:' .$target_other_file);
|
676 |
-
$file_validation=false;
|
677 |
-
};
|
678 |
-
}
|
679 |
-
|
680 |
-
// Write the other file validation results
|
681 |
-
if(! $file_validation) {
|
682 |
-
$this->logger->log_error(__METHOD__,'Other File Validation:FAIL');
|
683 |
-
}else{
|
684 |
-
$this->logger->log_info(__METHOD__,'Other File Validation:SUCCESS');
|
685 |
-
}
|
686 |
-
|
687 |
-
$this->logger->log_info(__METHOD__,'End - Validate backup');
|
688 |
-
return true;
|
689 |
}
|
690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
691 |
public function finalize_zip_file() {
|
692 |
$this->logger->log_info(__METHOD__,'Begin - Finalize the zip.');
|
693 |
|
@@ -718,5 +644,81 @@ class WPBackItUp_Backup {
|
|
718 |
|
719 |
}
|
720 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
721 |
|
722 |
}
|
57 |
$this->backup_name=$backup_name;
|
58 |
$this->backup_filename=$backup_name . '.tmp';
|
59 |
|
60 |
+
$backup_project_path = WPBACKITUP__BACKUP_PATH .'/TMP_'. $backup_name .'/';
|
61 |
|
62 |
$backup_folder_root =WPBACKITUP__BACKUP_PATH .'/';
|
63 |
$restore_folder_root = WPBACKITUP__RESTORE_FOLDER;
|
147 |
return true;
|
148 |
}
|
149 |
|
150 |
+
public function cleanup_backups_by_prefix($prefix) {
|
151 |
+
$this->logger->log_info( __METHOD__, 'Begin' );
|
152 |
+
$backup_root_path=$this->backup_folder_root;
|
153 |
+
|
154 |
+
//get a list of all the temps
|
155 |
+
$work_folder_list = glob($backup_root_path. $prefix .'*', GLOB_ONLYDIR);
|
156 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
157 |
+
foreach($work_folder_list as $folder) {
|
158 |
+
$file_system->recursive_delete($folder);
|
159 |
+
}
|
160 |
+
|
161 |
+
$this->logger->log_info( __METHOD__, 'End' );
|
162 |
+
}
|
163 |
+
|
164 |
+
public function cleanup_old_backups() {
|
165 |
+
$this->logger->log_info( __METHOD__, 'Begin' );
|
166 |
+
|
167 |
+
// --PURGE BACKUP FOLDER
|
168 |
+
//Purge logs in backup older than N days
|
169 |
+
$backup_root_path=$this->backup_folder_root;
|
170 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
171 |
+
|
172 |
+
//check retention limits
|
173 |
+
$file_system->purge_folders($backup_root_path,'*',$this->backup_retained_number);
|
174 |
+
|
175 |
+
$this->logger->log_info( __METHOD__, 'End' );
|
176 |
+
}
|
177 |
+
|
178 |
+
|
179 |
+
public function cleanup_unfinished_backups_OLD(){
|
180 |
$dir=$this->backup_folder_root;
|
181 |
$this->logger->log_info(__METHOD__,'Begin:'.$dir);
|
182 |
$ignore = array('cgi-bin','.','..','._');
|
205 |
$this->logger->log_info(__METHOD__, 'Begin - Cleanup Backup Folder:' . $path);
|
206 |
|
207 |
$fileSystem = new WPBackItUp_FileSystem($this->logger);
|
208 |
+
$work_files = array_filter(glob($this->backup_project_path. '*.{txt,sql}',GLOB_BRACE), 'is_file');
|
209 |
+
|
210 |
+
if(!$fileSystem ->delete_files($work_files)) {
|
211 |
+
$this->logger->log_error(__METHOD__,'Work files could not be deleted');
|
212 |
return false;
|
213 |
}
|
214 |
|
215 |
+
$this->logger->log_info(__METHOD__,'End - Work Files Deleted');
|
216 |
return true;
|
217 |
}
|
218 |
|
219 |
+
public function delete_site_data_files(){
|
220 |
+
$path = $this->backup_project_path;
|
221 |
+
$this->logger->log_info(__METHOD__, 'Begin - Cleanup Backup Folder:' . $path);
|
222 |
+
|
223 |
+
$fileSystem = new WPBackItUp_FileSystem($this->logger);
|
224 |
+
$work_files = array_filter(glob($this->backup_project_path. '*.{txt,sql}',GLOB_BRACE), 'is_file');
|
225 |
+
|
226 |
+
if(!$fileSystem ->delete_files($work_files)) {
|
227 |
+
$this->logger->log_error(__METHOD__,'Work files could not be deleted');
|
228 |
+
return false;
|
229 |
+
}
|
230 |
+
|
231 |
+
$this->logger->log_info(__METHOD__,'End - Work Files Deleted');
|
232 |
+
return true;
|
233 |
+
}
|
234 |
+
|
235 |
+
|
236 |
public function purge_old_files(){
|
237 |
$this->logger->log_info(__METHOD__,'Begin');
|
238 |
$fileSystem = new WPBackItUp_FileSystem( $this->logger);
|
252 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'/logs/';
|
253 |
|
254 |
//Purge logs in logs older than 5 days
|
255 |
+
$fileSystem->purge_files($logs_path,'*.log',$this->backup_retained_days);
|
256 |
+
|
257 |
+
//Purge Zipped logs in logs older than 5 days
|
258 |
+
$fileSystem->purge_files($logs_path,'*.zip',$this->backup_retained_days);
|
259 |
+
|
260 |
+
//Purge logs in logs older than 5 days
|
261 |
+
// $fileSystem->purge_files($logs_path,'Backup_*.log',$this->backup_retained_days);
|
262 |
+
|
263 |
+
// //Purge debug logs in logs older than 5 days
|
264 |
+
// $fileSystem->purge_files($logs_path,'*debug*.log',$this->backup_retained_days);
|
265 |
+
//
|
266 |
+
// //Purge upload logs in logs older than 5 days
|
267 |
+
// $fileSystem->purge_files($logs_path,'*upload*.log',$this->backup_retained_days);
|
268 |
+
//
|
269 |
+
// //Purge cleanup logs in logs older than 5 days
|
270 |
+
// $fileSystem->purge_files($logs_path,'*cleanup*.log',$this->backup_retained_days);
|
271 |
+
//
|
272 |
+
// //Purge Zipped logs in logs older than 5 days
|
273 |
+
// $fileSystem->purge_files($logs_path,'logs_*.zip',$this->backup_retained_days);
|
274 |
+
//
|
275 |
+
// //Purge restore logs in logs older than 5 days
|
276 |
+
// $fileSystem->purge_files($logs_path,'*restore*.log',$this->backup_retained_days);
|
277 |
|
278 |
$this->logger->log_info(__METHOD__,'End');
|
279 |
|
371 |
return false;
|
372 |
}
|
373 |
|
374 |
+
//Probably should change to json format
|
375 |
+
|
376 |
//Write Site URL
|
377 |
$entry = site_url( '/' ) ."\n";
|
378 |
fwrite($handle, $entry);
|
384 |
//write WP version
|
385 |
$entry =get_bloginfo( 'version')."\n" ;
|
386 |
fwrite($handle, $entry);
|
387 |
+
|
388 |
+
//write WP BackItUp
|
389 |
+
$entry =WPBACKITUP__VERSION."\n" ;
|
390 |
+
fwrite($handle, $entry);
|
391 |
+
|
392 |
fclose($handle);
|
393 |
|
394 |
+
|
395 |
if (file_exists($siteinfo)){
|
396 |
$this->logger->log_info(__METHOD__,'File created successfully.');
|
397 |
return true;
|
405 |
return false;
|
406 |
}
|
407 |
|
408 |
+
public function get_plugins_file_list() {
|
409 |
+
$this->logger->log_info( __METHOD__, 'Begin' );
|
|
|
410 |
|
411 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
412 |
+
$plugins_file_list = $file_system->get_recursive_file_list(WPBACKITUP__PLUGINS_ROOT_PATH. '/*' );
|
413 |
+
$this->logger->log_info( __METHOD__, 'Plugin File Count: ' .count($plugins_file_list));
|
|
|
414 |
|
415 |
+
return $plugins_file_list;
|
416 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
|
418 |
+
public function get_themes_file_list() {
|
419 |
+
$this->logger->log_info( __METHOD__, 'Begin' );
|
420 |
|
421 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
422 |
+
$themes_root_path = WPBACKITUP__THEMES_ROOT_PATH;
|
423 |
+
$themes_file_list = $file_system->get_recursive_file_list($themes_root_path. '/*' );
|
424 |
+
$this->logger->log_info( __METHOD__, 'Themes File Count: ' .count($themes_file_list));
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
|
426 |
+
return $themes_file_list;
|
|
|
427 |
}
|
428 |
|
429 |
+
public function get_uploads_file_list() {
|
430 |
+
$this->logger->log_info( __METHOD__, 'Begin' );
|
|
|
431 |
|
432 |
+
$upload_array = wp_upload_dir();
|
433 |
+
$uploads_root_path = $upload_array['basedir'];
|
434 |
|
435 |
+
//ignore these folders under uploads
|
436 |
+
$ignore = explode(',',WPBACKITUP__BACKUP_IGNORE_LIST);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
437 |
|
438 |
+
$uploads_folderlist = glob($uploads_root_path. '/*',GLOB_ONLYDIR|GLOB_NOSORT);
|
439 |
+
$uploads_file_list=array();
|
440 |
|
441 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
442 |
+
foreach ( $uploads_folderlist as $folder ) {
|
443 |
+
if (! $this->strposa(basename($folder), $ignore)){
|
444 |
+
array_push($uploads_file_list,$folder);
|
445 |
+
$file_list = $file_system->get_recursive_file_list($folder. '/*' );
|
446 |
+
$uploads_file_list = array_merge($uploads_file_list,$file_list);
|
447 |
+
}
|
448 |
+
}
|
|
|
|
|
|
|
449 |
|
450 |
+
//Need to grab the files in the root also
|
451 |
+
$files_only = array_filter(glob($uploads_root_path. '/*'), 'is_file');
|
452 |
+
if (count($files_only)>0){
|
453 |
+
$uploads_file_list = array_merge($uploads_file_list,$files_only);
|
454 |
+
}
|
455 |
|
456 |
+
$this->logger->log_info( __METHOD__, 'Themes File Count: ' .count($uploads_file_list));
|
457 |
|
458 |
+
return $uploads_file_list;
|
459 |
+
}
|
|
|
460 |
|
461 |
+
public function get_other_file_list() {
|
462 |
+
$this->logger->log_info( __METHOD__, 'Begin' );
|
463 |
|
464 |
+
$wpcontent_path = WPBACKITUP__CONTENT_PATH;
|
|
|
|
|
465 |
|
466 |
+
$upload_array = wp_upload_dir();
|
467 |
+
$uploads_folder = basename ($upload_array['basedir']);
|
468 |
+
$themes_folder = basename (WPBACKITUP__THEMES_ROOT_PATH);
|
469 |
+
$plugins_folder = basename (WPBACKITUP__PLUGINS_ROOT_PATH);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
|
471 |
+
//ignore these folders
|
472 |
+
$wpback_ignore = explode(',',WPBACKITUP__BACKUP_IGNORE_LIST);
|
473 |
+
$wpcontent_ignore=array($uploads_folder, $themes_folder, $plugins_folder);
|
474 |
+
$ignore = array_merge($wpback_ignore,$wpcontent_ignore);
|
475 |
|
476 |
+
$wpcontent_folderlist = glob($wpcontent_path. '/*',GLOB_ONLYDIR|GLOB_NOSORT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
|
478 |
+
$other_file_list=array();
|
479 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
480 |
+
foreach ( $wpcontent_folderlist as $folder ) {
|
481 |
+
if (!$this->strposa(basename($folder), $ignore)){
|
482 |
+
array_push($other_file_list,$folder);
|
483 |
+
$file_list = $file_system->get_recursive_file_list($folder. '/*' );
|
484 |
+
$other_file_list = array_merge($other_file_list,$file_list);
|
485 |
+
}
|
486 |
+
}
|
487 |
|
488 |
+
//Need to grab the files in the root also
|
489 |
+
$files_only = array_filter(glob($wpcontent_path. '/*'), 'is_file');
|
490 |
+
if (count($files_only)>0){
|
491 |
|
492 |
+
//Get rid of the debug.log file - dont want to restore it
|
493 |
+
$debug_log_index = $this->search_array('debug.log', $files_only);
|
494 |
+
if (false!==$debug_log_index) {
|
495 |
+
unset($files_only[$debug_log_index]);
|
496 |
+
}
|
497 |
|
498 |
+
$other_file_list = array_merge($other_file_list,$files_only);
|
499 |
+
}
|
|
|
500 |
|
501 |
+
$this->logger->log_info( __METHOD__, 'Other File Count: ' .count($other_file_list));
|
|
|
|
|
|
|
|
|
502 |
|
503 |
+
return $other_file_list;
|
504 |
+
}
|
505 |
|
|
|
|
|
|
|
506 |
|
507 |
+
//BackUp
|
508 |
+
public function backup_file_list($source_root,$target_root,$suffix,$file_list,$batch_size,$ignore=''){
|
509 |
+
$this->logger->log_info(__METHOD__,'Begin - Item Count: '. count($file_list));
|
510 |
|
511 |
+
$zip_file_path = $this->backup_project_path . $this->backup_name .'-'.$suffix .'.tmp';
|
512 |
$zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
|
513 |
|
514 |
+
foreach($file_list as $item) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
515 |
|
516 |
+
//skip it if in ignore
|
517 |
+
if ( !empty($ignore) && false!== strpos($item,$ignore)) {
|
518 |
+
$this->logger->log_info( __METHOD__, 'Skip File:' . $item );
|
519 |
+
array_shift($file_list); //remove from list
|
520 |
+
continue;
|
521 |
+
}
|
|
|
|
|
|
|
|
|
522 |
|
523 |
+
//skip it if folder
|
524 |
+
if ( is_dir( $item ) ) {
|
525 |
+
$this->logger->log_info( __METHOD__, 'Skip folder:' . $item );
|
526 |
+
array_shift( $file_list ); //remove from list
|
527 |
+
continue;
|
528 |
+
}
|
529 |
|
|
|
|
|
|
|
530 |
|
531 |
+
//replace the source path with the target
|
532 |
+
$target_item_path = str_replace(rtrim($source_root, '/'),rtrim($target_root,'/'),$item);
|
533 |
+
if ( $zip->add_file($item,$target_item_path)) {
|
534 |
+
array_shift($file_list);
|
535 |
+
$this->logger->log_info( __METHOD__, 'File Added:' . $target_item_path );
|
536 |
+
$this->logger->log_info( __METHOD__, 'Zip file count:' . $zip->get_zip_file_count() . '>=' . $batch_size);
|
537 |
|
538 |
+
//If we have added X# of files or hit the size limit then lets close the zip and finish on the next pass
|
539 |
+
if( $zip->get_zip_file_count()>=$batch_size){
|
540 |
|
541 |
+
$zip->close();//close the zip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
|
543 |
+
//check the compressed file size
|
544 |
+
$compressed_zip_file_size = $zip->get_zip_actual_size();
|
545 |
+
$this->logger->log_info( __METHOD__, 'Zip Actual Size after close:' . $zip->get_zip_actual_size());
|
546 |
|
547 |
+
//if the zip is too big we need to rename it
|
548 |
+
$threshold = $zip->get_max_zip_size(.8);
|
549 |
+
if ($compressed_zip_file_size >= $threshold) {
|
550 |
+
$this->logger->log_info(__METHOD__,'Zip hit max size threshold:'.$compressed_zip_file_size .'>' .$threshold );
|
551 |
+
if (! $this->add_zip_suffix($zip_file_path)){
|
552 |
+
return 'error';
|
553 |
+
}
|
554 |
+
}
|
555 |
|
556 |
+
$this->logger->log_info(__METHOD__,'End - Item Count:' . count($file_list));
|
557 |
+
return $file_list;
|
558 |
+
}
|
559 |
+
} else {
|
560 |
+
$this->logger->log_error( __METHOD__, 'File NOT added:' . $target_item_path );
|
561 |
+
return 'error';
|
562 |
+
}
|
563 |
+
}
|
564 |
|
|
|
|
|
565 |
|
566 |
+
//if we get here then close the zip
|
567 |
+
$zip->close();//close the zip
|
568 |
|
569 |
+
//if there are no more files to add then rename the zip
|
570 |
+
//Check to see if the file exists, it is possible that it does not if only empty folders were contained
|
571 |
+
if(count($file_list)==0 && file_exists($zip_file_path) ){
|
572 |
+
$this->logger->log_info( __METHOD__, 'Zip Actual Size after close:' . $zip->get_zip_actual_size());
|
573 |
+
if (! $this->add_zip_suffix($zip_file_path)){
|
574 |
+
return 'error';
|
575 |
+
}
|
576 |
+
}
|
577 |
|
578 |
+
$this->logger->log_info(__METHOD__,'End - Item Count:' . count($file_list));
|
579 |
+
return $file_list;
|
580 |
+
}
|
581 |
|
582 |
|
583 |
+
private function strposa($haystack, $needle) {
|
584 |
+
if(!is_array($needle)) $needle = array($needle);
|
585 |
|
586 |
+
foreach($needle as $query) {
|
587 |
+
//If wildcard on end then compare
|
588 |
+
if ('*' == substr($query, -1) && strpos( $haystack, rtrim($query,"*")) !== false) {
|
589 |
+
return true;
|
590 |
+
} else {
|
591 |
+
if ( $haystack==$query ) {
|
592 |
+
return true;
|
593 |
+
}
|
594 |
+
}
|
595 |
}
|
596 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
}
|
598 |
|
599 |
+
private function add_zip_suffix($zip_file_path){
|
600 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
601 |
+
|
602 |
+
$file_extension = pathinfo($zip_file_path, PATHINFO_EXTENSION);
|
603 |
+
$this->logger->log_info(__METHOD__,'File Extension:'.$file_extension);
|
604 |
+
if ($file_extension!='zip'){
|
605 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
606 |
+
$new_zip_name = str_replace('.' . $file_extension,'-'.time() .'.zip',$zip_file_path);
|
607 |
+
if ( !$file_system->rename_file($zip_file_path,$new_zip_name)){
|
608 |
+
$this->logger->log_error(__METHOD__,'Zip could not be renamed.');
|
609 |
+
return false;
|
610 |
+
}
|
611 |
+
}
|
612 |
+
|
613 |
+
//if we get here the file was renamed or was .zip already
|
614 |
+
return true;
|
615 |
+
}
|
616 |
+
|
617 |
public function finalize_zip_file() {
|
618 |
$this->logger->log_info(__METHOD__,'Begin - Finalize the zip.');
|
619 |
|
644 |
|
645 |
}
|
646 |
|
647 |
+
//Create manifest file
|
648 |
+
public function create_backup_manifest(){
|
649 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
650 |
+
|
651 |
+
//get a list of all the zips
|
652 |
+
$backup_files_path = array_filter(glob($this->backup_project_path. '*.zip'), 'is_file');
|
653 |
+
if (count($backup_files_path)>0){
|
654 |
+
//get rid of the path.
|
655 |
+
$backup_files = str_replace($this->backup_project_path,'',$backup_files_path);
|
656 |
+
$manifest_file=$this->backup_project_path . 'backupmanifest.txt';
|
657 |
+
file_put_contents($manifest_file,json_encode($backup_files));
|
658 |
+
|
659 |
+
//Find the main zip in the array to get the path
|
660 |
+
$main_zip_index = $this->search_array('-main-', $backup_files_path);
|
661 |
+
|
662 |
+
//add it to the main zip file
|
663 |
+
if ($main_zip_index!==false){
|
664 |
+
$zip_file_path = $backup_files_path[$main_zip_index];
|
665 |
+
$zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
|
666 |
+
$target_item_path = str_replace(rtrim($this->backup_project_path, '/'),rtrim('site-data','/'),$manifest_file);
|
667 |
+
if ( $zip->add_file($manifest_file,$target_item_path)) {
|
668 |
+
$zip->close();//close the zip
|
669 |
+
$this->logger->log_info(__METHOD__,'End - Manifest created.');
|
670 |
+
return true;
|
671 |
+
}
|
672 |
+
}
|
673 |
+
}
|
674 |
+
|
675 |
+
$this->logger->log_error(__METHOD__,'End - Manifest not created.');
|
676 |
+
return false;
|
677 |
+
}
|
678 |
+
|
679 |
+
private function search_array($search, $array)
|
680 |
+
{
|
681 |
+
foreach($array as $key => $value)
|
682 |
+
{
|
683 |
+
if (stristr($value, $search))
|
684 |
+
{
|
685 |
+
return $key;
|
686 |
+
}
|
687 |
+
}
|
688 |
+
return false;
|
689 |
+
}
|
690 |
+
|
691 |
+
|
692 |
+
public function rename_backup_folder() {
|
693 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
694 |
+
|
695 |
+
$backup_project_path = $this->backup_project_path;
|
696 |
+
//remove the 4 character prefix
|
697 |
+
$new_backup_path = str_replace('TMP_','',$backup_project_path);
|
698 |
+
|
699 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
700 |
+
if (! $file_system->rename_file($backup_project_path,$new_backup_path)){
|
701 |
+
$this->logger->log_error(__METHOD__,'Folder could not be renamed');
|
702 |
+
return false;
|
703 |
+
}
|
704 |
+
|
705 |
+
$this->set_final_backup_path();
|
706 |
+
|
707 |
+
$this->logger->log_info(__METHOD__,'End');
|
708 |
+
return true;
|
709 |
+
}
|
710 |
+
|
711 |
+
//this is needed because it is set to TMP until finalization then needed a way to know where the current path is
|
712 |
+
public function set_final_backup_path(){
|
713 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
714 |
+
|
715 |
+
$backup_project_path = $this->backup_project_path;
|
716 |
+
$new_backup_path = str_replace('TMP_','',$backup_project_path);
|
717 |
+
|
718 |
+
//set the path to the new path
|
719 |
+
$this->backup_project_path=$new_backup_path;
|
720 |
+
|
721 |
+
$this->logger->log_info(__METHOD__,'End');
|
722 |
+
}
|
723 |
|
724 |
}
|
lib/includes/class-filesystem.php
CHANGED
@@ -287,6 +287,9 @@ class WPBackItUp_FileSystem {
|
|
287 |
$i = 1;
|
288 |
foreach ($FileList as $key => $val)
|
289 |
{
|
|
|
|
|
|
|
290 |
if($i <= $number_Files_Allowed)
|
291 |
{
|
292 |
$i++;
|
@@ -317,11 +320,15 @@ class WPBackItUp_FileSystem {
|
|
317 |
}
|
318 |
|
319 |
$FileList = glob($path . $file_pattern);
|
320 |
-
|
|
|
321 |
usort($FileList, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
|
322 |
|
323 |
foreach ($FileList as $key => $file)
|
324 |
{
|
|
|
|
|
|
|
325 |
$current_date = new DateTime('now');
|
326 |
$file_mod_date = new DateTime(date('Y-m-d',filemtime($file)));
|
327 |
|
@@ -344,7 +351,66 @@ class WPBackItUp_FileSystem {
|
|
344 |
return true;
|
345 |
}
|
346 |
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
$this->logger->log('(FileSytem.get_file_handle) Path:' . $path);
|
349 |
|
350 |
try {
|
@@ -426,7 +492,7 @@ class WPBackItUp_FileSystem {
|
|
426 |
return true;
|
427 |
}
|
428 |
else{
|
429 |
-
$this->logger->log_error(__METHOD__,'File could not be
|
430 |
$this->logger->log(error_get_last());
|
431 |
return false;
|
432 |
}
|
@@ -466,4 +532,22 @@ class WPBackItUp_FileSystem {
|
|
466 |
$this->logger->log_info(__METHOD__,'End');
|
467 |
}
|
468 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
469 |
}
|
287 |
$i = 1;
|
288 |
foreach ($FileList as $key => $val)
|
289 |
{
|
290 |
+
$this->logger->log_info(__METHOD__,' File:'.$val);
|
291 |
+
$this->logger->log_info(__METHOD__,' File Date Time:'.filemtime($val));
|
292 |
+
|
293 |
if($i <= $number_Files_Allowed)
|
294 |
{
|
295 |
$i++;
|
320 |
}
|
321 |
|
322 |
$FileList = glob($path . $file_pattern);
|
323 |
+
|
324 |
+
//Sort by Date Time oldest first so can break when all old files are deleted
|
325 |
usort($FileList, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
|
326 |
|
327 |
foreach ($FileList as $key => $file)
|
328 |
{
|
329 |
+
$this->logger->log_info(__METHOD__,' File:'.$file);
|
330 |
+
$this->logger->log_info(__METHOD__,' File Date Time:'.filemtime($file));
|
331 |
+
|
332 |
$current_date = new DateTime('now');
|
333 |
$file_mod_date = new DateTime(date('Y-m-d',filemtime($file)));
|
334 |
|
351 |
return true;
|
352 |
}
|
353 |
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Purge the backups that exceed the retained number setting
|
357 |
+
*
|
358 |
+
* @param $path
|
359 |
+
* @param $pattern
|
360 |
+
* @param $retention_limit
|
361 |
+
*
|
362 |
+
* @return bool
|
363 |
+
*/
|
364 |
+
public function purge_folders($path, $pattern, $retention_limit)
|
365 |
+
{
|
366 |
+
$this->logger->log_info(__METHOD__,' Purge folders retained number:' . $retention_limit);
|
367 |
+
$this->logger->log_info(__METHOD__,' Purge folder path:' . $path);
|
368 |
+
$this->logger->log_info(__METHOD__,' Purge pattern:' . $pattern);
|
369 |
+
|
370 |
+
//Check Parms
|
371 |
+
if (empty($path) || empty($pattern) || !is_numeric($retention_limit)){
|
372 |
+
$this->logger->log_error(__METHOD__,' Invalid Parm values');
|
373 |
+
return false;
|
374 |
+
}
|
375 |
+
|
376 |
+
$folder_list = glob($path . $pattern, GLOB_ONLYDIR);
|
377 |
+
//Sort by Date Time so oldest is deleted first
|
378 |
+
usort($folder_list, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
|
379 |
+
|
380 |
+
$backup_count=0;
|
381 |
+
foreach ($folder_list as $key => $folder)
|
382 |
+
{
|
383 |
+
$this->logger->log_info(__METHOD__,' Folder:'.$folder);
|
384 |
+
$this->logger->log_info(__METHOD__,' Folder Date Time:'.filemtime($folder));
|
385 |
+
|
386 |
+
++$backup_count;
|
387 |
+
if($backup_count>$retention_limit){
|
388 |
+
if (file_exists($folder)) {
|
389 |
+
$this->recursive_delete($folder);
|
390 |
+
}
|
391 |
+
}
|
392 |
+
}
|
393 |
+
$this->logger->log_info(__METHOD__,'End');
|
394 |
+
return true;
|
395 |
+
}
|
396 |
+
|
397 |
+
public function delete_files($file_list)
|
398 |
+
{
|
399 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
400 |
+
|
401 |
+
foreach ($file_list as $key => $file)
|
402 |
+
{
|
403 |
+
if (file_exists($file)){
|
404 |
+
unlink($file);
|
405 |
+
$this->logger->log('Deleted:' . $file);
|
406 |
+
}
|
407 |
+
}
|
408 |
+
$this->logger->log_info(__METHOD__,'End');
|
409 |
+
return true;
|
410 |
+
}
|
411 |
+
|
412 |
+
|
413 |
+
function get_file_handle($path,$newFile=false) {
|
414 |
$this->logger->log('(FileSytem.get_file_handle) Path:' . $path);
|
415 |
|
416 |
try {
|
492 |
return true;
|
493 |
}
|
494 |
else{
|
495 |
+
$this->logger->log_error(__METHOD__,'File could not be renamed:');
|
496 |
$this->logger->log(error_get_last());
|
497 |
return false;
|
498 |
}
|
532 |
$this->logger->log_info(__METHOD__,'End');
|
533 |
}
|
534 |
|
535 |
+
|
536 |
+
public function get_recursive_file_list($pattern) {
|
537 |
+
$this->logger->log_info( __METHOD__, 'Begin: ' .$pattern );
|
538 |
+
|
539 |
+
return $this->glob_recursive($pattern);
|
540 |
+
}
|
541 |
+
|
542 |
+
private function glob_recursive($pattern, $flags = 0)
|
543 |
+
{
|
544 |
+
//The order here is important because the folders must be in the list before the files.
|
545 |
+
$files = glob($pattern, $flags);
|
546 |
+
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR) as $dir)
|
547 |
+
{
|
548 |
+
$files = array_merge($files, $this->glob_recursive($dir.'/'.basename($pattern), $flags));
|
549 |
+
}
|
550 |
+
|
551 |
+
return $files;
|
552 |
+
}
|
553 |
}
|
lib/includes/class-job.php
CHANGED
@@ -17,20 +17,29 @@ class WPBackItUp_Job {
|
|
17 |
private $job_end_time;
|
18 |
|
19 |
static private $backup_tasks = array(
|
20 |
-
1=>'
|
21 |
-
2=>'
|
22 |
-
3=>'
|
23 |
-
4=>'
|
24 |
-
5=>'
|
25 |
-
6=>'
|
26 |
-
7=>'
|
27 |
-
8=>'
|
28 |
-
9=>'
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
);
|
31 |
|
32 |
static private $cleanup_tasks = array(
|
33 |
-
1=>'
|
34 |
);
|
35 |
|
36 |
function __construct($job) {
|
@@ -65,6 +74,8 @@ class WPBackItUp_Job {
|
|
65 |
|
66 |
$tasks = get_post_meta( $this->job_id);
|
67 |
foreach($tasks as $key=>$value) {
|
|
|
|
|
68 |
|
69 |
$task = get_post_meta($this->job_id,$key);
|
70 |
|
@@ -96,6 +107,10 @@ class WPBackItUp_Job {
|
|
96 |
|
97 |
//Enumerate the tasks
|
98 |
foreach ($tasks as $key => $value) {
|
|
|
|
|
|
|
|
|
99 |
$task = get_post_meta($this->job_id,$key);
|
100 |
|
101 |
//Get Task Properties
|
@@ -104,7 +119,7 @@ class WPBackItUp_Job {
|
|
104 |
$task_allocated_id = $task[0]['task_allocated_id'];
|
105 |
$task_last_updated = $task[0]['task_last_updated'];
|
106 |
|
107 |
-
//if next
|
108 |
switch ($task_status) {
|
109 |
case "queued":
|
110 |
//Try allocate task
|
@@ -251,6 +266,33 @@ class WPBackItUp_Job {
|
|
251 |
}
|
252 |
|
253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
/**
|
255 |
* Set job status to active
|
256 |
*/
|
@@ -544,11 +586,20 @@ class WPBackItUp_Job {
|
|
544 |
$job_id = wp_insert_post($new_job );
|
545 |
$logger->log_info(__METHOD__,'Job Created:' .$job_id);
|
546 |
|
547 |
-
|
548 |
switch ($job_name) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
549 |
case "backup":
|
550 |
//add the tasks
|
551 |
-
if ( false === self::
|
552 |
$logger->log_info( __METHOD__, 'Backup tasks not Created - deleting job:' . $job_id );
|
553 |
wp_delete_post( $job_id, true );
|
554 |
return false;
|
@@ -558,7 +609,7 @@ class WPBackItUp_Job {
|
|
558 |
|
559 |
case "cleanup":
|
560 |
//add the tasks
|
561 |
-
if ( false === self::
|
562 |
$logger->log_info( __METHOD__, 'Cleanup tasks not Created - deleting job:' . $job_id );
|
563 |
wp_delete_post( $job_id, true );
|
564 |
return false;
|
@@ -577,51 +628,20 @@ class WPBackItUp_Job {
|
|
577 |
|
578 |
/**
|
579 |
* Create all the tasks for a job
|
580 |
-
* @param $job_id
|
581 |
*
|
582 |
-
* @return bool
|
583 |
-
*/
|
584 |
-
private static function create_backup_tasks($job_id){
|
585 |
-
$logger = new WPBackItUp_Logger(false,null,'debug_job');
|
586 |
-
$logger->log_info(__METHOD__,'Begin');
|
587 |
-
|
588 |
-
//Create the job tasks
|
589 |
-
$last_updated_time=time();
|
590 |
-
foreach (self::$backup_tasks as $key => $value){
|
591 |
-
$task_name = $value;
|
592 |
-
$task_data = array(
|
593 |
-
'task_id' => $task_name,
|
594 |
-
'task_status' => 'queued',
|
595 |
-
'task_allocated_id'=>'',
|
596 |
-
'task_last_updated'=>$last_updated_time
|
597 |
-
);
|
598 |
-
$task_created = update_post_meta( $job_id, $task_name, $task_data );
|
599 |
-
|
600 |
-
if (false===$task_created){
|
601 |
-
$logger->log_error( __METHOD__, 'Tasks NOT created');
|
602 |
-
return false;
|
603 |
-
}
|
604 |
-
$logger->log_info( __METHOD__, 'task created:' . $task_created );
|
605 |
-
}
|
606 |
-
|
607 |
-
$logger->log_info(__METHOD__,'End');
|
608 |
-
return true;
|
609 |
-
|
610 |
-
}
|
611 |
-
|
612 |
-
/**
|
613 |
-
* Create all the tasks for a job
|
614 |
* @param $job_id
|
615 |
*
|
|
|
|
|
616 |
* @return bool
|
617 |
*/
|
618 |
-
private static function
|
619 |
$logger = new WPBackItUp_Logger(false,null,'debug_job');
|
620 |
$logger->log_info(__METHOD__,'Begin');
|
621 |
|
622 |
//Create the job tasks
|
623 |
$last_updated_time=time();
|
624 |
-
foreach (
|
625 |
$task_name = $value;
|
626 |
$task_data = array(
|
627 |
'task_id' => $task_name,
|
@@ -635,7 +655,7 @@ class WPBackItUp_Job {
|
|
635 |
$logger->log_error( __METHOD__, 'Tasks NOT created');
|
636 |
return false;
|
637 |
}
|
638 |
-
$logger->log_info( __METHOD__, 'task created:' . $task_created );
|
639 |
}
|
640 |
|
641 |
$logger->log_info(__METHOD__,'End');
|
@@ -643,6 +663,74 @@ class WPBackItUp_Job {
|
|
643 |
|
644 |
}
|
645 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
/**
|
647 |
* @return mixed
|
648 |
*/
|
@@ -656,5 +744,13 @@ class WPBackItUp_Job {
|
|
656 |
public function get_job_end_time() {
|
657 |
return $this->job_end_time;
|
658 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
659 |
}
|
660 |
|
17 |
private $job_end_time;
|
18 |
|
19 |
static private $backup_tasks = array(
|
20 |
+
1=>'task_preparing',
|
21 |
+
2=>'task_backup_db' ,
|
22 |
+
3=>'task_backup_siteinfo',
|
23 |
+
4=>'task_backup_themes',
|
24 |
+
5=>'task_backup_plugins',
|
25 |
+
6=>'task_backup_uploads',
|
26 |
+
7=>'task_backup_other',
|
27 |
+
8=>'task_validate_backup',
|
28 |
+
9=>'task_finalize_backup',
|
29 |
+
);
|
30 |
+
|
31 |
+
static private $restore_tasks = array(
|
32 |
+
1=>'task_preparing',
|
33 |
+
2=>'task_unzip_backup_set',
|
34 |
+
3=>'task_validate_backup',
|
35 |
+
4=>'task_create_checkpoint',
|
36 |
+
5=>'task_stage_wpcontent',
|
37 |
+
6=>'task_restore_wpcontent',
|
38 |
+
8=>'task_restore_database',
|
39 |
);
|
40 |
|
41 |
static private $cleanup_tasks = array(
|
42 |
+
1=>'task_scheduled_cleanup'
|
43 |
);
|
44 |
|
45 |
function __construct($job) {
|
74 |
|
75 |
$tasks = get_post_meta( $this->job_id);
|
76 |
foreach($tasks as $key=>$value) {
|
77 |
+
//Is this a task of job meta data
|
78 |
+
if (substr($key, 0, 4)!='task') continue;
|
79 |
|
80 |
$task = get_post_meta($this->job_id,$key);
|
81 |
|
107 |
|
108 |
//Enumerate the tasks
|
109 |
foreach ($tasks as $key => $value) {
|
110 |
+
|
111 |
+
//Is this a task of job meta data
|
112 |
+
if (substr($key, 0, 4)!='task') continue;
|
113 |
+
|
114 |
$task = get_post_meta($this->job_id,$key);
|
115 |
|
116 |
//Get Task Properties
|
119 |
$task_allocated_id = $task[0]['task_allocated_id'];
|
120 |
$task_last_updated = $task[0]['task_last_updated'];
|
121 |
|
122 |
+
//if next task in stack is queued then its time to get to work
|
123 |
switch ($task_status) {
|
124 |
case "queued":
|
125 |
//Try allocate task
|
266 |
}
|
267 |
|
268 |
|
269 |
+
public function update_job_meta($meta_name,$meta_value){
|
270 |
+
$this->logger->log_info(__METHOD__,'Begin - Update job meta:' .$this->job_id .'-'. $meta_name);
|
271 |
+
|
272 |
+
return update_post_meta( $this->job_id, $meta_name, $meta_value );
|
273 |
+
}
|
274 |
+
|
275 |
+
// public function update_task_file_list($task_name,$file_list){
|
276 |
+
// $this->logger->log_info(__METHOD__,'Begin - Update file list:' .$this->job_id .'-'. $task_name);
|
277 |
+
//
|
278 |
+
// return update_post_meta( $this->job_id, $task_name, wp_slash($file_list) );
|
279 |
+
// }
|
280 |
+
|
281 |
+
// public function get_task_file_list($task_name){
|
282 |
+
// $this->logger->log_info(__METHOD__,'Begin - Update file list:' .$this->job_id .'-'. $task_name);
|
283 |
+
//
|
284 |
+
// $file_list = get_post_meta($this->job_id,$task_name,true);
|
285 |
+
//
|
286 |
+
// return $file_list;
|
287 |
+
// }
|
288 |
+
|
289 |
+
public function get_job_meta($meta_name){
|
290 |
+
$this->logger->log_info(__METHOD__,'Begin - Update file list:' .$this->job_id .'-'. $meta_name);
|
291 |
+
|
292 |
+
return get_post_meta($this->job_id,$meta_name,true);
|
293 |
+
|
294 |
+
}
|
295 |
+
|
296 |
/**
|
297 |
* Set job status to active
|
298 |
*/
|
586 |
$job_id = wp_insert_post($new_job );
|
587 |
$logger->log_info(__METHOD__,'Job Created:' .$job_id);
|
588 |
|
|
|
589 |
switch ($job_name) {
|
590 |
+
case "restore":
|
591 |
+
//add the tasks
|
592 |
+
if ( false === self::create_tasks( $job_id,self::$restore_tasks ) ) {
|
593 |
+
$logger->log_info( __METHOD__, 'Restore tasks not Created - deleting job:' . $job_id );
|
594 |
+
wp_delete_post( $job_id, true );
|
595 |
+
return false;
|
596 |
+
}
|
597 |
+
|
598 |
+
break;
|
599 |
+
|
600 |
case "backup":
|
601 |
//add the tasks
|
602 |
+
if ( false === self::create_tasks( $job_id,self::$backup_tasks ) ) {
|
603 |
$logger->log_info( __METHOD__, 'Backup tasks not Created - deleting job:' . $job_id );
|
604 |
wp_delete_post( $job_id, true );
|
605 |
return false;
|
609 |
|
610 |
case "cleanup":
|
611 |
//add the tasks
|
612 |
+
if ( false === self::create_tasks( $job_id,self::$cleanup_tasks ) ) {
|
613 |
$logger->log_info( __METHOD__, 'Cleanup tasks not Created - deleting job:' . $job_id );
|
614 |
wp_delete_post( $job_id, true );
|
615 |
return false;
|
628 |
|
629 |
/**
|
630 |
* Create all the tasks for a job
|
|
|
631 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
* @param $job_id
|
633 |
*
|
634 |
+
* @param $tasks
|
635 |
+
*
|
636 |
* @return bool
|
637 |
*/
|
638 |
+
private static function create_tasks($job_id, $tasks){
|
639 |
$logger = new WPBackItUp_Logger(false,null,'debug_job');
|
640 |
$logger->log_info(__METHOD__,'Begin');
|
641 |
|
642 |
//Create the job tasks
|
643 |
$last_updated_time=time();
|
644 |
+
foreach ($tasks as $key => $value){
|
645 |
$task_name = $value;
|
646 |
$task_data = array(
|
647 |
'task_id' => $task_name,
|
655 |
$logger->log_error( __METHOD__, 'Tasks NOT created');
|
656 |
return false;
|
657 |
}
|
658 |
+
$logger->log_info( __METHOD__, 'task created:' . $task_created .':'. $task_name);
|
659 |
}
|
660 |
|
661 |
$logger->log_info(__METHOD__,'End');
|
663 |
|
664 |
}
|
665 |
|
666 |
+
// /**
|
667 |
+
// * Create all the tasks for a job
|
668 |
+
// * @param $job_id
|
669 |
+
// *
|
670 |
+
// * @return bool
|
671 |
+
// */
|
672 |
+
// private static function create_backup_tasks($job_id){
|
673 |
+
// $logger = new WPBackItUp_Logger(false,null,'debug_job');
|
674 |
+
// $logger->log_info(__METHOD__,'Begin');
|
675 |
+
//
|
676 |
+
// //Create the job tasks
|
677 |
+
// $last_updated_time=time();
|
678 |
+
// foreach (self::$backup_tasks as $key => $value){
|
679 |
+
// $task_name = $value;
|
680 |
+
// $task_data = array(
|
681 |
+
// 'task_id' => $task_name,
|
682 |
+
// 'task_status' => 'queued',
|
683 |
+
// 'task_allocated_id'=>'',
|
684 |
+
// 'task_last_updated'=>$last_updated_time
|
685 |
+
// );
|
686 |
+
// $task_created = update_post_meta( $job_id, $task_name, $task_data );
|
687 |
+
//
|
688 |
+
// if (false===$task_created){
|
689 |
+
// $logger->log_error( __METHOD__, 'Tasks NOT created');
|
690 |
+
// return false;
|
691 |
+
// }
|
692 |
+
// $logger->log_info( __METHOD__, 'task created:' . $task_created .':'. $task_name);
|
693 |
+
// }
|
694 |
+
//
|
695 |
+
// $logger->log_info(__METHOD__,'End');
|
696 |
+
// return true;
|
697 |
+
//
|
698 |
+
// }
|
699 |
+
|
700 |
+
// /**
|
701 |
+
// * Create all the tasks for a job
|
702 |
+
// * @param $job_id
|
703 |
+
// *
|
704 |
+
// * @return bool
|
705 |
+
// */
|
706 |
+
// private static function create_cleanup_tasks($job_id){
|
707 |
+
// $logger = new WPBackItUp_Logger(false,null,'debug_job');
|
708 |
+
// $logger->log_info(__METHOD__,'Begin');
|
709 |
+
//
|
710 |
+
// //Create the job tasks
|
711 |
+
// $last_updated_time=time();
|
712 |
+
// foreach (self::$cleanup_tasks as $key => $value){
|
713 |
+
// $task_name = $value;
|
714 |
+
// $task_data = array(
|
715 |
+
// 'task_id' => $task_name,
|
716 |
+
// 'task_status' => 'queued',
|
717 |
+
// 'task_allocated_id'=>'',
|
718 |
+
// 'task_last_updated'=>$last_updated_time
|
719 |
+
// );
|
720 |
+
// $task_created = update_post_meta( $job_id, $task_name, $task_data );
|
721 |
+
//
|
722 |
+
// if (false===$task_created){
|
723 |
+
// $logger->log_error( __METHOD__, 'Tasks NOT created');
|
724 |
+
// return false;
|
725 |
+
// }
|
726 |
+
// $logger->log_info( __METHOD__, 'task created:' . $task_created );
|
727 |
+
// }
|
728 |
+
//
|
729 |
+
// $logger->log_info(__METHOD__,'End');
|
730 |
+
// return true;
|
731 |
+
//
|
732 |
+
// }
|
733 |
+
|
734 |
/**
|
735 |
* @return mixed
|
736 |
*/
|
744 |
public function get_job_end_time() {
|
745 |
return $this->job_end_time;
|
746 |
}
|
747 |
+
|
748 |
+
/**
|
749 |
+
* Get Job status
|
750 |
+
* @return mixed
|
751 |
+
*/
|
752 |
+
public function get_job_status() {
|
753 |
+
return $this->job_status;
|
754 |
+
}
|
755 |
}
|
756 |
|
lib/includes/class-logger.php
CHANGED
@@ -114,6 +114,17 @@ class WPBackItUp_Logger {
|
|
114 |
}
|
115 |
}
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
function log_sysinfo() {
|
118 |
global $wpdb,$WPBackitup;
|
119 |
try{
|
114 |
}
|
115 |
}
|
116 |
|
117 |
+
//Log warning
|
118 |
+
public function log_warning($function,$message,$additional_message=null) {
|
119 |
+
$function='(' . $function . ') WARNING: ' . $additional_message;
|
120 |
+
if( is_array( $message ) || is_object( $message ) ){
|
121 |
+
$this->log($function);
|
122 |
+
$this->log($message);
|
123 |
+
} else {
|
124 |
+
$this->log($function .$message);
|
125 |
+
}
|
126 |
+
}
|
127 |
+
|
128 |
function log_sysinfo() {
|
129 |
global $wpdb,$WPBackitup;
|
130 |
try{
|
lib/includes/class-restore.php
CHANGED
@@ -12,17 +12,31 @@ class WPBackItUp_Restore {
|
|
12 |
private $logger;
|
13 |
|
14 |
//Public Properties
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
try {
|
22 |
$this->logger = $logger;
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
} catch(Exception $e) {
|
@@ -35,7 +49,1037 @@ class WPBackItUp_Restore {
|
|
35 |
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
}
|
12 |
private $logger;
|
13 |
|
14 |
//Public Properties
|
15 |
+
private $backup_id;
|
16 |
+
private $backup_name;
|
17 |
+
private $backup_folder_path;
|
18 |
+
private $restore_root_folder_path;
|
19 |
+
private $restore_staging_suffix;
|
20 |
|
21 |
+
const SITEDATAPATH = 'site-data';
|
22 |
+
const PLUGINSPATH = 'wp-content-plugins';
|
23 |
+
const THEMESPATH = 'wp-content-themes';
|
24 |
+
const OTHERPATH = 'wp-content-other';
|
25 |
+
const UPLOADPATH = 'wp-content-uploads';
|
26 |
+
|
27 |
+
function __construct($logger, $backup_name, $backup_id) {
|
28 |
+
//global $WPBackitup;
|
29 |
|
30 |
try {
|
31 |
$this->logger = $logger;
|
32 |
|
33 |
+
$this->backup_name=$backup_name;
|
34 |
+
$this->backup_folder_path = WPBACKITUP__BACKUP_PATH .'/' .$backup_name;
|
35 |
+
|
36 |
+
$this->restore_root_folder_path = WPBACKITUP__RESTORE_PATH;
|
37 |
+
|
38 |
+
$this->backup_id=$backup_id;
|
39 |
+
$this->restore_staging_suffix = '_' .$backup_id;
|
40 |
|
41 |
|
42 |
} catch(Exception $e) {
|
49 |
|
50 |
}
|
51 |
|
52 |
+
public function delete_restore_folder() {
|
53 |
+
$this->logger->log_info( __METHOD__, 'Begin delete restore folders.' );
|
54 |
+
|
55 |
+
//get a list of all the folders
|
56 |
+
$item_list = glob($this->restore_root_folder_path .'/*');
|
57 |
+
return $this->delete_folders($item_list);
|
58 |
+
}
|
59 |
+
|
60 |
+
public function delete_staged_folders() {
|
61 |
+
$this->logger->log_info( __METHOD__, 'Begin delete staged folders.' );
|
62 |
+
|
63 |
+
//get a list of all the staged folders
|
64 |
+
$item_list = glob(WPBACKITUP__CONTENT_PATH .'/*'.$this->restore_staging_suffix .'*');
|
65 |
+
return $this->delete_folders($item_list);
|
66 |
+
|
67 |
+
}
|
68 |
+
|
69 |
+
private function delete_folders($item_list) {
|
70 |
+
$this->logger->log_info( __METHOD__, 'Begin' );
|
71 |
+
|
72 |
+
$this->logger->log_info( __METHOD__, 'Folders to be deleted:' );
|
73 |
+
$this->logger->log($item_list);
|
74 |
+
|
75 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
76 |
+
foreach($item_list as $item) {
|
77 |
+
if (is_dir($item)) {
|
78 |
+
if (! $file_system->recursive_delete( $item )){
|
79 |
+
$this->logger->log_error( __METHOD__, 'Folder could NOT be deleted:' . $item);
|
80 |
+
return false;
|
81 |
+
}
|
82 |
+
}else{
|
83 |
+
if (! unlink($item)){
|
84 |
+
$this->logger->log_error( __METHOD__, 'File could NOT be deleted:' . $item);
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
$this->logger->log_info( __METHOD__, 'End' );
|
91 |
+
return true;
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
//Create an empty restore folder
|
96 |
+
public function create_restore_root_folder() {
|
97 |
+
$this->logger->log_info(__METHOD__,'Create restore folder.' . $this->restore_root_folder_path);
|
98 |
+
|
99 |
+
$fileSystem = new WPBackItUp_FileSystem($this->logger);
|
100 |
+
if( $fileSystem->create_dir($this->restore_root_folder_path)) {
|
101 |
+
//Secure restore folder
|
102 |
+
$fileSystem->secure_folder( $this->restore_root_folder_path);
|
103 |
+
return true;
|
104 |
+
|
105 |
+
} else{
|
106 |
+
return false;
|
107 |
+
}
|
108 |
+
|
109 |
+
}
|
110 |
+
|
111 |
+
//Unzip the backup to the restore folder
|
112 |
+
function unzip_archive_file($backup_set_list){
|
113 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
114 |
+
|
115 |
+
if (count($backup_set_list)<=0) return false;
|
116 |
+
|
117 |
+
$backup_file_path = $backup_set_list[0];
|
118 |
+
$this->logger->log_info(__METHOD__,'Begin - Unzip Backup File:' .$backup_file_path);
|
119 |
+
try {
|
120 |
+
$zip = new ZipArchive;
|
121 |
+
$res = $zip->open($backup_file_path);
|
122 |
+
if ($res === TRUE) {
|
123 |
+
if (true===$zip->extractTo($this->restore_root_folder_path)){
|
124 |
+
$zip->close();
|
125 |
+
} else {
|
126 |
+
$zip->close();
|
127 |
+
$this->logger->log_error(__METHOD__,'Cant unzip backup:'.$backup_file_path);
|
128 |
+
return false;
|
129 |
+
}
|
130 |
+
} else {
|
131 |
+
$this->logger->log_error(__METHOD__,'Cant open backup archive:'.$backup_file_path);
|
132 |
+
return false;
|
133 |
+
}
|
134 |
+
|
135 |
+
$this->logger->log_info(__METHOD__,'Backup file unzipped: ' .$backup_file_path);
|
136 |
+
|
137 |
+
} catch(Exception $e) {
|
138 |
+
$this->logger->log_error(__METHOD__,'An Unexpected Error has happened: ' .$e);
|
139 |
+
return false;
|
140 |
+
}
|
141 |
+
|
142 |
+
return true;
|
143 |
+
}
|
144 |
+
|
145 |
+
//Validate the restore folder
|
146 |
+
function validate_restore_folder(){
|
147 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
148 |
+
|
149 |
+
$restore_folder_root=$this->restore_root_folder_path . '/';
|
150 |
+
$this->logger->log_info(__METHOD__,'Validate restore folder : ' .$restore_folder_root);
|
151 |
+
|
152 |
+
|
153 |
+
//Do we have at least 4 folders - other may sometimes not be there
|
154 |
+
if ( count( glob( $restore_folder_root.'*', GLOB_ONLYDIR ) ) < 4 ) {
|
155 |
+
$this->logger->log_error(__METHOD__,'Restore directory INVALID: ' .$restore_folder_root);
|
156 |
+
return false;
|
157 |
+
}
|
158 |
+
|
159 |
+
|
160 |
+
$site_data_folder = $restore_folder_root .self::SITEDATAPATH;
|
161 |
+
if(!is_dir($site_data_folder) ){
|
162 |
+
$this->logger->log_error(__METHOD__,'site-data missing from restore folder:' .$site_data_folder);
|
163 |
+
return false;
|
164 |
+
}
|
165 |
+
|
166 |
+
$plugins_folder = $restore_folder_root .self::PLUGINSPATH;
|
167 |
+
if(!is_dir($plugins_folder) ){
|
168 |
+
$this->logger->log_error(__METHOD__,'wp-content-plugins missing from restore folder:' .$plugins_folder);
|
169 |
+
return false;
|
170 |
+
}
|
171 |
+
|
172 |
+
$themes_folder = $restore_folder_root .self::THEMESPATH;
|
173 |
+
if(!is_dir($themes_folder) ){
|
174 |
+
$this->logger->log_error(__METHOD__,'wp-content-themes missing from restore folder:' .$themes_folder);
|
175 |
+
return false;
|
176 |
+
}
|
177 |
+
|
178 |
+
//Not an error
|
179 |
+
$other_folder = $restore_folder_root .self::OTHERPATH;
|
180 |
+
if(!is_dir($other_folder) ){
|
181 |
+
$this->logger->log_info(__METHOD__,'wp-content-other missing from restore folder:' .$other_folder);
|
182 |
+
}
|
183 |
+
|
184 |
+
$uploads_folder = $restore_folder_root .self::UPLOADPATH;
|
185 |
+
if(!is_dir($uploads_folder) ){
|
186 |
+
$this->logger->log_error(__METHOD__,'wp-content-uploads missing from restore folder:' .$uploads_folder);
|
187 |
+
return false;
|
188 |
+
}
|
189 |
+
|
190 |
+
$this->logger->log_info(__METHOD__,'End - Restoration directory validated: ' .$restore_folder_root);
|
191 |
+
return true;
|
192 |
+
}
|
193 |
+
|
194 |
+
//Validate the restore folder
|
195 |
+
function validate_siteinfo_file(){
|
196 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
197 |
+
|
198 |
+
$site_info_path = $this->restore_root_folder_path . '/' .self::SITEDATAPATH .'/backupsiteinfo.txt';
|
199 |
+
$this->logger->log_info(__METHOD__,'Validate Site info file: ' . $site_info_path);
|
200 |
+
if(! file_exists($site_info_path) || empty($site_info_path)) {
|
201 |
+
$this->logger->log_error(__METHOD__,'backupsiteinfo.txt missing or empty ' .$site_info_path);
|
202 |
+
return false;
|
203 |
+
}
|
204 |
+
|
205 |
+
|
206 |
+
//Get file values
|
207 |
+
$this->logger->log_info(__METHOD__, 'GET Site Info data' );
|
208 |
+
$import_siteinfo_lines = file( $site_info_path);
|
209 |
+
if (count($import_siteinfo_lines)<3){
|
210 |
+
$this->logger->log_error(__METHOD__,'Site Data file NOT valid.' );
|
211 |
+
return false;
|
212 |
+
} else {
|
213 |
+
$restore_siteurl = str_replace( "\n", '', trim( $import_siteinfo_lines[0] ) );
|
214 |
+
$restore_table_prefix = str_replace( "\n", '', $import_siteinfo_lines[1] );
|
215 |
+
$restore_wp_version = str_replace( "\n", '', $import_siteinfo_lines[2] );
|
216 |
+
$restore_wpbackitup_version = str_replace( "\n", '', $import_siteinfo_lines[3] );
|
217 |
+
|
218 |
+
$site_data = array (
|
219 |
+
'restore_siteurl'=>$restore_siteurl,
|
220 |
+
'restore_table_prefix'=>$restore_table_prefix,
|
221 |
+
'restore_wp_version'=>$restore_wp_version,
|
222 |
+
'restore_wpbackitup_version'=>$restore_wpbackitup_version,
|
223 |
+
);
|
224 |
+
|
225 |
+
$this->logger->log_info(__METHOD__,'Site Data:' );
|
226 |
+
$this->logger->log($site_data);
|
227 |
+
return $site_data;
|
228 |
+
}
|
229 |
+
|
230 |
+
}
|
231 |
+
|
232 |
+
//Validate the manifest
|
233 |
+
function validate_manifest_file($backup_set_list, &$error_code){
|
234 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
235 |
+
|
236 |
+
$manifest_file_path = $this->restore_root_folder_path . '/' .self::SITEDATAPATH .'/backupmanifest.txt';
|
237 |
+
$this->logger->log_info(__METHOD__,'Validate backup manifest: ' . $manifest_file_path);
|
238 |
+
|
239 |
+
if(! file_exists($manifest_file_path) || empty($manifest_file_path)) {
|
240 |
+
$this->logger->log_info(__METHOD__,'No manifest found.');
|
241 |
+
return true; //Old backups will not have a manifest - OK
|
242 |
+
}
|
243 |
+
|
244 |
+
$manifest_data_string = file_get_contents($manifest_file_path);
|
245 |
+
if (false===$manifest_data_string || empty($manifest_data_string)){
|
246 |
+
$this->logger->log_error(__METHOD__,'Manifest empty.');
|
247 |
+
$error_code=1;
|
248 |
+
return false;
|
249 |
+
}
|
250 |
+
|
251 |
+
// make sure all the files in the manifest are part of the set
|
252 |
+
$manifest_data_array = json_decode($manifest_data_string,true);
|
253 |
+
foreach($manifest_data_array as $zip_file)
|
254 |
+
{
|
255 |
+
//does this file exist in the set
|
256 |
+
if (false===$this->search_array($zip_file, $backup_set_list)){
|
257 |
+
$this->logger->log_error(__METHOD__,'Zip File Missing:' .$zip_file);
|
258 |
+
$error_code=2;
|
259 |
+
return false;
|
260 |
+
}
|
261 |
+
}
|
262 |
+
|
263 |
+
// Do we have any extra zip files
|
264 |
+
foreach($backup_set_list as $zip_file)
|
265 |
+
{
|
266 |
+
//does this file exist in the manifest
|
267 |
+
if (false===$this->search_array(basename($zip_file), $manifest_data_array)){
|
268 |
+
$this->logger->log_error(__METHOD__,'Zip File Not in manifest:' .$zip_file);
|
269 |
+
$error_code=3;
|
270 |
+
return false;
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
$this->logger->log_info(__METHOD__,'End' );
|
275 |
+
return true;
|
276 |
+
|
277 |
+
}
|
278 |
+
|
279 |
+
private function search_array($search, $array)
|
280 |
+
{
|
281 |
+
foreach($array as $key => $value)
|
282 |
+
{
|
283 |
+
if (stristr($value, $search))
|
284 |
+
{
|
285 |
+
return $key;
|
286 |
+
}
|
287 |
+
}
|
288 |
+
return false;
|
289 |
+
}
|
290 |
+
|
291 |
+
//Make sure there IS a backup to restore
|
292 |
+
function validate_SQL_exists(){
|
293 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
294 |
+
|
295 |
+
$backup_sql_file = $this->restore_root_folder_path . '/' .self::SITEDATAPATH . '/' . WPBACKITUP__SQL_DBBACKUP_FILENAME;
|
296 |
+
$this->logger->log_info(__METHOD__,'Check for database backup file' . $backup_sql_file);
|
297 |
+
if(!file_exists($backup_sql_file) || empty($backup_sql_file)) {
|
298 |
+
$this->logger->log_error(__METHOD__,'Database backup file NOT FOUND.');
|
299 |
+
return false;
|
300 |
+
}
|
301 |
+
|
302 |
+
$this->logger->log_info(__METHOD__,'Database backup file exists');
|
303 |
+
return true;
|
304 |
+
}
|
305 |
+
|
306 |
+
public function export_database(){
|
307 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
308 |
+
|
309 |
+
$date = date_i18n('Y-m-d-Hi',current_time( 'timestamp' ));
|
310 |
+
$backup_file = $this->backup_folder_path .'/'. 'db-backup-' . $date .'.cur';
|
311 |
+
|
312 |
+
$sqlUtil = new WPBackItUp_SQL($this->logger);
|
313 |
+
$this->logger->log_info(__METHOD__,'Begin - Export Database: ' .$backup_file);
|
314 |
+
|
315 |
+
//Try SQLDump First
|
316 |
+
$this->logger->log_info(__METHOD__,'Export DB with MYSQLDUMP');
|
317 |
+
if(!$sqlUtil->mysqldump_export($backup_file) ) {
|
318 |
+
|
319 |
+
$this->logger->log_info(__METHOD__,'Export DB with MYSQLDUMP/PATH');
|
320 |
+
if(!$sqlUtil->mysqldump_export($backup_file,true) ) {
|
321 |
+
|
322 |
+
$this->logger->log_info(__METHOD__,'Export DB with Manual SQL EXPORT');
|
323 |
+
if(!$sqlUtil->manual_export($backup_file) ) {
|
324 |
+
$this->logger->log_error(__METHOD__,'SQL EXPORT FAILED');
|
325 |
+
return false;
|
326 |
+
}
|
327 |
+
}
|
328 |
+
}
|
329 |
+
$this->logger->log_info(__METHOD__,'Database Exported successfully');
|
330 |
+
|
331 |
+
return true;
|
332 |
+
}
|
333 |
+
|
334 |
+
|
335 |
+
public function rename_folder($from_folder_name,$to_folder_name){
|
336 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
337 |
+
$this->logger->log_info(__METHOD__,'Rename from folder name:' . $from_folder_name);
|
338 |
+
$this->logger->log_info(__METHOD__,'Rename to folder name: '. $to_folder_name);
|
339 |
+
|
340 |
+
$file_system = new WPBackItUp_FileSystem($this->logger);
|
341 |
+
if ( !$file_system->rename_file($from_folder_name,$to_folder_name)) {
|
342 |
+
$this->logger->log_error(__METHOD__,'Folder could not be renamed');
|
343 |
+
return false;
|
344 |
+
}
|
345 |
+
|
346 |
+
$this->logger->log_info(__METHOD__,'End');
|
347 |
+
|
348 |
+
return true;
|
349 |
+
}
|
350 |
+
|
351 |
+
// Restore everything but plugins
|
352 |
+
public function restore_wpcontent(){
|
353 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
354 |
+
$error_folders = array();
|
355 |
+
$error_files = array();
|
356 |
+
|
357 |
+
//Create the archive folder
|
358 |
+
$archive_folder = $this->restore_root_folder_path .'/Archive'.$this->restore_staging_suffix;
|
359 |
+
if (! is_dir($archive_folder)){
|
360 |
+
mkdir($archive_folder);
|
361 |
+
}
|
362 |
+
|
363 |
+
//Get all staged directories and rename them
|
364 |
+
//Plugins, backup & restore folders wereent staged
|
365 |
+
$wpcontent_folder_list = glob(WPBACKITUP__CONTENT_PATH .'/*'.$this->restore_staging_suffix ,GLOB_ONLYDIR);
|
366 |
+
foreach ( $wpcontent_folder_list as $from_folder_name ) {
|
367 |
+
|
368 |
+
$folder_name_only = basename( $from_folder_name );
|
369 |
+
$this->logger->log_info(__METHOD__,'Folder name:' . $folder_name_only);
|
370 |
+
|
371 |
+
$to_folder_name = WPBACKITUP__CONTENT_PATH . '/' . str_replace( $this->restore_staging_suffix, '', $folder_name_only );
|
372 |
+
|
373 |
+
//rename the existing folder to OLD if exists
|
374 |
+
$archive_success=true;
|
375 |
+
if (is_dir($to_folder_name)){
|
376 |
+
//try to rename it 5 times
|
377 |
+
$archive_folder_name = $archive_folder .'/' .str_replace( $this->restore_staging_suffix, '', $folder_name_only );
|
378 |
+
for ($i = 1; $i <= 5; $i++) {
|
379 |
+
$this->logger->log_info(__METHOD__,'Archive attempt:' . $i);
|
380 |
+
if ( $this->rename_folder($to_folder_name,$archive_folder_name)) {
|
381 |
+
$archive_success=true;
|
382 |
+
break; // break out if rename successful
|
383 |
+
}else{
|
384 |
+
$archive_success=false;
|
385 |
+
sleep(1); //give it a second
|
386 |
+
}
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
$rename_success=false;
|
391 |
+
//Rename the staged folder
|
392 |
+
if ($archive_success) {
|
393 |
+
for ($i = 1; $i <= 5; $i++) {
|
394 |
+
$this->logger->log_info(__METHOD__,'Restore attempt:' . $i);
|
395 |
+
if ( $this->rename_folder( $from_folder_name, $to_folder_name ) ) {
|
396 |
+
$rename_success=true;
|
397 |
+
break; // break out if rename successful
|
398 |
+
}else{
|
399 |
+
$rename_success=false;
|
400 |
+
sleep(1); //give it a second
|
401 |
+
}
|
402 |
+
}
|
403 |
+
}
|
404 |
+
|
405 |
+
//keep going on failure
|
406 |
+
if (! $rename_success){
|
407 |
+
array_push($error_folders,$from_folder_name);
|
408 |
+
$this->logger->log_error(__METHOD__, 'Cant restore folder.' .$from_folder_name );
|
409 |
+
}
|
410 |
+
}
|
411 |
+
|
412 |
+
|
413 |
+
if (count($error_folders)>0){
|
414 |
+
$this->logger->log_error(__METHOD__,'End - Error Folders:');
|
415 |
+
$this->logger->log($error_folders);
|
416 |
+
return $error_folders;
|
417 |
+
}
|
418 |
+
|
419 |
+
$this->logger->log_info(__METHOD__,'End Restont WPContent Folders- No errors');
|
420 |
+
|
421 |
+
//NOW restore the files
|
422 |
+
$wpcontent_files_only = array_filter(glob($this->restore_root_folder_path .'/' .self::OTHERPATH .'/*'), 'is_file');
|
423 |
+
foreach ( $wpcontent_files_only as $from_file_name ) {
|
424 |
+
$file_name_only = basename( $from_file_name );
|
425 |
+
|
426 |
+
$this->logger->log_info(__METHOD__,'WPContent File name:' . $file_name_only);
|
427 |
+
|
428 |
+
//Archive the old file
|
429 |
+
$to_file_name = WPBACKITUP__CONTENT_PATH .'/' . $file_name_only;
|
430 |
+
$archive_success=true;
|
431 |
+
if (file_exists($to_file_name)){
|
432 |
+
|
433 |
+
//try to rename it 5 times
|
434 |
+
$archive_file_name = $archive_folder .'/' . $file_name_only;
|
435 |
+
for ($i = 1; $i <= 5; $i++) {
|
436 |
+
$this->logger->log_info(__METHOD__,'Archive attempt:' . $i);
|
437 |
+
if ( $this->rename_folder($to_file_name,$archive_file_name)) {
|
438 |
+
$archive_success=true;
|
439 |
+
break; // break out if rename successful
|
440 |
+
}else{
|
441 |
+
$archive_success=false;
|
442 |
+
sleep(1); //give it a second
|
443 |
+
}
|
444 |
+
}
|
445 |
+
}
|
446 |
+
|
447 |
+
$rename_success=false;
|
448 |
+
if ($archive_success){
|
449 |
+
//Restore the file
|
450 |
+
for ($i = 1; $i <= 5; $i++) {
|
451 |
+
$this->logger->log_info(__METHOD__,'Restore attempt:' . $i);
|
452 |
+
if ( $this->rename_folder( $from_file_name, $to_file_name ) ) {
|
453 |
+
$rename_success=true;
|
454 |
+
break; // break out if rename successful
|
455 |
+
}else{
|
456 |
+
$rename_success=false;
|
457 |
+
sleep(1); //give it a second
|
458 |
+
}
|
459 |
+
}
|
460 |
+
|
461 |
+
}
|
462 |
+
|
463 |
+
//keep going on failure but add file to list
|
464 |
+
if (!$rename_success){
|
465 |
+
array_push($error_files,$from_folder_name);
|
466 |
+
$this->logger->log_error(__METHOD__, 'Cant restore file.' .$from_file_name );
|
467 |
+
|
468 |
+
}
|
469 |
+
}
|
470 |
+
|
471 |
+
|
472 |
+
if (count($error_files)>0) {
|
473 |
+
$this->logger->log_error(__METHOD__,'End - Error Files:');
|
474 |
+
$this->logger->log($error_files);
|
475 |
+
return $error_folders;
|
476 |
+
} else{
|
477 |
+
$this->logger->log_info(__METHOD__,'End Restore WPContent - No errors');
|
478 |
+
return true;
|
479 |
+
}
|
480 |
+
|
481 |
+
}
|
482 |
+
|
483 |
+
public function restore_plugins(){
|
484 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
485 |
+
$error_folders = array();
|
486 |
+
$error_files = array();
|
487 |
+
|
488 |
+
//Create the archive folder if it doesnt exist
|
489 |
+
$archive_folder = $this->restore_root_folder_path .'/Archive'.$this->restore_staging_suffix;
|
490 |
+
if (! is_dir($archive_folder)){
|
491 |
+
mkdir($archive_folder);
|
492 |
+
}
|
493 |
+
|
494 |
+
//Create the plugins archive
|
495 |
+
$plugin_archive_folder = $archive_folder .'/' . basename(WPBACKITUP__PLUGINS_ROOT_PATH);
|
496 |
+
if (! is_dir($plugin_archive_folder)){
|
497 |
+
mkdir($plugin_archive_folder);
|
498 |
+
}
|
499 |
+
|
500 |
+
|
501 |
+
//Move the folders ONLY
|
502 |
+
$plugins_folder_list = glob($this->restore_root_folder_path .'/' .self::PLUGINSPATH .'/*' ,GLOB_ONLYDIR);
|
503 |
+
foreach ( $plugins_folder_list as $from_folder_name ) {
|
504 |
+
$folder_name_only = basename( $from_folder_name );
|
505 |
+
|
506 |
+
//Dont restore wp backitup plugin
|
507 |
+
$this->logger->log_info(__METHOD__,'Plugin Folder name:' . $folder_name_only);
|
508 |
+
if ( $folder_name_only != WPBACKITUP__PLUGIN_FOLDER) {
|
509 |
+
|
510 |
+
//Archive the old plugin
|
511 |
+
$to_folder_name = WPBACKITUP__PLUGINS_ROOT_PATH .'/' . $folder_name_only;
|
512 |
+
$archive_success=true;
|
513 |
+
if (is_dir($to_folder_name)){
|
514 |
+
|
515 |
+
//try to rename it 5 times
|
516 |
+
$archive_folder_name = $plugin_archive_folder .'/' . $folder_name_only;
|
517 |
+
for ($i = 1; $i <= 5; $i++) {
|
518 |
+
$this->logger->log_info(__METHOD__,'Archive attempt:' . $i);
|
519 |
+
if ( $this->rename_folder($to_folder_name,$archive_folder_name)) {
|
520 |
+
$archive_success=true;
|
521 |
+
break; // break out if rename successful
|
522 |
+
}else{
|
523 |
+
$archive_success=false;
|
524 |
+
sleep(1); //give it a second
|
525 |
+
}
|
526 |
+
}
|
527 |
+
}
|
528 |
+
|
529 |
+
$rename_success=false;
|
530 |
+
if ($archive_success){
|
531 |
+
//Restore the plugin
|
532 |
+
for ($i = 1; $i <= 5; $i++) {
|
533 |
+
$this->logger->log_info(__METHOD__,'Restore attempt:' . $i);
|
534 |
+
if ( $this->rename_folder( $from_folder_name, $to_folder_name ) ) {
|
535 |
+
$rename_success=true;
|
536 |
+
break; // break out if rename successful
|
537 |
+
}else{
|
538 |
+
$rename_success=false;
|
539 |
+
sleep(1); //give it a second
|
540 |
+
}
|
541 |
+
}
|
542 |
+
|
543 |
+
}
|
544 |
+
|
545 |
+
//keep going on failure but add folder to list
|
546 |
+
if (!$rename_success){
|
547 |
+
array_push($error_folders,$from_folder_name);
|
548 |
+
$this->logger->log_error(__METHOD__, 'Cant restore plugin folder.' .$from_folder_name );
|
549 |
+
}
|
550 |
+
}
|
551 |
+
}
|
552 |
+
|
553 |
+
|
554 |
+
//If error on folders then return
|
555 |
+
if (count($error_folders)>0){
|
556 |
+
$this->logger->log_error(__METHOD__,'End - Error Folders:');
|
557 |
+
$this->logger->log($error_folders);
|
558 |
+
return $error_folders;
|
559 |
+
}
|
560 |
+
$this->logger->log_info(__METHOD__, 'End restore plugin folders.');
|
561 |
+
|
562 |
+
|
563 |
+
//NOW move the files
|
564 |
+
$plugins_files_only = array_filter(glob($this->restore_root_folder_path .'/' .self::PLUGINSPATH .'/*'), 'is_file');
|
565 |
+
foreach ( $plugins_files_only as $from_file_name ) {
|
566 |
+
$file_name_only = basename( $from_file_name );
|
567 |
+
|
568 |
+
$this->logger->log_info(__METHOD__,'Plugin File name:' . $file_name_only);
|
569 |
+
|
570 |
+
//Archive the old file
|
571 |
+
$to_file_name = WPBACKITUP__PLUGINS_ROOT_PATH .'/' . $file_name_only;
|
572 |
+
$archive_success=true;
|
573 |
+
if (file_exists($to_file_name)){
|
574 |
+
|
575 |
+
//try to rename it 5 times
|
576 |
+
$archive_file_name = $plugin_archive_folder .'/' . $file_name_only;
|
577 |
+
for ($i = 1; $i <= 5; $i++) {
|
578 |
+
$this->logger->log_info(__METHOD__,'Archive attempt:' . $i);
|
579 |
+
if ( $this->rename_folder($to_file_name,$archive_file_name)) {
|
580 |
+
$archive_success=true;
|
581 |
+
break; // break out if rename successful
|
582 |
+
}else{
|
583 |
+
$archive_success=false;
|
584 |
+
sleep(1); //give it a second
|
585 |
+
}
|
586 |
+
}
|
587 |
+
}
|
588 |
+
|
589 |
+
$rename_success=false;
|
590 |
+
if ($archive_success){
|
591 |
+
//Restore the plugin
|
592 |
+
for ($i = 1; $i <= 5; $i++) {
|
593 |
+
$this->logger->log_info(__METHOD__,'Restore attempt:' . $i);
|
594 |
+
if ( $this->rename_folder( $from_file_name, $to_file_name ) ) {
|
595 |
+
$rename_success=true;
|
596 |
+
break; // break out if rename successful
|
597 |
+
}else{
|
598 |
+
$rename_success=false;
|
599 |
+
sleep(1); //give it a second
|
600 |
+
}
|
601 |
+
}
|
602 |
+
|
603 |
+
}
|
604 |
+
|
605 |
+
//keep going on failure but add file to list
|
606 |
+
if (!$rename_success){
|
607 |
+
array_push($error_files,$from_folder_name);
|
608 |
+
$this->logger->log_error(__METHOD__, 'Cant restore plugin file.' .$from_file_name );
|
609 |
+
|
610 |
+
}
|
611 |
+
}
|
612 |
+
|
613 |
+
|
614 |
+
if (count($error_files)>0) {
|
615 |
+
$this->logger->log_error(__METHOD__,'End - Error Files:');
|
616 |
+
$this->logger->log($error_files);
|
617 |
+
return $error_folders;
|
618 |
+
} else{
|
619 |
+
$this->logger->log_info(__METHOD__,'End Restore Plugins - No errors');
|
620 |
+
return true;
|
621 |
+
}
|
622 |
+
|
623 |
+
|
624 |
+
}
|
625 |
+
|
626 |
+
public function restore_database(){
|
627 |
+
$this->logger->log_info(__METHOD__,'Begin - restore database.');
|
628 |
+
|
629 |
+
$backup_sql_file = $this->restore_root_folder_path . '/' .self::SITEDATAPATH . '/' . WPBACKITUP__SQL_DBBACKUP_FILENAME;
|
630 |
+
return $this->run_sql_from_file($backup_sql_file);
|
631 |
+
|
632 |
+
}
|
633 |
+
|
634 |
+
private function run_sql_from_file($sql_file_path){
|
635 |
+
$this->logger->log_info(__METHOD__,'Begin - SQL: '. $sql_file_path);
|
636 |
+
|
637 |
+
|
638 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
639 |
+
if(!$dbc->run_sql_exec($sql_file_path)) {
|
640 |
+
//try with sql path on this time
|
641 |
+
if(!$dbc->run_sql_exec($sql_file_path,true)) {
|
642 |
+
//Try manually
|
643 |
+
if ( ! $dbc->run_sql_manual( $sql_file_path ) ) {
|
644 |
+
$this->logger->log_error( __METHOD__, 'Database import error.' );
|
645 |
+
return false;
|
646 |
+
}
|
647 |
+
}
|
648 |
+
}
|
649 |
+
|
650 |
+
$this->logger->log_info(__METHOD__,'End');
|
651 |
+
return true;
|
652 |
+
}
|
653 |
+
|
654 |
+
public function activate_plugins(){
|
655 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
656 |
+
|
657 |
+
$plugins = get_plugins();
|
658 |
+
foreach ( $plugins as $plugin => $value ) {
|
659 |
+
//Activate plugin if NOT already active
|
660 |
+
if (! is_plugin_active($plugin) ) {
|
661 |
+
$result = activate_plugin($plugin);
|
662 |
+
if ( is_wp_error( $result ) ) {
|
663 |
+
$this->logger->log_error(__METHOD__,'Plugin could NOT be activated:' .$plugin);
|
664 |
+
} else{
|
665 |
+
$this->logger->log_info(__METHOD__,'Plugin activated:' .$plugin);
|
666 |
+
}
|
667 |
+
}
|
668 |
+
}
|
669 |
+
|
670 |
+
$this->logger->log_info(__METHOD__,'End');
|
671 |
+
return true;
|
672 |
+
}
|
673 |
+
|
674 |
+
public function deactivate_plugins(){
|
675 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
676 |
+
|
677 |
+
$plugins = get_option('active_plugins');
|
678 |
+
foreach ($plugins as $plugin) {
|
679 |
+
//dont deactivate wp-backitup
|
680 |
+
if ('wp-backitup/wp-backitup.php' != $plugin){
|
681 |
+
deactivate_plugins($plugin);
|
682 |
+
$this->logger->log_info(__METHOD__,'Plugin Deactivated:' . $plugin);
|
683 |
+
}
|
684 |
+
}
|
685 |
+
|
686 |
+
$this->logger->log_info(__METHOD__,'End');
|
687 |
+
}
|
688 |
+
|
689 |
+
//get siteurl
|
690 |
+
public function get_siteurl(){
|
691 |
+
global $table_prefix;
|
692 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
693 |
+
|
694 |
+
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
|
695 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
696 |
+
$siteurl = $dbc->get_sql_scalar($sql);
|
697 |
+
if (empty($siteurl)) {
|
698 |
+
$this->logger->log_error(__METHOD__,'Siteurl not found');
|
699 |
+
return false;
|
700 |
+
}
|
701 |
+
|
702 |
+
$this->logger->log_info(__METHOD__,'End - Siteurl found:' .$siteurl);
|
703 |
+
return $siteurl;
|
704 |
+
}
|
705 |
+
|
706 |
+
//get homeurl
|
707 |
+
function get_homeurl(){
|
708 |
+
global $table_prefix;
|
709 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
710 |
+
|
711 |
+
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
|
712 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
713 |
+
$homeurl = $dbc->get_sql_scalar($sql);
|
714 |
+
if (empty($homeurl)) {
|
715 |
+
$this->logger->log_error(__METHOD__,' Homeurl not found.');
|
716 |
+
return false;
|
717 |
+
}
|
718 |
+
$this->logger->log_info(__METHOD__,'End - homeurl found:' . $homeurl);
|
719 |
+
return $homeurl;
|
720 |
+
}
|
721 |
+
|
722 |
+
//get user login
|
723 |
+
function get_user_login($user_id){
|
724 |
+
global $table_prefix;
|
725 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
726 |
+
|
727 |
+
$sql = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
728 |
+
|
729 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
730 |
+
$user_login = $dbc->get_sql_scalar($sql);
|
731 |
+
if (empty($user_login)) {
|
732 |
+
$this->logger->log_error(__METHOD__,'User_login not found.');
|
733 |
+
return false;
|
734 |
+
}
|
735 |
+
|
736 |
+
$this->logger->log_info(__METHOD__,'End - User_login found.');
|
737 |
+
return $user_login;
|
738 |
+
}
|
739 |
+
|
740 |
+
//get user pass
|
741 |
+
function get_user_pass($user_id){
|
742 |
+
global $table_prefix;
|
743 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
744 |
+
|
745 |
+
$sql = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
746 |
+
|
747 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
748 |
+
$user_pass = $dbc->get_sql_scalar($sql);
|
749 |
+
if (empty($user_pass)) {
|
750 |
+
$this->logger->log_error(__METHOD__,'User_pass not found.');
|
751 |
+
return false;
|
752 |
+
}
|
753 |
+
$this->logger->log_info(__METHOD__,'End - User_pass found.');
|
754 |
+
return $user_pass;
|
755 |
+
}
|
756 |
+
|
757 |
+
//get user email
|
758 |
+
function get_user_email($user_id){
|
759 |
+
global $table_prefix;
|
760 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
761 |
+
|
762 |
+
$sql = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
|
763 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
764 |
+
$user_email = $dbc->get_sql_scalar($sql);
|
765 |
+
if (empty($user_email)) {
|
766 |
+
$this->logger->log_error(__METHOD__,'User_email not found.');
|
767 |
+
return false;
|
768 |
+
}
|
769 |
+
$this->logger->log_info(__METHOD__,'End - User_email found.');
|
770 |
+
return $user_email;
|
771 |
+
}
|
772 |
+
|
773 |
+
|
774 |
+
//Update user credentials
|
775 |
+
function update_user_credentials($user_id, $user_login, $user_pass_hash, $user_email,$table_prefix){
|
776 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
777 |
+
|
778 |
+
//prefer SQL update because password hash is safer than plain text update
|
779 |
+
$sql = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass_hash ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
|
780 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
781 |
+
if (!$dbc->run_sql_command($sql)){
|
782 |
+
$this->logger->log_error(__METHOD__,'User Credential database update failed.');
|
783 |
+
return false;
|
784 |
+
}
|
785 |
+
$this->logger->log_info(__METHOD__,'End - User Credential updated in database.');
|
786 |
+
return true;
|
787 |
+
}
|
788 |
+
|
789 |
+
//Create user
|
790 |
+
function create_user_XXX($current_user){
|
791 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
792 |
+
|
793 |
+
$user_id = wp_insert_user( $current_user ) ;
|
794 |
+
if( is_wp_error($user_id) ) {
|
795 |
+
$this->logger->log_error(__METHOD__,'User was not created:' .$user_id->get_error_message());
|
796 |
+
return false;
|
797 |
+
}
|
798 |
+
|
799 |
+
$this->logger->log_info(__METHOD__,'End - New user created:' . $user_id);
|
800 |
+
return true;
|
801 |
+
}
|
802 |
+
|
803 |
+
|
804 |
+
//update credentials
|
805 |
+
function update_credentials($user_id, $user_full_name, $user_login, $user_pass_hash, $user_email,$table_prefix){
|
806 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
807 |
+
|
808 |
+
//prefer SQL update because password hash is safer than plain text update
|
809 |
+
|
810 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
811 |
+
|
812 |
+
//Fetch the user
|
813 |
+
$sql = "SELECT id from " . $table_prefix ."users where user_login = '" .$user_login ."'";
|
814 |
+
$query_result = $dbc->get_sql_scalar($sql);
|
815 |
+
$this->logger->log_info(__METHOD__,'Fetch user by login:' .$query_result);
|
816 |
+
|
817 |
+
if (!empty($query_result)) {
|
818 |
+
$this->logger->log_info(__METHOD__,'Update User Credentials.');
|
819 |
+
//update the user
|
820 |
+
$sql = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass_hash ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
|
821 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
822 |
+
if (!$dbc->run_sql_command($sql)){
|
823 |
+
$this->logger->log_error(__METHOD__,'User Credential database update failed.');
|
824 |
+
return false;
|
825 |
+
}
|
826 |
+
$this->logger->log_info(__METHOD__,'End - User Credential updated in database.');
|
827 |
+
return true;
|
828 |
+
|
829 |
+
|
830 |
+
} else {
|
831 |
+
$this->logger->log_info(__METHOD__,'Create User Credentials.');
|
832 |
+
//Create the user
|
833 |
+
$sql = "INSERT INTO ". $table_prefix ."users (user_login, user_nicename, display_name, user_pass, user_email, user_registered, user_status) values('" .$user_login ."','" .$user_full_name ."','" .$user_full_name ."','" .$user_pass_hash ."','" .$user_email ."', NOW() ,'0')";
|
834 |
+
if (!$dbc->run_sql_command($sql)){
|
835 |
+
$this->logger->log_error(__METHOD__,'User insert failed.');
|
836 |
+
return false;
|
837 |
+
}else{
|
838 |
+
$this->logger->log_info(__METHOD__,'User inserted in database successfully.');
|
839 |
+
}
|
840 |
+
|
841 |
+
//Get the new user ID
|
842 |
+
$sql = "SELECT id from " . $table_prefix ."users where user_login = '" .$user_login ."'";
|
843 |
+
$user_id = $dbc->get_sql_scalar($sql);
|
844 |
+
$this->logger->log_info(__METHOD__,'Fetch user by id:' .$user_id);
|
845 |
+
|
846 |
+
$sql = "INSERT INTO ". $table_prefix ."usermeta (user_id, meta_key, meta_value) values(" .$user_id .",'wp_capabilities', 'a:1:{s:13:\"administrator\";s:1:\"1\";}')";
|
847 |
+
if (!$dbc->run_sql_command($sql)){
|
848 |
+
$this->logger->log_error(__METHOD__,'user capabilities insert failed.');
|
849 |
+
return false;
|
850 |
+
}else {
|
851 |
+
$this->logger->log_info(__METHOD__,'User capabilities inserted successfully.');
|
852 |
+
}
|
853 |
+
|
854 |
+
$sql = "INSERT INTO ". $table_prefix ."usermeta (user_id, meta_key, meta_value) values(" .$user_id .",'wp_user_level', '10')";
|
855 |
+
if (!$dbc->run_sql_command($sql)){
|
856 |
+
$this->logger->log_error(__METHOD__,'User level insert failed');
|
857 |
+
return false;
|
858 |
+
}else{
|
859 |
+
$this->logger->log_info(__METHOD__,'User level inserted successfully.');
|
860 |
+
}
|
861 |
+
|
862 |
+
$this->logger->log_info(__METHOD__,'End - User created in database successfully.');
|
863 |
+
return true;
|
864 |
+
}
|
865 |
+
|
866 |
+
}
|
867 |
+
|
868 |
+
//update the site URL in the restored database
|
869 |
+
function update_siteurl($table_prefix, $current_siteurl){
|
870 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
871 |
+
|
872 |
+
$sql = "UPDATE ". $table_prefix ."options SET option_value='" .$current_siteurl ."' WHERE option_name='siteurl'";
|
873 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
874 |
+
if (!$dbc->run_sql_command($sql)){
|
875 |
+
$this->logger->log('Error: SiteURL updated failed.');
|
876 |
+
return false;
|
877 |
+
}
|
878 |
+
$this->logger->log_info(__METHOD__,'End - SiteURL updated in database:' .$current_siteurl);
|
879 |
+
return true;
|
880 |
+
}
|
881 |
+
|
882 |
+
//Update homeURL
|
883 |
+
function update_homeurl($table_prefix, $homeurl){
|
884 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
885 |
+
|
886 |
+
$sql = "UPDATE ". $table_prefix ."options SET option_value='" .$homeurl ."' WHERE option_name='home'";
|
887 |
+
$dbc = new WPBackItUp_SQL($this->logger);
|
888 |
+
if (!$dbc->run_sql_command($sql)){
|
889 |
+
$this->logger->log(__METHOD__,'HomeURL database update failed..');
|
890 |
+
return false;
|
891 |
+
}
|
892 |
+
$this->logger->log_info(__METHOD__,'End - HomeURL updated in database:'.$homeurl);
|
893 |
+
return true;
|
894 |
+
}
|
895 |
+
|
896 |
+
function update_permalinks(){
|
897 |
+
global $wp_rewrite;
|
898 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
899 |
+
|
900 |
+
try {
|
901 |
+
$wp_rewrite->flush_rules( true );//Update permalinks - hard flush
|
902 |
+
|
903 |
+
}catch(Exception $e) {
|
904 |
+
$this->logger->log_error(__METHOD__,'Exception: ' .$e);
|
905 |
+
return false;
|
906 |
+
}
|
907 |
+
$this->logger->log_info(__METHOD__,'End - Permalinks updated.');
|
908 |
+
return true;
|
909 |
+
}
|
910 |
+
|
911 |
+
public function zip_logs(){
|
912 |
+
$this->logger->log_info(__METHOD__,'Begin');
|
913 |
+
|
914 |
+
//Zip up all the logs in the log folder
|
915 |
+
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
916 |
+
$zip_file_path = $logs_path .'/Restore_Logs_' .$this->backup_id . '.zip';
|
917 |
+
|
918 |
+
//copy/replace WP debug file
|
919 |
+
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
920 |
+
$this->logger->log_info(__METHOD__,"Copy WP Debug: " .$wpdebug_file_path);
|
921 |
+
if (file_exists($wpdebug_file_path)) {
|
922 |
+
copy( $wpdebug_file_path, $logs_path .'/wpdebug.log' );
|
923 |
+
}
|
924 |
+
|
925 |
+
$zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
|
926 |
+
$zip->zip_files_in_folder($logs_path,$this->backup_id,'*.log');
|
927 |
+
$zip->close();
|
928 |
+
|
929 |
+
$this->logger->log_info(__METHOD__,'End');
|
930 |
+
|
931 |
+
return $zip_file_path;
|
932 |
+
|
933 |
+
}
|
934 |
+
|
935 |
+
function send_notification_email($err, $success,$logs=array(),$notification_email) {
|
936 |
+
global $logger,$status_array,$backup_job;
|
937 |
+
$logger->log_info(__METHOD__,"Begin");
|
938 |
+
|
939 |
+
$utility = new WPBackItUp_Utility($logger);
|
940 |
+
|
941 |
+
if($success)
|
942 |
+
{
|
943 |
+
//Don't send logs on success unless debug is on.
|
944 |
+
if (WPBACKITUP__DEBUG!==true){
|
945 |
+
$logs=array();
|
946 |
+
}
|
947 |
+
|
948 |
+
$subject = get_bloginfo() . ' - Restore completed successfully.';
|
949 |
+
$message = '<b>Your site was restored successfully.</b><br/><br/>';
|
950 |
+
|
951 |
+
} else {
|
952 |
+
$subject = get_bloginfo() .' - Backup did not complete successfully.';
|
953 |
+
$message = '<b>Your restore did not complete successfully.</b><br/><br/>';
|
954 |
+
}
|
955 |
+
|
956 |
+
$local_datetime = get_date_from_gmt(date( 'Y-m-d H:i:s',current_time( 'timestamp' )));
|
957 |
+
$message .= 'WordPress Site: <a href="' . home_url() . '" target="_blank">' . home_url() .'</a><br/>';
|
958 |
+
$message .= 'Restore date: ' . $local_datetime . '<br/>';
|
959 |
+
|
960 |
+
//$message .= 'Completion Code: ' . $backup_job->backup_id .'-'. $processing_minutes .'-' .$processing_seconds .'<br/>';
|
961 |
+
$message .= 'WP BackItUp Version: ' . WPBACKITUP__VERSION . '<br/>';
|
962 |
+
$message .= '<br/>';
|
963 |
+
|
964 |
+
|
965 |
+
//Add the completed steps on success
|
966 |
+
// if($success) {
|
967 |
+
// $message .='<b>Steps Completed</b><br/>';
|
968 |
+
//
|
969 |
+
// //Add the completed statuses
|
970 |
+
// foreach ($status_array as $status_key => $status_value) {
|
971 |
+
// if ($status_value==2) {
|
972 |
+
// foreach ($status_description as $msg_key => $msg_value) {
|
973 |
+
// if ($status_key==$msg_key) {
|
974 |
+
// $message .= $msg_value . '<br/>';
|
975 |
+
// break;
|
976 |
+
// }
|
977 |
+
// }
|
978 |
+
// }
|
979 |
+
// }
|
980 |
+
// } else {
|
981 |
+
// //Error occurred
|
982 |
+
// $message .= '<br/>';
|
983 |
+
// $message .= 'Errors:<br/>' . get_error_message($err);
|
984 |
+
// }
|
985 |
+
|
986 |
+
// $term='success';
|
987 |
+
// if(!$success)$term='error';
|
988 |
+
// $message .='<br/><br/>Checkout '. $WPBackitup->get_anchor_with_utm('www.wpbackitup.com', '', 'notification+email', $term) .' for info about WP BackItUp and our other products.<br/>';
|
989 |
+
|
990 |
+
|
991 |
+
if($notification_email)
|
992 |
+
$utility->send_email($notification_email,$subject,$message,$logs);
|
993 |
+
|
994 |
+
$logger->log_info(__METHOD__,"End");
|
995 |
+
}
|
996 |
+
|
997 |
+
function save_process_status($process,$status){
|
998 |
+
$this->logger->log_info(__METHOD__,"Begin");
|
999 |
+
|
1000 |
+
//Write status to JSON file - cant use database because it will e restored
|
1001 |
+
$local_datetime = get_date_from_gmt(date( 'Y-m-d H:i:s',current_time( 'timestamp' )));
|
1002 |
+
$process_status = array(
|
1003 |
+
'status' => $status,
|
1004 |
+
'start_time'=>$local_datetime,
|
1005 |
+
'end_time' =>''
|
1006 |
+
);
|
1007 |
+
|
1008 |
+
$log_file_path = WPBACKITUP__PLUGIN_PATH .'logs/restore_' .$this->backup_id .'.log';
|
1009 |
+
$restore_status_string=false;
|
1010 |
+
if (file_exists($log_file_path)){
|
1011 |
+
$restore_status_string = file_get_contents($log_file_path);
|
1012 |
+
}
|
1013 |
+
|
1014 |
+
if (false===$restore_status_string || empty($restore_status_string)){
|
1015 |
+
$restore_status_array=array($process=>$process_status);
|
1016 |
+
} else{
|
1017 |
+
$restore_status_array = json_decode($restore_status_string,true);
|
1018 |
+
|
1019 |
+
//Does the process already exist
|
1020 |
+
if (! array_key_exists ($process,$restore_status_array)){
|
1021 |
+
//Add to existing array
|
1022 |
+
$restore_status_array[$process]=$process_status;
|
1023 |
+
}else{
|
1024 |
+
//update the end time
|
1025 |
+
$restore_status_array[$process]['end_time'] = $local_datetime;
|
1026 |
+
$restore_status_array[$process]['status'] = $status;
|
1027 |
+
}
|
1028 |
+
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
$restore_status_string = json_encode($restore_status_array);
|
1032 |
+
file_put_contents($log_file_path, $restore_status_string);
|
1033 |
+
|
1034 |
+
$this->logger->log_info(__METHOD__,"End");
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
|
1038 |
+
|
1039 |
+
|
1040 |
+
|
1041 |
+
/** GETTERS */
|
1042 |
+
|
1043 |
+
/**
|
1044 |
+
* @return string
|
1045 |
+
*/
|
1046 |
+
public function get_backup_folder_path() {
|
1047 |
+
return $this->backup_folder_path;
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
/**
|
1051 |
+
* @return string
|
1052 |
+
*/
|
1053 |
+
public function get_restore_root_folder_path() {
|
1054 |
+
return $this->restore_root_folder_path;
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
/**
|
1058 |
+
* @return string
|
1059 |
+
*/
|
1060 |
+
// public function get_restore_folder_path() {
|
1061 |
+
// return $this->restore_folder_path;
|
1062 |
+
// }
|
1063 |
+
|
1064 |
+
/**
|
1065 |
+
* @return mixed
|
1066 |
+
*/
|
1067 |
+
public function get_backup_name() {
|
1068 |
+
return $this->backup_name;
|
1069 |
+
}
|
1070 |
|
1071 |
+
/**
|
1072 |
+
* @return string
|
1073 |
+
*/
|
1074 |
+
public function get_restore_staging_suffix() {
|
1075 |
+
return $this->restore_staging_suffix;
|
1076 |
+
}
|
1077 |
|
1078 |
+
/**
|
1079 |
+
* @return mixed
|
1080 |
+
*/
|
1081 |
+
public function get_backup_id() {
|
1082 |
+
return $this->backup_id;
|
1083 |
+
}
|
1084 |
|
1085 |
}
|
lib/includes/class-sql.php
CHANGED
@@ -63,7 +63,9 @@ class WPBackItUp_SQL {
|
|
63 |
.=' ' . $db_name
|
64 |
. ' > "' . $sql_file_path .'"';
|
65 |
|
66 |
-
|
|
|
|
|
67 |
|
68 |
exec($command,$output,$rtn_var);
|
69 |
$this->logger->log('(SQL.mysqldump_export)Execute output:');
|
@@ -207,7 +209,7 @@ class WPBackItUp_SQL {
|
|
207 |
return true;
|
208 |
}
|
209 |
|
210 |
-
public function run_sql_exec($sql_file) {
|
211 |
$this->logger->log('(SQL.run_sql_exec)SQL Execute:' .$sql_file);
|
212 |
|
213 |
//Is the backup sql file empty
|
@@ -224,21 +226,36 @@ class WPBackItUp_SQL {
|
|
224 |
|
225 |
try {
|
226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
$db_name = DB_NAME;
|
228 |
$db_user = DB_USER;
|
229 |
$db_pass = DB_PASSWORD;
|
230 |
$db_host = $this->get_hostonly(DB_HOST);
|
231 |
$db_port = $this->get_portonly(DB_HOST);
|
232 |
|
233 |
-
$process = 'mysql';
|
234 |
$command = $process
|
235 |
-
. ' --host=' . $db_host
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
. ' --password=' . $db_pass
|
238 |
. ' --database=' . $db_name
|
239 |
. ' --execute="SOURCE ' . $sql_file .'"';
|
240 |
|
241 |
-
|
|
|
|
|
242 |
|
243 |
//$output = shell_exec($command);
|
244 |
exec($command,$output,$rtn_var);
|
@@ -248,6 +265,7 @@ class WPBackItUp_SQL {
|
|
248 |
|
249 |
//0 is success
|
250 |
if ($rtn_var!=0){
|
|
|
251 |
return false;
|
252 |
}
|
253 |
|
@@ -257,7 +275,7 @@ class WPBackItUp_SQL {
|
|
257 |
}
|
258 |
|
259 |
//Success
|
260 |
-
$this->logger->log('(SQL.run_sql_exec)SQL Executed successfully
|
261 |
return true;
|
262 |
}
|
263 |
|
63 |
.=' ' . $db_name
|
64 |
. ' > "' . $sql_file_path .'"';
|
65 |
|
66 |
+
if (WPBACKITUP__DEBUG) {
|
67 |
+
$this->logger->log('(SQL.db_SQLDump)Execute command:' . $command);
|
68 |
+
}
|
69 |
|
70 |
exec($command,$output,$rtn_var);
|
71 |
$this->logger->log('(SQL.mysqldump_export)Execute output:');
|
209 |
return true;
|
210 |
}
|
211 |
|
212 |
+
public function run_sql_exec($sql_file,$with_mysqlpath=false) {
|
213 |
$this->logger->log('(SQL.run_sql_exec)SQL Execute:' .$sql_file);
|
214 |
|
215 |
//Is the backup sql file empty
|
226 |
|
227 |
try {
|
228 |
|
229 |
+
$mysql_path='';
|
230 |
+
if ($with_mysqlpath) {
|
231 |
+
$mysql_path = $this->get_mysql_path();
|
232 |
+
if ($mysql_path===false) return false;
|
233 |
+
}
|
234 |
+
|
235 |
$db_name = DB_NAME;
|
236 |
$db_user = DB_USER;
|
237 |
$db_pass = DB_PASSWORD;
|
238 |
$db_host = $this->get_hostonly(DB_HOST);
|
239 |
$db_port = $this->get_portonly(DB_HOST);
|
240 |
|
241 |
+
$process = $mysql_path .'mysql';
|
242 |
$command = $process
|
243 |
+
. ' --host=' . $db_host;
|
244 |
+
|
245 |
+
//Check for port
|
246 |
+
if (false!==$db_port){
|
247 |
+
$command .=' --port=' . $db_port;
|
248 |
+
}
|
249 |
+
|
250 |
+
$command .=
|
251 |
+
' --user=' . $db_user
|
252 |
. ' --password=' . $db_pass
|
253 |
. ' --database=' . $db_name
|
254 |
. ' --execute="SOURCE ' . $sql_file .'"';
|
255 |
|
256 |
+
if (WPBACKITUP__DEBUG) {
|
257 |
+
$this->logger->log( '(SQL.db_run_sql)Execute command:' . $command );
|
258 |
+
}
|
259 |
|
260 |
//$output = shell_exec($command);
|
261 |
exec($command,$output,$rtn_var);
|
265 |
|
266 |
//0 is success
|
267 |
if ($rtn_var!=0){
|
268 |
+
$this->logger->log('(SQL.run_sql_exec) An Error has occurred RTNVAL: ' .$rtn_var);
|
269 |
return false;
|
270 |
}
|
271 |
|
275 |
}
|
276 |
|
277 |
//Success
|
278 |
+
$this->logger->log('(SQL.run_sql_exec)SQL Executed successfully');
|
279 |
return true;
|
280 |
}
|
281 |
|
lib/includes/class-utility.php
CHANGED
@@ -25,16 +25,21 @@ class WPBackItUp_Utility {
|
|
25 |
}
|
26 |
|
27 |
|
28 |
-
function send_email($to,$subject,$message,$attachments=array())
|
29 |
{
|
30 |
try {
|
31 |
//global $WPBackitup;
|
32 |
if($to) {
|
33 |
-
$from_email = get_bloginfo('admin_email');
|
34 |
-
$headers[] = 'Content-type: text/html';
|
35 |
-
$headers[] = 'From: WP BackItUp '. '<'. $from_email .'>';
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
$this->logger->log('(send_email)EMail Sent from:' .$from_email);
|
39 |
$this->logger->log('(send_email)EMail Sent to:' .$to);
|
40 |
}
|
25 |
}
|
26 |
|
27 |
|
28 |
+
function send_email($to,$subject,$message,$attachments=array(),$reply_email=null)
|
29 |
{
|
30 |
try {
|
31 |
//global $WPBackitup;
|
32 |
if($to) {
|
|
|
|
|
|
|
33 |
|
34 |
+
$from_email = get_bloginfo( 'admin_email' );
|
35 |
+
$headers[] = 'Content-type: text/html';
|
36 |
+
$headers[] = 'From: WP BackItUp <'. $from_email .'>';
|
37 |
+
|
38 |
+
if (null!=$reply_email) {
|
39 |
+
$headers[] = 'Reply-To: <'. $reply_email .'>';
|
40 |
+
}
|
41 |
+
|
42 |
+
wp_mail($to, $subject, nl2br($message), $headers,$attachments);
|
43 |
$this->logger->log('(send_email)EMail Sent from:' .$from_email);
|
44 |
$this->logger->log('(send_email)EMail Sent to:' .$to);
|
45 |
}
|
lib/includes/class-wpbackitup-admin.php
CHANGED
@@ -59,7 +59,8 @@ class WPBackitup_Admin {
|
|
59 |
'backup_schedule'=>"",
|
60 |
'backup_lastrun_date'=>"-2147483648",
|
61 |
'cleanup_lastrun_date'=>"-2147483648",
|
62 |
-
'backup_batch_size'=>"
|
|
|
63 |
);
|
64 |
|
65 |
|
@@ -112,10 +113,10 @@ class WPBackitup_Admin {
|
|
112 |
add_action('wp_ajax_wp-backitup_backup', array( &$this, 'ajax_queue_backup' ));
|
113 |
|
114 |
//Load the restore action
|
115 |
-
add_action('wp_ajax_wp-backitup_restore', array( &$this, '
|
116 |
|
117 |
//Load the upload action
|
118 |
-
add_action('wp_ajax_wp-
|
119 |
|
120 |
//Status reader for UI
|
121 |
add_action('wp_ajax_wp-backitup_restore_status_reader', array( &$this,'ajax_get_restore_status'));
|
@@ -125,7 +126,7 @@ class WPBackitup_Admin {
|
|
125 |
add_action('wp_ajax_wp-backitup_backup_response_reader', array( &$this,'ajax_backup_response_reader'));
|
126 |
|
127 |
//Delete File Action
|
128 |
-
add_action('wp_ajax_wp-backitup_delete_file', array( &$this,'
|
129 |
|
130 |
//View Log Action
|
131 |
add_action('admin_post_viewlog', array( &$this,'admin_viewlog'));
|
@@ -133,9 +134,6 @@ class WPBackitup_Admin {
|
|
133 |
//Download Backup
|
134 |
add_action('admin_post_download_backup', array( &$this,'admin_download_backup'));
|
135 |
|
136 |
-
//List Logs Action
|
137 |
-
add_action('admin_post_nopriv_listlogs', array( &$this,'admin_listlogs'));
|
138 |
-
|
139 |
//Create Daily backup action
|
140 |
add_action( 'wpbackitup_queue_scheduled_jobs', array( &$this,'wpbackitup_queue_scheduled_jobs'));
|
141 |
|
@@ -163,9 +161,13 @@ class WPBackitup_Admin {
|
|
163 |
add_submenu_page( $this->namespace, 'Restore', 'Restore', 'administrator', $this->namespace.'-restore', array( &$this, 'admin_restore_page' ) );
|
164 |
}
|
165 |
|
|
|
|
|
|
|
166 |
//Add Settings Menu Nav
|
167 |
add_submenu_page( $this->namespace, 'Settings', 'Settings', 'administrator', $this->namespace.'-settings', array( &$this, 'admin_settings_page' ) );
|
168 |
|
|
|
169 |
if (WPBACKITUP__DEBUG===true){
|
170 |
add_submenu_page( $this->namespace, 'Test', 'Test', 'administrator', $this->namespace.'-test', array( &$this, 'admin_test_page' ) );
|
171 |
}
|
@@ -180,7 +182,7 @@ class WPBackitup_Admin {
|
|
180 |
//Only load the JS and CSS when plugin is active
|
181 |
if( !empty($_REQUEST['page']) && substr($_REQUEST['page'], 0, 11) === 'wp-backitup') {
|
182 |
|
183 |
-
|
184 |
wp_register_script( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "js/wpbackitup_admin.js", array( 'jquery' ), $this->version, true );
|
185 |
wp_enqueue_script( "{$this->namespace}-admin" );
|
186 |
|
@@ -191,6 +193,11 @@ class WPBackitup_Admin {
|
|
191 |
//Admin fonts
|
192 |
wp_register_style( 'google-fonts', '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' );
|
193 |
wp_enqueue_style( 'google-fonts' );
|
|
|
|
|
|
|
|
|
|
|
194 |
}
|
195 |
}
|
196 |
|
@@ -234,6 +241,15 @@ class WPBackitup_Admin {
|
|
234 |
include WPBACKITUP__PLUGIN_PATH . "/views/settings.php";
|
235 |
}
|
236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
/**
|
238 |
* The admin section backup page rendering method
|
239 |
*
|
@@ -293,6 +309,11 @@ class WPBackitup_Admin {
|
|
293 |
|
294 |
}
|
295 |
|
|
|
|
|
|
|
|
|
|
|
296 |
}
|
297 |
// Handle GET requests
|
298 |
else {
|
@@ -320,47 +341,40 @@ class WPBackitup_Admin {
|
|
320 |
include_once 'class-job.php';
|
321 |
}
|
322 |
|
323 |
-
//If no backup or cleanup queued already then queue one
|
324 |
-
if (!WPBackItUp_Job::is_job_queued('backup')) {
|
325 |
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
|
|
331 |
|
332 |
-
//Setup the job run event
|
333 |
-
wp_schedule_single_event( time(), 'wpbackitup_run_backup_tasks' );
|
334 |
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
if (false===wp_next_scheduled('wpbackitup_run_backup_tasks')){
|
340 |
-
wp_schedule_single_event( time(), 'wpbackitup_run_backup_tasks' );
|
341 |
-
}
|
342 |
-
}
|
343 |
|
344 |
-
|
345 |
-
if (!WPBackItUp_Job::is_job_queued('cleanup')) {
|
346 |
-
//Is it time for a cleanup
|
347 |
-
//Check scheduler and queue tasks that need to be run
|
348 |
-
$scheduler = new WPBackItUp_Scheduler();
|
349 |
-
if ( $scheduler->isTaskScheduled( 'cleanup' ) && !WPBackItUp_Job::is_job_queued('backup') ) {
|
350 |
-
$cleanup_job = WPBackItUp_Job::queue_job( 'cleanup' );
|
351 |
|
352 |
-
|
353 |
-
|
354 |
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
-
}
|
364 |
|
365 |
exit(0); //success nothing to schedule
|
366 |
}
|
@@ -396,6 +410,58 @@ class WPBackitup_Admin {
|
|
396 |
exit;
|
397 |
}
|
398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
//Run scheduled backup tasks
|
400 |
function wpbackitup_run_backup_tasks(){
|
401 |
|
@@ -440,16 +506,16 @@ class WPBackitup_Admin {
|
|
440 |
}
|
441 |
|
442 |
|
443 |
-
public function ajax_get_restore_status() {
|
444 |
-
// Check permissions
|
445 |
-
if (! self::is_authorized()) exit('Access denied.');
|
446 |
-
|
447 |
-
$log = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
|
448 |
-
if(file_exists($log) ) {
|
449 |
-
readfile($log);
|
450 |
-
}
|
451 |
-
exit;
|
452 |
-
}
|
453 |
|
454 |
|
455 |
/**
|
@@ -492,22 +558,66 @@ class WPBackitup_Admin {
|
|
492 |
exit;
|
493 |
}
|
494 |
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
|
500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
}
|
502 |
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
if (! self::is_authorized()) exit('Access denied.');
|
507 |
|
508 |
-
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/
|
509 |
}
|
510 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
|
512 |
|
513 |
public function ajax_backup_response_reader() {
|
@@ -525,21 +635,35 @@ class WPBackitup_Admin {
|
|
525 |
exit;
|
526 |
}
|
527 |
|
528 |
-
public function
|
529 |
{
|
530 |
// Check permissions
|
531 |
if (! self::is_authorized()) exit('Access denied.');
|
532 |
|
533 |
-
$
|
534 |
-
$backup_file_path = WPBACKITUP__BACKUP_PATH .'/' . $backup_file_name;
|
535 |
-
$log_file_path = str_replace('.zip','.log',$backup_file_path);
|
536 |
|
537 |
-
|
538 |
-
|
539 |
-
|
|
|
540 |
|
541 |
-
|
542 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
543 |
}
|
544 |
|
545 |
exit('deleted');
|
@@ -548,23 +672,15 @@ class WPBackitup_Admin {
|
|
548 |
function admin_viewlog(){
|
549 |
if (! self::is_authorized()) exit('Access denied.');
|
550 |
|
551 |
-
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/
|
552 |
}
|
553 |
|
554 |
function admin_download_backup(){
|
555 |
if (! self::is_authorized()) exit('Access denied.');
|
556 |
|
557 |
-
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/
|
558 |
}
|
559 |
|
560 |
-
function admin_listlogs(){
|
561 |
-
if (! self::is_authorized()) exit('Access denied.');
|
562 |
-
|
563 |
-
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/listlogs.php' );
|
564 |
-
}
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
/**
|
569 |
* Process update page form submissions and validate license key
|
570 |
*
|
@@ -691,6 +807,119 @@ class WPBackitup_Admin {
|
|
691 |
return false;
|
692 |
}
|
693 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
694 |
/**
|
695 |
* Process registration page form submissions
|
696 |
*
|
@@ -991,6 +1220,68 @@ class WPBackitup_Admin {
|
|
991 |
|
992 |
}
|
993 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
994 |
/**---------- END GETTERS --------------- **/
|
995 |
|
996 |
/**---------- SETTERS --------------- **/
|
@@ -1033,6 +1324,10 @@ class WPBackitup_Admin {
|
|
1033 |
public function set_backup_batch_size($value){
|
1034 |
$this->set('backup_batch_size', $value);
|
1035 |
}
|
|
|
|
|
|
|
|
|
1036 |
/**---------- END SETTERS --------------- **/
|
1037 |
|
1038 |
|
@@ -1116,8 +1411,12 @@ class WPBackitup_Admin {
|
|
1116 |
$logger->log('Validation Response:');
|
1117 |
$logger->log($response);
|
1118 |
|
1119 |
-
if ( is_wp_error( $response ) )
|
|
|
1120 |
return false; //Exit and don't update
|
|
|
|
|
|
|
1121 |
|
1122 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
1123 |
$logger->log('License Object Info');
|
@@ -1355,6 +1654,12 @@ class WPBackitup_Admin {
|
|
1355 |
exit ('WP BackItUp was not able to create the required backup and restore folders.');
|
1356 |
}
|
1357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1358 |
} catch (Exception $e) {
|
1359 |
exit ('WP BackItUp encountered an error during activation.</br>' .$e->getMessage());
|
1360 |
}
|
59 |
'backup_schedule'=>"",
|
60 |
'backup_lastrun_date'=>"-2147483648",
|
61 |
'cleanup_lastrun_date'=>"-2147483648",
|
62 |
+
'backup_batch_size'=>"500",
|
63 |
+
'support_email' => "",
|
64 |
);
|
65 |
|
66 |
|
113 |
add_action('wp_ajax_wp-backitup_backup', array( &$this, 'ajax_queue_backup' ));
|
114 |
|
115 |
//Load the restore action
|
116 |
+
add_action('wp_ajax_wp-backitup_restore', array( &$this, 'ajax_queue_restore' ));
|
117 |
|
118 |
//Load the upload action
|
119 |
+
add_action('wp_ajax_wp-backitup_plupload_action', array($this,'plupload_action'));
|
120 |
|
121 |
//Status reader for UI
|
122 |
add_action('wp_ajax_wp-backitup_restore_status_reader', array( &$this,'ajax_get_restore_status'));
|
126 |
add_action('wp_ajax_wp-backitup_backup_response_reader', array( &$this,'ajax_backup_response_reader'));
|
127 |
|
128 |
//Delete File Action
|
129 |
+
add_action('wp_ajax_wp-backitup_delete_file', array( &$this,'ajax_delete_backup'));
|
130 |
|
131 |
//View Log Action
|
132 |
add_action('admin_post_viewlog', array( &$this,'admin_viewlog'));
|
134 |
//Download Backup
|
135 |
add_action('admin_post_download_backup', array( &$this,'admin_download_backup'));
|
136 |
|
|
|
|
|
|
|
137 |
//Create Daily backup action
|
138 |
add_action( 'wpbackitup_queue_scheduled_jobs', array( &$this,'wpbackitup_queue_scheduled_jobs'));
|
139 |
|
161 |
add_submenu_page( $this->namespace, 'Restore', 'Restore', 'administrator', $this->namespace.'-restore', array( &$this, 'admin_restore_page' ) );
|
162 |
}
|
163 |
|
164 |
+
//Add Support Menu Nav
|
165 |
+
add_submenu_page( $this->namespace, 'Support', 'Support', 'administrator', $this->namespace.'-support', array( &$this, 'admin_support_page' ) );
|
166 |
+
|
167 |
//Add Settings Menu Nav
|
168 |
add_submenu_page( $this->namespace, 'Settings', 'Settings', 'administrator', $this->namespace.'-settings', array( &$this, 'admin_settings_page' ) );
|
169 |
|
170 |
+
|
171 |
if (WPBACKITUP__DEBUG===true){
|
172 |
add_submenu_page( $this->namespace, 'Test', 'Test', 'administrator', $this->namespace.'-test', array( &$this, 'admin_test_page' ) );
|
173 |
}
|
182 |
//Only load the JS and CSS when plugin is active
|
183 |
if( !empty($_REQUEST['page']) && substr($_REQUEST['page'], 0, 11) === 'wp-backitup') {
|
184 |
|
185 |
+
// Admin JavaScript
|
186 |
wp_register_script( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "js/wpbackitup_admin.js", array( 'jquery' ), $this->version, true );
|
187 |
wp_enqueue_script( "{$this->namespace}-admin" );
|
188 |
|
193 |
//Admin fonts
|
194 |
wp_register_style( 'google-fonts', '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' );
|
195 |
wp_enqueue_style( 'google-fonts' );
|
196 |
+
|
197 |
+
//UPLOADS only
|
198 |
+
if ($_REQUEST['page']=='wp-backitup-restore') {
|
199 |
+
wp_enqueue_media();
|
200 |
+
}
|
201 |
}
|
202 |
}
|
203 |
|
241 |
include WPBACKITUP__PLUGIN_PATH . "/views/settings.php";
|
242 |
}
|
243 |
|
244 |
+
/**
|
245 |
+
* The admin section support page rendering method
|
246 |
+
*
|
247 |
+
*/
|
248 |
+
public function admin_support_page()
|
249 |
+
{
|
250 |
+
include WPBACKITUP__PLUGIN_PATH . "/views/support.php";
|
251 |
+
}
|
252 |
+
|
253 |
/**
|
254 |
* The admin section backup page rendering method
|
255 |
*
|
309 |
|
310 |
}
|
311 |
|
312 |
+
if( wp_verify_nonce( $nonce, "{$this->namespace}-support-form" ) ) {
|
313 |
+
$logger->log('Support Form Post');
|
314 |
+
$this->_admin_send_support_request();
|
315 |
+
}
|
316 |
+
|
317 |
}
|
318 |
// Handle GET requests
|
319 |
else {
|
341 |
include_once 'class-job.php';
|
342 |
}
|
343 |
|
|
|
|
|
344 |
|
345 |
+
//If any jobs are queued or active then just exit
|
346 |
+
if (WPBackItUp_Job::is_job_queued('backup') ||
|
347 |
+
WPBackItUp_Job::is_job_queued('restore') ||
|
348 |
+
WPBackItUp_Job::is_job_queued('cleanup')) {
|
349 |
+
exit;
|
350 |
+
}
|
351 |
|
|
|
|
|
352 |
|
353 |
+
//Is it time for a backup?
|
354 |
+
//Check scheduler and queue tasks that need to be run
|
355 |
+
$scheduler = new WPBackItUp_Scheduler();
|
356 |
+
if ( $scheduler->isTaskScheduled( 'backup' ) ) {
|
|
|
|
|
|
|
|
|
357 |
|
358 |
+
$backup_job = WPBackItUp_Job::queue_job( 'backup' );
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
|
360 |
+
//Setup the job run event
|
361 |
+
wp_schedule_single_event( time(), 'wpbackitup_run_backup_tasks' );
|
362 |
|
363 |
+
exit( 0 ); //success - don't schedule anything else
|
364 |
+
}
|
365 |
+
|
366 |
+
//Is it time for a cleanup
|
367 |
+
//Check scheduler and queue tasks that need to be run
|
368 |
+
if ( $scheduler->isTaskScheduled( 'cleanup' ) && !WPBackItUp_Job::is_job_queued('backup') ) {
|
369 |
+
|
370 |
+
$cleanup_job = WPBackItUp_Job::queue_job( 'cleanup' );
|
371 |
+
|
372 |
+
//Setup the job run event
|
373 |
+
wp_schedule_single_event( time(), 'wpbackitup_run_cleanup_tasks' );
|
374 |
+
|
375 |
+
exit( 0 ); //success - don't schedule anything else
|
376 |
+
}
|
377 |
|
|
|
378 |
|
379 |
exit(0); //success nothing to schedule
|
380 |
}
|
410 |
exit;
|
411 |
}
|
412 |
|
413 |
+
//Run queue manual restore
|
414 |
+
public function ajax_queue_restore() {
|
415 |
+
$rtnData = new stdClass();
|
416 |
+
|
417 |
+
// Check permissions
|
418 |
+
if (! self::is_authorized()) exit('Access denied.');
|
419 |
+
|
420 |
+
$logger = new WPBackItUp_Logger(false,null,'debug_events');
|
421 |
+
$logger->log_info(__METHOD__,'Begin');
|
422 |
+
|
423 |
+
//Include Job class
|
424 |
+
if( !class_exists( 'WPBackItUp_Job' ) ) {
|
425 |
+
include_once 'class-job.php';
|
426 |
+
}
|
427 |
+
|
428 |
+
$validation_error=false;
|
429 |
+
//Get posted values
|
430 |
+
$backup_file_name = $_POST['selected_file'];//Get the backup file name
|
431 |
+
if( empty($backup_file_name)) {
|
432 |
+
$rtnData->message = 'No backup file selected.';
|
433 |
+
$validation_error=true;
|
434 |
+
}
|
435 |
+
|
436 |
+
//Get user ID - GET ThIS FROM POST ID
|
437 |
+
$user_id = $_POST['user_id'];
|
438 |
+
if( empty($user_id)) {
|
439 |
+
$rtnData->message = 'No user id found.';
|
440 |
+
$validation_error=true;
|
441 |
+
}
|
442 |
+
|
443 |
+
//If no job queued already then queue one
|
444 |
+
if (! $validation_error){
|
445 |
+
if (! WPBackItUp_Job::is_job_queued('restore')){
|
446 |
+
$job=WPBackItUp_Job::queue_job('restore');
|
447 |
+
if ($job!== false){
|
448 |
+
$job->update_job_meta('backup_name',$backup_file_name);
|
449 |
+
$job->update_job_meta('user_id',$user_id);
|
450 |
+
$rtnData->message = 'Restore Queued';
|
451 |
+
}else {
|
452 |
+
$rtnData->message = 'Restore could not be queued';
|
453 |
+
}
|
454 |
+
}else{
|
455 |
+
$rtnData->message = 'Restore already in queue';
|
456 |
+
}
|
457 |
+
}
|
458 |
+
|
459 |
+
$logger->log_info(__METHOD__,$rtnData->message);
|
460 |
+
$logger->log_info(__METHOD__,'End');
|
461 |
+
echo json_encode($rtnData);
|
462 |
+
exit;
|
463 |
+
}
|
464 |
+
|
465 |
//Run scheduled backup tasks
|
466 |
function wpbackitup_run_backup_tasks(){
|
467 |
|
506 |
}
|
507 |
|
508 |
|
509 |
+
// public function ajax_get_restore_status() {
|
510 |
+
// // Check permissions
|
511 |
+
// if (! self::is_authorized()) exit('Access denied.');
|
512 |
+
//
|
513 |
+
// $log = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
|
514 |
+
// if(file_exists($log) ) {
|
515 |
+
// readfile($log);
|
516 |
+
// }
|
517 |
+
// exit;
|
518 |
+
// }
|
519 |
|
520 |
|
521 |
/**
|
558 |
exit;
|
559 |
}
|
560 |
|
561 |
+
/**
|
562 |
+
* Return the restore status and try run tasks
|
563 |
+
*/
|
564 |
+
public function ajax_get_restore_status() {
|
565 |
+
// Check permissions
|
566 |
+
if (! self::is_authorized()) exit('Access denied.');
|
567 |
+
|
568 |
+
$event_logger = new WPBackItUp_Logger(false,null,'debug_events');
|
569 |
+
|
570 |
+
$event_logger->log_info(__METHOD__ ,'User Permissions: ' .current_user_can( 'manage_options' ));
|
571 |
+
|
572 |
+
//Check permissions
|
573 |
+
if ( current_user_can( 'manage_options' ) ) {
|
574 |
+
//echo('RUNNING BACKUP');
|
575 |
+
|
576 |
+
$process_id = uniqid();
|
577 |
|
578 |
+
$event_logger->log_info(__METHOD__ .'(' .$process_id .')', 'Begin');
|
579 |
+
|
580 |
+
//Try Run Next Backup Tasks
|
581 |
+
$event_logger->log_info(__METHOD__.'(' .$process_id .')','Try Run restore task');
|
582 |
+
|
583 |
+
$this->backup_type='manual';
|
584 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_restore.php' );
|
585 |
+
|
586 |
+
$event_logger->log_info(__METHOD__.'(' .$process_id .')','End Try Run Backup Task');
|
587 |
+
|
588 |
+
//return status
|
589 |
+
$log = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
|
590 |
+
if(file_exists($log) ) {
|
591 |
+
//Probably should use the database instead now.
|
592 |
+
readfile($log);
|
593 |
+
$event_logger->log_info(__METHOD__.'(' .$process_id .')','Status sent to browser.');
|
594 |
+
}
|
595 |
+
}
|
596 |
+
|
597 |
+
exit;
|
598 |
}
|
599 |
|
600 |
+
public function plupload_action() {
|
601 |
+
// Check permissions
|
602 |
+
if (! self::is_authorized()) exit('Access denied.');
|
|
|
603 |
|
604 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/handler_upload.php' );
|
605 |
}
|
606 |
|
607 |
+
public function upload_dir($uploads) {
|
608 |
+
$upload_path = WPBACKITUP__UPLOAD_PATH;
|
609 |
+
if (is_writable($upload_path)) $uploads['path'] = $upload_path;
|
610 |
+
return $uploads;
|
611 |
+
}
|
612 |
+
|
613 |
+
public function unique_filename_callback($dir, $name, $ext) {
|
614 |
+
return $name.$ext;
|
615 |
+
}
|
616 |
+
|
617 |
+
|
618 |
+
public function sanitize_file_name($filename) {
|
619 |
+
return $filename;
|
620 |
+
}
|
621 |
|
622 |
|
623 |
public function ajax_backup_response_reader() {
|
635 |
exit;
|
636 |
}
|
637 |
|
638 |
+
public function ajax_delete_backup()
|
639 |
{
|
640 |
// Check permissions
|
641 |
if (! self::is_authorized()) exit('Access denied.');
|
642 |
|
643 |
+
$logger = new WPBackItUp_Logger(true,null,'debug_delete');
|
|
|
|
|
644 |
|
645 |
+
$backup_folder_name = str_replace('deleteRow', '', $_POST['filed']);
|
646 |
+
|
647 |
+
$backup_folder_path = WPBACKITUP__BACKUP_PATH .'/' . $backup_folder_name;
|
648 |
+
$DLT_backup_folder_path = WPBACKITUP__BACKUP_PATH .'/DLT_' . $backup_folder_name .'_' . current_time( 'timestamp' );;
|
649 |
|
650 |
+
$logger->log_info(__METHOD__,'From:'.$backup_folder_path );
|
651 |
+
$logger->log_info(__METHOD__,'To:'.$DLT_backup_folder_path );
|
652 |
+
|
653 |
+
//Mark the folder deleted so cleanup will handle
|
654 |
+
if (file_exists ($backup_folder_path)){
|
655 |
+
|
656 |
+
if( !class_exists( 'WPBackItUp_FileSystem' ) ) {
|
657 |
+
include_once 'class-filesystem.php';
|
658 |
+
}
|
659 |
+
|
660 |
+
$file_system = new WPBackItUp_FileSystem($logger);
|
661 |
+
if (! $file_system->rename_file($backup_folder_path,$DLT_backup_folder_path)){
|
662 |
+
$logger->log_error(__METHOD__,'Folder was not renamed');
|
663 |
+
exit('Backup NOT deleted');
|
664 |
+
}
|
665 |
+
}else{
|
666 |
+
$logger->log_error(__METHOD__,'Folder not found:'. $backup_folder_path);
|
667 |
}
|
668 |
|
669 |
exit('deleted');
|
672 |
function admin_viewlog(){
|
673 |
if (! self::is_authorized()) exit('Access denied.');
|
674 |
|
675 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/handler_viewlog.php' );
|
676 |
}
|
677 |
|
678 |
function admin_download_backup(){
|
679 |
if (! self::is_authorized()) exit('Access denied.');
|
680 |
|
681 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/handler_download.php' );
|
682 |
}
|
683 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
684 |
/**
|
685 |
* Process update page form submissions and validate license key
|
686 |
*
|
807 |
return false;
|
808 |
}
|
809 |
|
810 |
+
/**
|
811 |
+
* Send support request Schedule
|
812 |
+
*
|
813 |
+
*/
|
814 |
+
public function _admin_send_support_request() {
|
815 |
+
// Verify submission for processing using wp_nonce
|
816 |
+
|
817 |
+
$url= str_replace('&s=1','',$_REQUEST['_wp_http_referer']);
|
818 |
+
$logger = new WPBackItUp_Logger(true,null,'debug_support');
|
819 |
+
$logger->log_sysinfo();
|
820 |
+
$logger->log_info(__METHOD__,'Send Support Request');
|
821 |
+
|
822 |
+
$error=false;
|
823 |
+
if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-support-form" ) ) {
|
824 |
+
|
825 |
+
$logger->log_info(__METHOD__,"Send support request");
|
826 |
+
$logger->log_info(__METHOD__,$_POST);
|
827 |
+
|
828 |
+
//save the email in place of transient
|
829 |
+
$this->set_support_email($_POST['support_email']);
|
830 |
+
|
831 |
+
// save the transients in case of error
|
832 |
+
foreach( $_POST as $key => $val ){
|
833 |
+
set_transient($key, __($val, $this->namespace), 60);
|
834 |
+
}
|
835 |
+
|
836 |
+
//validate form fields
|
837 |
+
if(empty($_POST['support_email']) || !is_email($_POST['support_email']))
|
838 |
+
{
|
839 |
+
$error=true;
|
840 |
+
set_transient('error-support-email', __('Please enter a valid email', $this->namespace), 60);
|
841 |
+
}
|
842 |
+
|
843 |
+
if(empty($_POST['support_subject']))
|
844 |
+
{
|
845 |
+
$error=true;
|
846 |
+
set_transient('error-support-subject', __('Please enter a short description of your problem', $this->namespace), 60);
|
847 |
+
}
|
848 |
+
|
849 |
+
if(empty($_POST['support_body']))
|
850 |
+
{
|
851 |
+
$error=true;
|
852 |
+
set_transient('error-support-body', __('Please enter your problem description', $this->namespace), 60);
|
853 |
+
}
|
854 |
+
|
855 |
+
$include_logs=false;
|
856 |
+
if(!empty($_POST['support_include_logs']))
|
857 |
+
{
|
858 |
+
$include_logs=true;
|
859 |
+
}
|
860 |
+
|
861 |
+
//Send if no errors
|
862 |
+
if (!$error){
|
863 |
+
|
864 |
+
if( !class_exists( 'WPBackItUp_Zip' ) ) {
|
865 |
+
include_once 'class-zip.php';
|
866 |
+
}
|
867 |
+
|
868 |
+
if( !class_exists( 'WPBackItUp_Utility' ) ) {
|
869 |
+
include_once 'class-utility.php';
|
870 |
+
}
|
871 |
+
|
872 |
+
$support_request_id=time();
|
873 |
+
$logs_attachment = array(); //default to no logs
|
874 |
+
if ($include_logs){
|
875 |
+
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
876 |
+
|
877 |
+
//copy/replace WP debug file
|
878 |
+
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
879 |
+
$logger->log_info(__METHOD__,"Copy WP Debug: " .$wpdebug_file_path);
|
880 |
+
if (file_exists($wpdebug_file_path)) {
|
881 |
+
copy( $wpdebug_file_path, $logs_path .'/wpdebug.log' );
|
882 |
+
}
|
883 |
+
|
884 |
+
|
885 |
+
$zip_file_path = $logs_path . '/logs_' . $support_request_id . '.zip';
|
886 |
+
$zip = new WPBackItUp_Zip($logger,$zip_file_path);
|
887 |
+
$zip->zip_files_in_folder($logs_path,$support_request_id,'*.log');
|
888 |
+
$zip->close();
|
889 |
+
|
890 |
+
$logs_attachment = array( $zip_file_path );
|
891 |
+
|
892 |
+
}
|
893 |
+
|
894 |
+
$utility = new WPBackItUp_Utility($logger);
|
895 |
+
$support_to_address = WPBACKITUP__SUPPORT_EMAIL;
|
896 |
+
$support_from_email=$_POST['support_email'];
|
897 |
+
$support_subject = 'Support Request (' .$support_request_id .'): ' .$_POST['support_subject'];
|
898 |
+
|
899 |
+
|
900 |
+
$site_info = 'WordPress Site: <a href="' . home_url() . '" target="_blank">' . home_url() .'</a><br/>';
|
901 |
+
$site_info .="WP BackItUp License Type: " . $this->license_type_description() .' <br />';
|
902 |
+
|
903 |
+
$support_body=$site_info . '<br/><br/>' . $_POST['support_body'];
|
904 |
+
|
905 |
+
|
906 |
+
$utility->send_email($support_to_address,$support_subject,$support_body,$logs_attachment,$support_from_email);
|
907 |
+
|
908 |
+
// get rid of the transients
|
909 |
+
foreach( $_POST as $key => $val ){
|
910 |
+
delete_transient($key);
|
911 |
+
}
|
912 |
+
|
913 |
+
wp_safe_redirect($url . '&s=1');
|
914 |
+
exit;
|
915 |
+
}
|
916 |
+
}
|
917 |
+
|
918 |
+
wp_safe_redirect($url);
|
919 |
+
exit;
|
920 |
+
|
921 |
+
}
|
922 |
+
|
923 |
/**
|
924 |
* Process registration page form submissions
|
925 |
*
|
1220 |
|
1221 |
}
|
1222 |
|
1223 |
+
public function support_email(){
|
1224 |
+
return $this->get('support_email');
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
public function get_backup_list(){
|
1228 |
+
|
1229 |
+
// get retention number set
|
1230 |
+
$number_retained_archives = $this->backup_retained_number();
|
1231 |
+
|
1232 |
+
//Make sure backup folder exists
|
1233 |
+
$backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
|
1234 |
+
|
1235 |
+
//Create the backup list
|
1236 |
+
$folder_list = glob($backup_dir . "/*",GLOB_ONLYDIR);
|
1237 |
+
$backup_list=array();
|
1238 |
+
$i=0;
|
1239 |
+
if (count($folder_list)>0) {
|
1240 |
+
foreach($folder_list as $folder) {
|
1241 |
+
$backup_name = basename($folder);
|
1242 |
+
$backup_prefix = substr($backup_name,0,4);
|
1243 |
+
|
1244 |
+
//Dont include incomplete backups or deleted folders
|
1245 |
+
if ( $backup_prefix!='TMP_' &&
|
1246 |
+
$backup_prefix!='DLT_' ) {
|
1247 |
+
|
1248 |
+
$i++;
|
1249 |
+
if( $number_retained_archives && $i> $number_retained_archives ) break;
|
1250 |
+
|
1251 |
+
$logs = glob($folder . "/*.log");
|
1252 |
+
$log_exists=false;
|
1253 |
+
if (count($logs)>0){
|
1254 |
+
$log_exists=true;
|
1255 |
+
}
|
1256 |
+
|
1257 |
+
//Only get the files with the backup prefix.
|
1258 |
+
$zip_files = glob($folder . "/" .$backup_name ."*.zip");
|
1259 |
+
|
1260 |
+
array_push($backup_list,
|
1261 |
+
array(
|
1262 |
+
"backup_name" => $backup_name,
|
1263 |
+
"log_exists"=>$log_exists,
|
1264 |
+
"date_time" => filectime($folder),
|
1265 |
+
"zip_files"=>$zip_files,
|
1266 |
+
));
|
1267 |
+
|
1268 |
+
// $backup_list[] = [
|
1269 |
+
// "backup_name" => $backup_name,
|
1270 |
+
// "log_exists"=>$log_exists,
|
1271 |
+
// "date_time" => filectime($folder),
|
1272 |
+
// "zip_files"=>$zip_files,
|
1273 |
+
// ];
|
1274 |
+
}
|
1275 |
+
}
|
1276 |
+
//sort the list by date
|
1277 |
+
usort($backup_list, create_function('$a,$b', 'return $b["date_time"] - $a["date_time"];'));
|
1278 |
+
|
1279 |
+
return $backup_list;
|
1280 |
+
}
|
1281 |
+
|
1282 |
+
return false;
|
1283 |
+
}
|
1284 |
+
|
1285 |
/**---------- END GETTERS --------------- **/
|
1286 |
|
1287 |
/**---------- SETTERS --------------- **/
|
1324 |
public function set_backup_batch_size($value){
|
1325 |
$this->set('backup_batch_size', $value);
|
1326 |
}
|
1327 |
+
|
1328 |
+
function set_support_email($value){
|
1329 |
+
$this->set('support_email', $value);
|
1330 |
+
}
|
1331 |
/**---------- END SETTERS --------------- **/
|
1332 |
|
1333 |
|
1411 |
$logger->log('Validation Response:');
|
1412 |
$logger->log($response);
|
1413 |
|
1414 |
+
if ( is_wp_error( $response ) ){
|
1415 |
+
$logger->log_error(__METHOD__,$response->get_error_message());
|
1416 |
return false; //Exit and don't update
|
1417 |
+
}else{
|
1418 |
+
$logger->log_info(__METHOD__,'No request errors.');
|
1419 |
+
}
|
1420 |
|
1421 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
1422 |
$logger->log('License Object Info');
|
1654 |
exit ('WP BackItUp was not able to create the required backup and restore folders.');
|
1655 |
}
|
1656 |
|
1657 |
+
//Need to reset the batch size for this release
|
1658 |
+
$batch_size = get_option('wp-backitup_backup_batch_size');
|
1659 |
+
if ($batch_size<100){
|
1660 |
+
delete_option('wp-backitup_backup_batch_size');
|
1661 |
+
}
|
1662 |
+
|
1663 |
} catch (Exception $e) {
|
1664 |
exit ('WP BackItUp encountered an error during activation.</br>' .$e->getMessage());
|
1665 |
}
|
lib/includes/class-zip.php
CHANGED
@@ -1 +1 @@
|
|
1 |
-
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
* WP Backitup Zip Function
|
3 |
*
|
4 |
* @package WP Backitup
|
5 |
*
|
6 |
* @author cssimmon
|
7 |
*
|
8 |
*/
|
9 |
private $zip_file_count;
|
10 |
private $max_file_count;
|
11 |
$this->zip_file_count=0;
|
12 |
}
|
13 |
function __destruct() {
|
|
|
14 |
* WP Backitup Zip Function
|
15 |
*
|
16 |
* @package WP Backitup
|
17 |
*
|
18 |
* @author cssimmon
|
19 |
*
|
20 |
*/
|
21 |
private $zip_file_count;
|
22 |
$this->zip_file_count=0;
|
23 |
}
|
|
|
1 |
* WP Backitup Zip Function
|
2 |
*
|
3 |
* @package WP Backitup
|
4 |
*
|
5 |
* @author cssimmon
|
6 |
*
|
7 |
*/
|
8 |
private $zip_file_count;
|
9 |
private $max_file_count;
|
10 |
$this->zip_file_count=0;
|
11 |
}
|
12 |
function __destruct() {
|
13 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
14 |
* WP Backitup Zip Function
|
15 |
*
|
16 |
* @package WP Backitup
|
17 |
*
|
18 |
* @author cssimmon
|
19 |
*
|
20 |
*/
|
21 |
private $zip_file_count;
|
22 |
$this->zip_file_count=0;
|
23 |
}
|
lib/includes/download_backup.php
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
<?php if (!defined ('ABSPATH')) die('No direct access allowed (viewlog)');
|
2 |
-
|
3 |
-
|
4 |
-
if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
5 |
-
&& isset($_REQUEST['backup_name']) && !empty($_REQUEST['backup_name']) ){
|
6 |
-
|
7 |
-
if ( wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-download_backup')) {
|
8 |
-
|
9 |
-
// make sure .zip isnt included
|
10 |
-
$backup_filename = rtrim($_REQUEST['backup_name'], '.zip');
|
11 |
-
|
12 |
-
//Add zip
|
13 |
-
$backup_filename = $backup_filename. '.zip';
|
14 |
-
$backup_path = WPBACKITUP__BACKUP_PATH .'/' .$backup_filename ;
|
15 |
-
|
16 |
-
if(file_exists($backup_path) ) {
|
17 |
-
|
18 |
-
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
19 |
-
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
20 |
-
|
21 |
-
header('Content-type: application/zip');
|
22 |
-
header("Content-Disposition: attachment; filename=$backup_filename");
|
23 |
-
header("Content-Length: ".filesize($backup_path));
|
24 |
-
ob_get_clean();
|
25 |
-
readfile($backup_path);
|
26 |
-
if (ob_get_level()>1) ob_end_flush();
|
27 |
-
die();
|
28 |
-
}
|
29 |
-
}
|
30 |
-
}
|
31 |
-
|
32 |
-
//Return empty file
|
33 |
-
header ('Content-type: octet/stream');
|
34 |
-
header("Content-Disposition: attachment; filename=nobackup.log");
|
35 |
-
header("Content-Length: ' .100");
|
36 |
-
ob_get_clean();
|
37 |
-
echo('No backup found.'. PHP_EOL);
|
38 |
-
//echo($_REQUEST['_wpnonce']. PHP_EOL);
|
39 |
-
//echo($_REQUEST['viewlog_log']. PHP_EOL);
|
40 |
-
if (ob_get_level()>1) ob_end_flush();
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/includes/handler_download.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed (viewlog)');
|
2 |
+
@set_time_limit(WPBACKITUP__SCRIPT_TIMEOUT_SECONDS);
|
3 |
+
|
4 |
+
// required for IE, otherwise Content-disposition is ignored
|
5 |
+
//@apache_setenv('no-gzip', 1); Causes failure on siteground...research
|
6 |
+
@ini_set('zlib.output_compression', 'Off');
|
7 |
+
|
8 |
+
global $logger;
|
9 |
+
$logger = new WPBackItUp_Logger(true,null,'debug_download');
|
10 |
+
|
11 |
+
$logger->log_info(__METHOD__,$_REQUEST);
|
12 |
+
|
13 |
+
if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
14 |
+
&& isset($_REQUEST['backup_file']) && !empty($_REQUEST['backup_file']) ) {
|
15 |
+
|
16 |
+
if ( wp_verify_nonce( $_REQUEST['_wpnonce'], WPBACKITUP__NAMESPACE . '-download_backup' ) ) {
|
17 |
+
$logger->log_info( __METHOD__, 'nonce verified' );
|
18 |
+
|
19 |
+
//strip off the suffix IF one exists
|
20 |
+
$folder_name = rtrim( $_REQUEST['backup_file'], '.zip' );;
|
21 |
+
if ( ( $str_pos = strpos( $folder_name, '-main-' ) ) !== false ) {
|
22 |
+
$suffix = substr( $folder_name, $str_pos );
|
23 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
24 |
+
}
|
25 |
+
|
26 |
+
if ( ( $str_pos = strpos( $folder_name, '-others-' ) ) !== false ) {
|
27 |
+
$suffix = substr( $folder_name, $str_pos );
|
28 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
29 |
+
}
|
30 |
+
|
31 |
+
if ( ( $str_pos = strpos( $folder_name, '-plugins-' ) ) !== false ) {
|
32 |
+
$suffix = substr( $folder_name, $str_pos );
|
33 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
34 |
+
}
|
35 |
+
|
36 |
+
if ( ( $str_pos = strpos( $folder_name, '-themes-' ) ) !== false ) {
|
37 |
+
$suffix = substr( $folder_name, $str_pos );
|
38 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
39 |
+
}
|
40 |
+
|
41 |
+
if ( ( $str_pos = strpos( $folder_name, '-uploads-' ) ) !== false ) {
|
42 |
+
$suffix = substr( $folder_name, $str_pos );
|
43 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
44 |
+
}
|
45 |
+
|
46 |
+
$backup_filename = $_REQUEST['backup_file'];
|
47 |
+
$backup_path = WPBACKITUP__BACKUP_PATH . '/' . $folder_name . '/' . $backup_filename;
|
48 |
+
$logger->log_info( __METHOD__, 'Backup file path:' . $backup_path );
|
49 |
+
|
50 |
+
if ( !empty($backup_filename) && file_exists( $backup_path ) ) {
|
51 |
+
$file_size = filesize($backup_path);
|
52 |
+
$chunksize = 1*(1024*1024); // how many bytes per chunk
|
53 |
+
$buffer = '';
|
54 |
+
$cnt =0;
|
55 |
+
$handle = fopen($backup_path, 'rb');
|
56 |
+
if ($handle !== false) {
|
57 |
+
//Output Headers
|
58 |
+
header("Content-Disposition: attachment; filename=\"" . basename( $backup_path ) . "\";" );
|
59 |
+
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
60 |
+
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT" );
|
61 |
+
header("Content-type: application/zip");
|
62 |
+
header("Content-Transfer-Encoding: binary");
|
63 |
+
header("Content-Length: ".$file_size);
|
64 |
+
|
65 |
+
while (!feof($handle)) {
|
66 |
+
$buffer = fread($handle, $chunksize);
|
67 |
+
echo $buffer;
|
68 |
+
ob_flush();
|
69 |
+
flush();
|
70 |
+
}
|
71 |
+
|
72 |
+
fclose($handle);
|
73 |
+
$logger->log_info( __METHOD__, 'Download complete' );
|
74 |
+
exit();
|
75 |
+
|
76 |
+
} else {
|
77 |
+
$logger->log_error( __METHOD__, 'File Not found' );
|
78 |
+
}
|
79 |
+
} else {
|
80 |
+
$logger->log_error( __METHOD__, 'Backup file doesnt exist:' . $backup_path );
|
81 |
+
}
|
82 |
+
} else {
|
83 |
+
$logger->log_error( __METHOD__, 'Bad Nonce');
|
84 |
+
}
|
85 |
+
} else {
|
86 |
+
$logger->log_error( __METHOD__, 'Form data missing');
|
87 |
+
}
|
88 |
+
|
89 |
+
//Return empty file
|
90 |
+
header ('Content-type: octet/stream');
|
91 |
+
header("Content-Disposition: attachment; filename=empty.log");
|
92 |
+
header("Content-Length: 100");
|
93 |
+
ob_get_clean();
|
94 |
+
echo('No backup file found.'. PHP_EOL);
|
95 |
+
if (ob_get_level()>1) ob_end_flush();
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
|
lib/includes/handler_upload.php
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed (upload)');
|
2 |
+
/**
|
3 |
+
* WP BackItUp File Upload Handler
|
4 |
+
*
|
5 |
+
* @package WP BackItUp
|
6 |
+
*
|
7 |
+
* @author cssimmon
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
|
11 |
+
/*** Includes ***/
|
12 |
+
|
13 |
+
|
14 |
+
/*** Globals ***/
|
15 |
+
global $logger;
|
16 |
+
$logger = new WPBackItUp_Logger(false,null,'debug_upload');
|
17 |
+
$backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
|
18 |
+
|
19 |
+
//*****************//
|
20 |
+
//*** MAIN CODE ***//
|
21 |
+
//*****************//
|
22 |
+
$logger->log('***BEGIN UPLOAD***');
|
23 |
+
$logger->log($_POST);
|
24 |
+
|
25 |
+
|
26 |
+
//verify nonce
|
27 |
+
if ( !wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-upload')) {
|
28 |
+
$logger->log_error(__METHOD__,'Invalid Nonce');
|
29 |
+
echo json_encode( array( 'error' => sprintf( __( 'Invalid Nonce',WPBACKITUP__NAMESPACE ) ) ) );
|
30 |
+
exit;
|
31 |
+
|
32 |
+
}
|
33 |
+
|
34 |
+
//Check upload folder
|
35 |
+
$upload_path = WPBACKITUP__UPLOAD_PATH;
|
36 |
+
if ( !is_dir( $upload_path ) ){
|
37 |
+
if ( ! mkdir( $upload_path, 0755 )){
|
38 |
+
$logger->log_error(__METHOD__,'Upload directory is not writable, or does not exist.');
|
39 |
+
echo json_encode( array( 'error' => sprintf( __( "Upload directory is not writable, or does not exist.", WPBACKITUP__NAMESPACE ) ) ) );
|
40 |
+
exit;
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
add_filter( 'upload_dir', array( $this, 'upload_dir' ) );
|
45 |
+
add_filter( 'sanitize_file_name', array( $this, 'sanitize_file_name' ) );
|
46 |
+
|
47 |
+
$farray = array( 'test_form' => true, 'action' => WPBACKITUP__NAMESPACE . '_plupload_action' );
|
48 |
+
|
49 |
+
$farray['test_type'] = false;
|
50 |
+
$farray['ext'] = 'x-gzip';
|
51 |
+
$farray['type'] = 'application/octet-stream';
|
52 |
+
|
53 |
+
if ( ! isset( $_POST['chunks'] ) ) {
|
54 |
+
$farray['unique_filename_callback'] = array( $this, 'unique_filename_callback' );
|
55 |
+
}
|
56 |
+
|
57 |
+
$status = wp_handle_upload(
|
58 |
+
$_FILES['async-upload'],
|
59 |
+
$farray
|
60 |
+
);
|
61 |
+
|
62 |
+
//remove filters
|
63 |
+
remove_filter( 'upload_dir', array( $this, 'upload_dir' ) );
|
64 |
+
remove_filter( 'sanitize_file_name', array( $this, 'sanitize_file_name' ) );
|
65 |
+
|
66 |
+
if ( isset( $status['error'] ) ) {
|
67 |
+
$logger->log_error(__METHOD__,$status['error']);
|
68 |
+
echo json_encode( array( 'error' => $status['error'] ) );
|
69 |
+
exit;
|
70 |
+
}
|
71 |
+
|
72 |
+
if ( isset( $_POST['chunks'] ) && isset( $_POST['chunk'] ) ) {
|
73 |
+
$chunk_id = $_POST['chunk'];
|
74 |
+
$zip_file_name = basename( $_POST['name'] );
|
75 |
+
$from_file_path = $status['file'];
|
76 |
+
$to_file_path = $upload_path . '/' . $zip_file_name . '_' . $chunk_id . '.zip.tmp';
|
77 |
+
if ( ! rename( $from_file_path, $to_file_path ) ) {
|
78 |
+
@unlink( $from_file_path );
|
79 |
+
$logger->log_error(__METHOD__,'Cant rename file.');
|
80 |
+
echo json_encode( array( 'error' => sprintf( __( 'Error: %s', 'wpbackitup' ), __( 'File could not be uploaded', 'wpbackitup' ) ) ) );
|
81 |
+
exit;
|
82 |
+
}
|
83 |
+
|
84 |
+
// Combine all chunks when done
|
85 |
+
if ( $_POST['chunk'] == $_POST['chunks'] - 1 ) {
|
86 |
+
$zip_file_path = $upload_path . '/' . $zip_file_name;
|
87 |
+
if ( $zip_file_handle = fopen( $zip_file_path, 'wb' ) ) {
|
88 |
+
//fetch chunks in order
|
89 |
+
for ( $i = 0; $i < $_POST['chunks']; $i ++ ) {
|
90 |
+
$chunk_file = $upload_path . '/' . $zip_file_name . '_' . $i . '.zip.tmp';
|
91 |
+
if ( $rh = fopen( $chunk_file, 'rb' ) ) {
|
92 |
+
while ( $line = fread( $rh, 32768 ) ) {
|
93 |
+
fwrite( $zip_file_handle, $line );
|
94 |
+
}
|
95 |
+
fclose( $rh );
|
96 |
+
@unlink( $chunk_file );
|
97 |
+
}
|
98 |
+
}
|
99 |
+
fclose( $zip_file_handle );
|
100 |
+
|
101 |
+
$status['file'] = $zip_file_path;
|
102 |
+
|
103 |
+
//File is finished uploading now move to backup project folder
|
104 |
+
|
105 |
+
//remove the suffix
|
106 |
+
$file_name = substr( basename( $zip_file_path ), 0, - 4 );
|
107 |
+
|
108 |
+
//strip off the suffix
|
109 |
+
$prefix = substr( $file_name, 0, 6 );
|
110 |
+
$suffix = '';
|
111 |
+
$folder_name = '';
|
112 |
+
|
113 |
+
if ( ( $str_pos = strpos( $file_name, '-main-' ) ) !== false ) {
|
114 |
+
$suffix = substr( $file_name, $str_pos );
|
115 |
+
$folder_name = str_replace( $suffix, '', $file_name );
|
116 |
+
}
|
117 |
+
|
118 |
+
if ( ( $str_pos = strpos( $file_name, '-others-' ) ) !== false ) {
|
119 |
+
$suffix = substr( $file_name, $str_pos );
|
120 |
+
$folder_name = str_replace( $suffix, '', $file_name );
|
121 |
+
}
|
122 |
+
|
123 |
+
if ( ( $str_pos = strpos( $file_name, '-plugins-' ) ) !== false ) {
|
124 |
+
$suffix = substr( $file_name, $str_pos );
|
125 |
+
$folder_name = str_replace( $suffix, '', $file_name );
|
126 |
+
}
|
127 |
+
|
128 |
+
if ( ( $str_pos = strpos( $file_name, '-themes-' ) ) !== false ) {
|
129 |
+
$suffix = substr( $file_name, $str_pos );
|
130 |
+
$folder_name = str_replace( $suffix, '', $file_name );
|
131 |
+
}
|
132 |
+
|
133 |
+
if ( ( $str_pos = strpos( $file_name, '-uploads-' ) ) !== false ) {
|
134 |
+
$suffix = substr( $file_name, $str_pos );
|
135 |
+
$folder_name = str_replace( $suffix, '', $file_name );
|
136 |
+
}
|
137 |
+
|
138 |
+
//Is this a BackItUp archive
|
139 |
+
if ( empty( $folder_name ) || empty( $suffix ) || 'Backup' != $prefix ) {
|
140 |
+
$logger->log_error(__METHOD__,'Upload does not appear to be a WP BackItUp backup archive');
|
141 |
+
echo json_encode( array( 'error' => sprintf( __( "Upload does not appear to be a WP BackItUp backup archive file.",WPBACKITUP__NAMESPACE ) ) ) );
|
142 |
+
unlink( $zip_file_path );//get rid of it
|
143 |
+
exit;
|
144 |
+
}
|
145 |
+
|
146 |
+
//Does folder exist
|
147 |
+
$backup_archive_folder = WPBACKITUP__BACKUP_PATH . '/' . $folder_name;
|
148 |
+
if ( ! is_dir( $backup_archive_folder ) ) {
|
149 |
+
if ( ! mkdir( $backup_archive_folder, 0755 ) ) {
|
150 |
+
$logger->log_error(__METHOD__,'Upload directory is not writable');
|
151 |
+
echo json_encode( array( 'error' => sprintf( __( "Upload directory is not writable, or does not exist.", WPBACKITUP__NAMESPACE ) ) ) );
|
152 |
+
exit;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
//move the file to the archive folder
|
157 |
+
//will overwrite if exists
|
158 |
+
$target_file = $backup_archive_folder . "/" . basename( $zip_file_path );
|
159 |
+
if ( ! rename( $zip_file_path, $target_file ) ) {
|
160 |
+
$logger->log_error(__METHOD__,'Cant move zip file to backup folder');
|
161 |
+
echo json_encode( array( 'error' => sprintf( __( "Could not import file into WP BackItUp backup set.",WPBACKITUP__NAMESPACE ) ) ) );
|
162 |
+
exit;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
// send the uploaded file url in response
|
169 |
+
$response['success'] = $status['url'];
|
170 |
+
echo json_encode( $response );
|
171 |
+
exit;
|
172 |
+
|
173 |
+
|
174 |
+
/******************/
|
175 |
+
/*** Functions ***/
|
176 |
+
/******************/
|
lib/includes/{viewlog.php → handler_viewlog.php}
RENAMED
@@ -1,22 +1,28 @@
|
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (viewlog)');
|
|
|
2 |
|
3 |
|
4 |
if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
5 |
-
&& isset($_REQUEST['
|
6 |
|
7 |
if ( wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-viewlog')) {
|
8 |
|
9 |
-
$
|
10 |
-
$
|
|
|
11 |
|
12 |
if(file_exists($log_path) ) {
|
13 |
-
|
14 |
-
header("Content-Disposition: attachment; filename
|
|
|
|
|
|
|
15 |
header("Content-Length: ".filesize($log_path));
|
|
|
16 |
ob_get_clean();
|
17 |
readfile($log_path);
|
18 |
if (ob_get_level()>1) ob_end_flush();
|
19 |
-
|
20 |
}
|
21 |
}
|
22 |
}
|
@@ -27,8 +33,6 @@ header("Content-Disposition: attachment; filename=empty.log");
|
|
27 |
header("Content-Length: 100");
|
28 |
ob_get_clean();
|
29 |
echo('No log file found.'. PHP_EOL);
|
30 |
-
//echo($_REQUEST['_wpnonce']. PHP_EOL);
|
31 |
-
//echo($_REQUEST['viewlog_log']. PHP_EOL);
|
32 |
if (ob_get_level()>1) ob_end_flush();
|
33 |
|
34 |
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (viewlog)');
|
2 |
+
@set_time_limit(WPBACKITUP__SCRIPT_TIMEOUT_SECONDS);
|
3 |
|
4 |
|
5 |
if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
6 |
+
&& isset($_REQUEST['backup_name']) && !empty($_REQUEST['backup_name']) ){
|
7 |
|
8 |
if ( wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-viewlog')) {
|
9 |
|
10 |
+
$backup_folder = $_REQUEST['backup_name'];
|
11 |
+
$log_filename = $_REQUEST['backup_name']. '.log';
|
12 |
+
$log_path = WPBACKITUP__BACKUP_PATH .'/' .$backup_folder .'/' .$log_filename ;
|
13 |
|
14 |
if(file_exists($log_path) ) {
|
15 |
+
|
16 |
+
header("Content-Disposition: attachment; filename=\"" . basename( $log_path ) . "\";" );
|
17 |
+
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
18 |
+
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT" );
|
19 |
+
header("Content-type: octet/stream");
|
20 |
header("Content-Length: ".filesize($log_path));
|
21 |
+
|
22 |
ob_get_clean();
|
23 |
readfile($log_path);
|
24 |
if (ob_get_level()>1) ob_end_flush();
|
25 |
+
exit();
|
26 |
}
|
27 |
}
|
28 |
}
|
33 |
header("Content-Length: 100");
|
34 |
ob_get_clean();
|
35 |
echo('No log file found.'. PHP_EOL);
|
|
|
|
|
36 |
if (ob_get_level()>1) ob_end_flush();
|
37 |
|
38 |
|
lib/includes/job_backup.php
CHANGED
@@ -25,22 +25,20 @@ if( !class_exists( 'WPBackItUp_SQL' ) ) {
|
|
25 |
include_once 'class-sql.php';
|
26 |
}
|
27 |
|
28 |
-
// include backup class
|
29 |
if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
30 |
include_once 'class-backup.php';
|
31 |
}
|
32 |
|
33 |
-
// include logger class
|
34 |
if( !class_exists( 'WPBackItUp_Zip' ) ) {
|
35 |
include_once 'class-zip.php';
|
36 |
}
|
37 |
|
38 |
-
|
39 |
if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
|
40 |
include_once 'class-filesystem.php';
|
41 |
}
|
42 |
|
43 |
-
|
44 |
if( !class_exists( 'WPBackItUp_Job' ) ) {
|
45 |
include_once 'class-job.php';
|
46 |
}
|
@@ -66,9 +64,8 @@ $status_array = array(
|
|
66 |
'backup_plugins'=>$inactive,
|
67 |
'backup_uploads'=>$inactive,
|
68 |
'backup_other'=>$inactive,
|
69 |
-
'finalize_backup'=>$inactive,
|
70 |
'validate_backup'=>$inactive,
|
71 |
-
'
|
72 |
);
|
73 |
|
74 |
|
@@ -134,7 +131,6 @@ if ($backup_job){
|
|
134 |
return;
|
135 |
}
|
136 |
|
137 |
-
|
138 |
//Should only get here when there is a task to run
|
139 |
$logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Run Backup task:' .$current_task);
|
140 |
|
@@ -163,65 +159,67 @@ if ($backup_error) {
|
|
163 |
|
164 |
//Check for error type
|
165 |
switch ($error_task) {
|
166 |
-
case "
|
167 |
set_status('preparing',$active,true);
|
168 |
write_fatal_error_status('2101');
|
169 |
end_backup(2101, false);
|
170 |
break;
|
171 |
|
172 |
-
case "
|
173 |
set_status( 'backupdb', $active, true );
|
174 |
write_fatal_error_status( '2104' );
|
175 |
end_backup( 2104, false );
|
176 |
break;
|
177 |
|
178 |
-
case "
|
179 |
set_status( 'infofile', $active, true );
|
180 |
write_fatal_error_status( '2105' );
|
181 |
end_backup( 2105, false );
|
182 |
break;
|
183 |
|
184 |
-
case "
|
185 |
set_status( 'backup_themes', $active, true );
|
186 |
write_fatal_error_status( '2120' );
|
187 |
end_backup( 2120, false );
|
188 |
break;
|
189 |
|
190 |
-
case "
|
191 |
set_status( 'backup_plugins', $active, true );
|
192 |
write_fatal_error_status( '2121' );
|
193 |
end_backup( 2121, false );
|
194 |
break;
|
195 |
|
196 |
-
case "
|
197 |
set_status( 'backup_uploads', $active, true );
|
198 |
write_fatal_error_status( '2122' );
|
199 |
end_backup( 2122, false );
|
200 |
break;
|
201 |
|
202 |
-
case "
|
203 |
set_status( 'backup_other', $active, true );
|
204 |
write_fatal_error_status( '2123' );
|
205 |
end_backup( 2123, false );
|
206 |
break;
|
207 |
|
208 |
-
case "
|
209 |
-
set_status( 'finalize_backup', $active, true );
|
210 |
-
write_fatal_error_status( '2109' );
|
211 |
-
end_backup( 2109, false );
|
212 |
-
break;
|
213 |
-
|
214 |
-
case "validate_backup":
|
215 |
set_status( 'validate_backup', $active, true );
|
216 |
write_fatal_error_status( '2126' );
|
217 |
end_backup( 2126, false );
|
218 |
break;
|
219 |
|
220 |
-
case "
|
221 |
-
set_status( '
|
222 |
-
|
|
|
223 |
break;
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
default:
|
226 |
write_warning_status( '2999' );
|
227 |
end_backup( 2999, false );
|
@@ -231,7 +229,7 @@ if ($backup_error) {
|
|
231 |
}
|
232 |
|
233 |
//Cleanup Task
|
234 |
-
if ('
|
235 |
|
236 |
//Init
|
237 |
$logger->log('***BEGIN BACKUP***');
|
@@ -262,8 +260,9 @@ if ('cleanup_prev'==$current_task) {
|
|
262 |
//*** END Check Dependencies ***
|
263 |
|
264 |
|
|
|
265 |
//Cleanup any backups that didnt finish normally
|
266 |
-
|
267 |
|
268 |
//Make sure wpbackitup_backups exists
|
269 |
if (! $wp_backup->backup_root_folder_exists() ){
|
@@ -289,6 +288,27 @@ if ('cleanup_prev'==$current_task) {
|
|
289 |
end_backup(102,false);
|
290 |
}
|
291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
set_status('preparing',$complete,false);
|
293 |
$backup_job->set_task_complete();
|
294 |
|
@@ -298,7 +318,7 @@ if ('cleanup_prev'==$current_task) {
|
|
298 |
|
299 |
|
300 |
//Backup the database
|
301 |
-
if ('
|
302 |
$logger->log( '**BEGIN SQL EXPORT**' );
|
303 |
write_response_processing( "Create database export" );
|
304 |
set_status( 'backupdb', $active, true );
|
@@ -307,7 +327,7 @@ if ('backup_db'==$current_task) {
|
|
307 |
$backup_job->set_task_error('104');
|
308 |
|
309 |
write_fatal_error_status( '104' );
|
310 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
311 |
end_backup( 104, false );
|
312 |
}
|
313 |
|
@@ -320,19 +340,39 @@ if ('backup_db'==$current_task) {
|
|
320 |
}
|
321 |
|
322 |
//Extract the site info
|
323 |
-
if ('
|
324 |
$logger->log( '**SITE INFO**' );
|
325 |
write_response_processing( "Retrieve Site Info" );
|
326 |
set_status( 'infofile', $active, true );
|
327 |
|
328 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
$backup_job->set_task_error('105');
|
330 |
|
331 |
write_fatal_error_status( '105' );
|
332 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
333 |
end_backup( 105, false );
|
334 |
}
|
335 |
|
|
|
|
|
|
|
336 |
set_status( 'infofile', $complete, false );
|
337 |
$backup_job->set_task_complete();
|
338 |
|
@@ -342,184 +382,205 @@ if ('backup_siteinfo'==$current_task) {
|
|
342 |
}
|
343 |
|
344 |
//Backup the themes
|
345 |
-
if ('
|
346 |
-
$logger->log(
|
347 |
write_response_processing( "Backup themes " );
|
348 |
set_status( 'backup_themes', $active, true );
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
|
354 |
set_status( 'backup_themes', $complete, false );
|
355 |
$backup_job->set_task_complete();
|
356 |
$logger->log('**END BACKUP THEMES TASK**');
|
357 |
-
|
358 |
-
|
359 |
-
case "error":
|
360 |
-
$logger->log('Error backing up themes.');
|
361 |
-
|
362 |
-
$backup_job->set_task_error('120');
|
363 |
-
|
364 |
-
write_fatal_error_status( '120' );
|
365 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
366 |
-
end_backup( 120, false );
|
367 |
-
break;
|
368 |
-
|
369 |
-
case "continue":
|
370 |
-
$logger->log('Continue backing up themes.');
|
371 |
-
$backup_job->set_task_queued();
|
372 |
-
break;
|
373 |
}
|
374 |
|
375 |
return;
|
376 |
}
|
377 |
|
378 |
//Backup the plugins
|
379 |
-
if ('
|
380 |
$logger->log( '**BACKUP PLUGINS TASK**' );
|
381 |
write_response_processing( "Backup plugins " );
|
382 |
set_status( 'backup_plugins', $active, true );
|
383 |
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
set_status( 'backup_plugins', $complete, false );
|
390 |
$backup_job->set_task_complete();
|
391 |
$logger->log('**END BACKUP PLUGINS TASK**');
|
392 |
-
|
393 |
-
|
394 |
-
case "error":
|
395 |
-
$logger->log('Error backing up plugins.');
|
396 |
-
|
397 |
-
$backup_job->set_task_error('121');
|
398 |
-
write_fatal_error_status( '121' );
|
399 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
400 |
-
end_backup( 121, false );
|
401 |
-
break;
|
402 |
-
|
403 |
-
case "continue":
|
404 |
-
$logger->log('Continue backing up plugins.');
|
405 |
-
|
406 |
-
$backup_job->set_task_queued();
|
407 |
-
break;
|
408 |
}
|
409 |
|
410 |
return;
|
411 |
}
|
412 |
|
|
|
413 |
//Backup the uploads
|
414 |
-
if ('
|
415 |
$logger->log( '**BACKUP UPLOADS TASK**' );
|
416 |
write_response_processing( "Backup uploads " );
|
417 |
set_status( 'backup_uploads', $active, true );
|
418 |
|
419 |
-
|
420 |
-
|
421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
|
|
|
|
|
|
423 |
set_status( 'backup_uploads', $complete, false );
|
424 |
$backup_job->set_task_complete();
|
425 |
-
$logger->log('**END BACKUP UPLOADS TASK**');
|
426 |
-
|
427 |
-
|
428 |
-
case "error":
|
429 |
-
$logger->log('Error backing up uploads.');
|
430 |
-
|
431 |
-
$backup_job->set_task_error('122');
|
432 |
-
write_fatal_error_status( '122' );
|
433 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
434 |
-
end_backup( 122, false );
|
435 |
-
break;
|
436 |
-
|
437 |
-
case "continue":
|
438 |
-
$logger->log('Continue backing up uploads.');
|
439 |
-
|
440 |
-
$backup_job->set_task_queued();
|
441 |
-
break;
|
442 |
}
|
443 |
|
444 |
return;
|
445 |
}
|
446 |
|
447 |
//Backup all the other content in the wp-content root
|
448 |
-
if ('
|
449 |
$logger->log( '**BACKUP OTHER TASK**' );
|
450 |
write_response_processing( "Backup other files " );
|
451 |
set_status( 'backup_other', $active, true );
|
452 |
|
453 |
-
|
454 |
-
|
455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
|
457 |
-
set_status('backup_other'
|
458 |
$backup_job->set_task_complete();
|
459 |
-
$logger->log('**END BACKUP OTHER TASK**');
|
460 |
-
|
461 |
-
|
462 |
-
case "error":
|
463 |
-
$logger->log('Error backing up others.');
|
464 |
-
$backup_job->set_task_error('123');
|
465 |
-
|
466 |
-
write_fatal_error_status( '123' );
|
467 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
468 |
-
end_backup( 123, false );
|
469 |
-
break;
|
470 |
|
471 |
-
case "continue":
|
472 |
-
$logger->log('Continue backing up others.');
|
473 |
-
$backup_job->set_task_queued();
|
474 |
-
break;
|
475 |
}
|
476 |
|
477 |
return;
|
478 |
-
|
479 |
}
|
480 |
|
481 |
-
|
482 |
//ENCRYPT CONTENT TASK
|
483 |
//wp-config.php
|
484 |
//db backup
|
485 |
|
486 |
-
//Zip up the backup folder
|
487 |
-
if ('finalize_backup'==$current_task) {
|
488 |
-
$logger->log( '**FINALIZE BACKUP**' );
|
489 |
-
write_response_processing( "Compress Backup " );
|
490 |
-
set_status( 'finalize_backup', $active, true );
|
491 |
-
|
492 |
-
if ( ! $wp_backup->backup_site_data() ) {
|
493 |
-
$backup_job->set_task_error('108');
|
494 |
-
|
495 |
-
write_fatal_error_status( '108' );
|
496 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
497 |
-
end_backup( 108, false );
|
498 |
-
}
|
499 |
-
|
500 |
-
//rename the tmp file to zip
|
501 |
-
if ( ! $wp_backup->finalize_zip_file() ) {
|
502 |
-
$backup_job->set_task_error('109');
|
503 |
-
|
504 |
-
write_fatal_error_status( '109' );
|
505 |
-
cleanup_on_failure( $wp_backup->backup_project_path );
|
506 |
-
end_backup( 109, false );
|
507 |
-
}
|
508 |
-
|
509 |
-
set_status( 'finalize_backup', $complete, false );
|
510 |
-
$backup_job->set_task_complete();
|
511 |
-
|
512 |
-
$logger->log( '**END FINALIZE BACKUP**' );
|
513 |
-
return;
|
514 |
-
|
515 |
-
}
|
516 |
-
|
517 |
-
|
518 |
-
//If we get this far change the extension
|
519 |
-
$wp_backup->set_zip_extension();
|
520 |
-
|
521 |
//Validate the backup IF logging is turned on - reporting only
|
522 |
-
if ('
|
523 |
//Validate the content if logging is on
|
524 |
$logger->log('**VALIDATE CONTENT**');
|
525 |
|
@@ -527,10 +588,11 @@ if ('validate_backup'==$current_task) {
|
|
527 |
set_status( 'validate_backup', $active, true );
|
528 |
|
529 |
if ($WPBackitup->logging()){
|
530 |
-
|
531 |
-
|
532 |
}
|
533 |
|
|
|
|
|
534 |
set_status( 'validate_backup', $complete, false );
|
535 |
$backup_job->set_task_complete();
|
536 |
$logger->log('**END VALIDATE CONTENT**');
|
@@ -538,33 +600,70 @@ if ('validate_backup'==$current_task) {
|
|
538 |
return;
|
539 |
}
|
540 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
set_status( 'cleanup', $active, true );
|
547 |
|
548 |
if ( ! $wp_backup->cleanup_current_backup() ) {
|
549 |
//Warning - no need to error job
|
550 |
write_warning_status( '106' );
|
551 |
}
|
552 |
|
553 |
-
//
|
554 |
-
$wp_backup->
|
|
|
555 |
|
556 |
-
|
|
|
|
|
|
|
|
|
|
|
557 |
$backup_job->set_task_complete();
|
558 |
|
559 |
-
$logger->log( '**END
|
|
|
560 |
}
|
561 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
//SUCCESS- End Job!
|
563 |
set_status_success();
|
564 |
write_response_file_success();
|
565 |
$WPBackitup->increment_successful_backup_count();
|
566 |
-
end_backup(null,true);
|
|
|
567 |
|
|
|
568 |
/******************/
|
569 |
/*** Functions ***/
|
570 |
/******************/
|
@@ -588,9 +687,9 @@ function end_backup($err=null, $success=null){
|
|
588 |
$logger->log('Zip up all the logs.');
|
589 |
//Zip up all the logs in the log folder
|
590 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
591 |
-
$zip_file_path = $
|
592 |
|
593 |
-
//copy/
|
594 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
595 |
$logger->log_info(__METHOD__,"Copy WP Debug: " .$wpdebug_file_path);
|
596 |
if (file_exists($wpdebug_file_path)) {
|
@@ -628,10 +727,9 @@ function end_backup($err=null, $success=null){
|
|
628 |
$logger->close_file();
|
629 |
|
630 |
//Move the log if it exists
|
631 |
-
$newlogFilePath = $wp_backup->
|
632 |
if (null!=$success && file_exists($logFilePath)){
|
633 |
-
|
634 |
-
unlink($logFilePath);
|
635 |
}
|
636 |
|
637 |
echo('Backup has completed');
|
@@ -730,7 +828,7 @@ function cleanup_on_failure($path){
|
|
730 |
$logger->log('Cleanup On Fail suspended: debug on.');
|
731 |
}
|
732 |
else{
|
733 |
-
$wp_backup->
|
734 |
}
|
735 |
}
|
736 |
|
@@ -847,7 +945,7 @@ function write_response_file_success() {
|
|
847 |
$jsonResponse = new stdClass();
|
848 |
$jsonResponse->backupStatus = 'success';
|
849 |
$jsonResponse->backupMessage = 'success';
|
850 |
-
$jsonResponse->
|
851 |
$jsonResponse->backupLicense = $WPBackitup->license_active();
|
852 |
$jsonResponse->backupRetained = $wp_backup->backup_retained_number;
|
853 |
|
25 |
include_once 'class-sql.php';
|
26 |
}
|
27 |
|
|
|
28 |
if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
29 |
include_once 'class-backup.php';
|
30 |
}
|
31 |
|
|
|
32 |
if( !class_exists( 'WPBackItUp_Zip' ) ) {
|
33 |
include_once 'class-zip.php';
|
34 |
}
|
35 |
|
36 |
+
|
37 |
if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
|
38 |
include_once 'class-filesystem.php';
|
39 |
}
|
40 |
|
41 |
+
|
42 |
if( !class_exists( 'WPBackItUp_Job' ) ) {
|
43 |
include_once 'class-job.php';
|
44 |
}
|
64 |
'backup_plugins'=>$inactive,
|
65 |
'backup_uploads'=>$inactive,
|
66 |
'backup_other'=>$inactive,
|
|
|
67 |
'validate_backup'=>$inactive,
|
68 |
+
'finalize_backup'=>$inactive,
|
69 |
);
|
70 |
|
71 |
|
131 |
return;
|
132 |
}
|
133 |
|
|
|
134 |
//Should only get here when there is a task to run
|
135 |
$logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Run Backup task:' .$current_task);
|
136 |
|
159 |
|
160 |
//Check for error type
|
161 |
switch ($error_task) {
|
162 |
+
case "task_preparing":
|
163 |
set_status('preparing',$active,true);
|
164 |
write_fatal_error_status('2101');
|
165 |
end_backup(2101, false);
|
166 |
break;
|
167 |
|
168 |
+
case "task_backup_db":
|
169 |
set_status( 'backupdb', $active, true );
|
170 |
write_fatal_error_status( '2104' );
|
171 |
end_backup( 2104, false );
|
172 |
break;
|
173 |
|
174 |
+
case "task_backup_siteinfo":
|
175 |
set_status( 'infofile', $active, true );
|
176 |
write_fatal_error_status( '2105' );
|
177 |
end_backup( 2105, false );
|
178 |
break;
|
179 |
|
180 |
+
case "task_backup_themes":
|
181 |
set_status( 'backup_themes', $active, true );
|
182 |
write_fatal_error_status( '2120' );
|
183 |
end_backup( 2120, false );
|
184 |
break;
|
185 |
|
186 |
+
case "task_backup_plugins":
|
187 |
set_status( 'backup_plugins', $active, true );
|
188 |
write_fatal_error_status( '2121' );
|
189 |
end_backup( 2121, false );
|
190 |
break;
|
191 |
|
192 |
+
case "task_backup_uploads":
|
193 |
set_status( 'backup_uploads', $active, true );
|
194 |
write_fatal_error_status( '2122' );
|
195 |
end_backup( 2122, false );
|
196 |
break;
|
197 |
|
198 |
+
case "task_backup_other":
|
199 |
set_status( 'backup_other', $active, true );
|
200 |
write_fatal_error_status( '2123' );
|
201 |
end_backup( 2123, false );
|
202 |
break;
|
203 |
|
204 |
+
case "task_validate_backup":
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
set_status( 'validate_backup', $active, true );
|
206 |
write_fatal_error_status( '2126' );
|
207 |
end_backup( 2126, false );
|
208 |
break;
|
209 |
|
210 |
+
case "task_finalize_backup":
|
211 |
+
set_status( 'finalize_backup', $active, true );
|
212 |
+
write_fatal_error_status( '2109' );
|
213 |
+
end_backup( 2109, false );
|
214 |
break;
|
215 |
|
216 |
+
|
217 |
+
|
218 |
+
// case "task_cleanup_current": //Dont end backup on this error
|
219 |
+
// set_status( 'cleanup', $active, true );
|
220 |
+
// write_warning_status( '2106' );
|
221 |
+
// break;
|
222 |
+
|
223 |
default:
|
224 |
write_warning_status( '2999' );
|
225 |
end_backup( 2999, false );
|
229 |
}
|
230 |
|
231 |
//Cleanup Task
|
232 |
+
if ('task_preparing'==$current_task) {
|
233 |
|
234 |
//Init
|
235 |
$logger->log('***BEGIN BACKUP***');
|
260 |
//*** END Check Dependencies ***
|
261 |
|
262 |
|
263 |
+
//This is handled in the cleanup jobs now
|
264 |
//Cleanup any backups that didnt finish normally
|
265 |
+
//$wp_backup->cleanup_unfinished_backups();
|
266 |
|
267 |
//Make sure wpbackitup_backups exists
|
268 |
if (! $wp_backup->backup_root_folder_exists() ){
|
288 |
end_backup(102,false);
|
289 |
}
|
290 |
|
291 |
+
//Generate the list of files to be backed up and update the tasks info
|
292 |
+
|
293 |
+
$plugins_file_list = $wp_backup->get_plugins_file_list();
|
294 |
+
$backup_job->update_job_meta('backup_plugins_filelist',wp_slash($plugins_file_list));
|
295 |
+
$backup_job->update_job_meta('backup_plugins_filelist_remaining',wp_slash($plugins_file_list));
|
296 |
+
|
297 |
+
$themes_file_list = $wp_backup->get_themes_file_list();
|
298 |
+
$backup_job->update_job_meta('backup_themes_filelist',wp_slash($themes_file_list));
|
299 |
+
$backup_job->update_job_meta('backup_themes_filelist_remaining',wp_slash($themes_file_list));
|
300 |
+
|
301 |
+
//some folders excluded
|
302 |
+
$uploads_file_list = $wp_backup->get_uploads_file_list();
|
303 |
+
$backup_job->update_job_meta('backup_uploads_filelist',wp_slash($uploads_file_list));
|
304 |
+
$backup_job->update_job_meta('backup_uploads_filelist_remaining',wp_slash($uploads_file_list));
|
305 |
+
|
306 |
+
//some folders excluded
|
307 |
+
$others_file_list = $wp_backup->get_other_file_list();
|
308 |
+
$backup_job->update_job_meta('backup_others_filelist',wp_slash($others_file_list));
|
309 |
+
$backup_job->update_job_meta('backup_others_filelist_remaining',wp_slash($others_file_list));
|
310 |
+
|
311 |
+
|
312 |
set_status('preparing',$complete,false);
|
313 |
$backup_job->set_task_complete();
|
314 |
|
318 |
|
319 |
|
320 |
//Backup the database
|
321 |
+
if ('task_backup_db'==$current_task) {
|
322 |
$logger->log( '**BEGIN SQL EXPORT**' );
|
323 |
write_response_processing( "Create database export" );
|
324 |
set_status( 'backupdb', $active, true );
|
327 |
$backup_job->set_task_error('104');
|
328 |
|
329 |
write_fatal_error_status( '104' );
|
330 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
331 |
end_backup( 104, false );
|
332 |
}
|
333 |
|
340 |
}
|
341 |
|
342 |
//Extract the site info
|
343 |
+
if ('task_backup_siteinfo'==$current_task) {
|
344 |
$logger->log( '**SITE INFO**' );
|
345 |
write_response_processing( "Retrieve Site Info" );
|
346 |
set_status( 'infofile', $active, true );
|
347 |
|
348 |
+
if ( $wp_backup->create_siteinfo_file() ) {
|
349 |
+
|
350 |
+
//Add site Info and SQL data to main zip
|
351 |
+
$site_data_suffix='main';
|
352 |
+
$source_site_data_root = $wp_backup->backup_project_path;
|
353 |
+
$target_site_data_root = 'site-data';
|
354 |
+
|
355 |
+
$site_data_files = array_filter(glob($wp_backup->backup_project_path. '*.{txt,sql}',GLOB_BRACE), 'is_file');
|
356 |
+
$site_data_complete = $wp_backup->backup_file_list( $source_site_data_root, $target_site_data_root, $site_data_suffix, $site_data_files, WPBACKITUP__PLUGINS_BATCH_SIZE );
|
357 |
+
if ( $site_data_complete == 'error' ) {
|
358 |
+
$backup_job->set_task_error('105');
|
359 |
+
|
360 |
+
write_fatal_error_status( '105' );
|
361 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
362 |
+
end_backup( 105, false );
|
363 |
+
}
|
364 |
+
} else {
|
365 |
+
//Site data could be extracted
|
366 |
$backup_job->set_task_error('105');
|
367 |
|
368 |
write_fatal_error_status( '105' );
|
369 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
370 |
end_backup( 105, false );
|
371 |
}
|
372 |
|
373 |
+
//get rid of the SQL and sitedata file - will check again at end in cleanup
|
374 |
+
$wp_backup->delete_site_data_files();
|
375 |
+
|
376 |
set_status( 'infofile', $complete, false );
|
377 |
$backup_job->set_task_complete();
|
378 |
|
382 |
}
|
383 |
|
384 |
//Backup the themes
|
385 |
+
if ('task_backup_themes'==$current_task) {
|
386 |
+
$logger->log('**BACKUP THEMES TASK**' );
|
387 |
write_response_processing( "Backup themes " );
|
388 |
set_status( 'backup_themes', $active, true );
|
389 |
|
390 |
+
$source_themes_root = WPBACKITUP__THEMES_ROOT_PATH;
|
391 |
+
$target_theme_root = 'wp-content-themes';
|
392 |
+
$themes_suffix='themes';
|
393 |
+
$themes_file_list = $backup_job->get_job_meta('backup_themes_filelist_remaining');
|
394 |
+
$themes_file_list_count= count($themes_file_list);
|
395 |
+
|
396 |
+
$themes_remaining_files = $wp_backup->backup_file_list($source_themes_root,$target_theme_root,$themes_suffix,$themes_file_list,WPBACKITUP__THEMES_BATCH_SIZE);
|
397 |
+
if ($themes_remaining_files=='error') {
|
398 |
+
//ERROR
|
399 |
+
$logger->log_error(__METHOD__,'Error backing up themes.');
|
400 |
+
$backup_job->set_task_error('120');
|
401 |
+
write_fatal_error_status( '120' );
|
402 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
403 |
+
end_backup( 120, false );
|
404 |
+
}else{
|
405 |
+
//update the file list with remaining files
|
406 |
+
$backup_job->update_job_meta('backup_themes_filelist_remaining',wp_slash($themes_remaining_files));
|
407 |
+
|
408 |
+
$themes_remaining_files_count= count($themes_remaining_files);
|
409 |
+
$themes_batch_count = $themes_file_list_count-$themes_remaining_files_count;
|
410 |
+
$logger->log('Backed up in this batch:' .$themes_batch_count);
|
411 |
+
|
412 |
+
$logger->log('Themes remaining:' .$themes_remaining_files_count);
|
413 |
+
if ($themes_remaining_files_count>0){
|
414 |
+
//CONTINUE
|
415 |
+
$logger->log_info(__METHOD__,'Continue backing up themes.');
|
416 |
+
$backup_job->set_task_queued();
|
417 |
+
}else{
|
418 |
+
//COMPLETE
|
419 |
+
$logger->log_info(__METHOD__,'Complete - All themes backed up.');
|
420 |
|
421 |
set_status( 'backup_themes', $complete, false );
|
422 |
$backup_job->set_task_complete();
|
423 |
$logger->log('**END BACKUP THEMES TASK**');
|
424 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
}
|
426 |
|
427 |
return;
|
428 |
}
|
429 |
|
430 |
//Backup the plugins
|
431 |
+
if ('task_backup_plugins'==$current_task) {
|
432 |
$logger->log( '**BACKUP PLUGINS TASK**' );
|
433 |
write_response_processing( "Backup plugins " );
|
434 |
set_status( 'backup_plugins', $active, true );
|
435 |
|
436 |
+
$source_plugins_root = WPBACKITUP__PLUGINS_ROOT_PATH;
|
437 |
+
$target_plugins_root = 'wp-content-plugins';
|
438 |
+
$plugins_suffix='plugins';
|
439 |
+
$plugins_file_list = $backup_job->get_job_meta('backup_plugins_filelist_remaining');
|
440 |
+
$plugins_file_list_count= count($plugins_file_list);
|
441 |
+
|
442 |
+
$plugins_remaining_files = $wp_backup->backup_file_list($source_plugins_root,$target_plugins_root,$plugins_suffix,$plugins_file_list,WPBACKITUP__PLUGINS_BATCH_SIZE);
|
443 |
+
if ($plugins_remaining_files=='error') {
|
444 |
+
//ERROR
|
445 |
+
$logger->log('Error backing up plugins.');
|
446 |
+
|
447 |
+
$backup_job->set_task_error('121');
|
448 |
+
write_fatal_error_status( '121' );
|
449 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
450 |
+
end_backup( 121, false );
|
451 |
+
} else {
|
452 |
+
//update the file list with remaining files
|
453 |
+
$backup_job->update_job_meta('backup_plugins_filelist_remaining',wp_slash($plugins_remaining_files));
|
454 |
+
|
455 |
+
$plugins_remaining_files_count= count($plugins_remaining_files);
|
456 |
+
$plugins_batch_count = $plugins_file_list_count-$plugins_remaining_files_count;
|
457 |
+
$logger->log('Backed up in this batch:' .$plugins_batch_count);
|
458 |
+
|
459 |
+
$logger->log('Plugins remaining:' .$plugins_remaining_files_count);
|
460 |
+
if ($plugins_remaining_files_count>0){
|
461 |
+
//CONTINUE
|
462 |
+
$logger->log('Continue backing up plugins.');
|
463 |
+
$backup_job->set_task_queued();
|
464 |
+
} else{
|
465 |
+
//COMPLETE
|
466 |
+
$logger->log('Complete - All plugins backed up.');
|
467 |
set_status( 'backup_plugins', $complete, false );
|
468 |
$backup_job->set_task_complete();
|
469 |
$logger->log('**END BACKUP PLUGINS TASK**');
|
470 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
}
|
472 |
|
473 |
return;
|
474 |
}
|
475 |
|
476 |
+
|
477 |
//Backup the uploads
|
478 |
+
if ('task_backup_uploads'==$current_task) {
|
479 |
$logger->log( '**BACKUP UPLOADS TASK**' );
|
480 |
write_response_processing( "Backup uploads " );
|
481 |
set_status( 'backup_uploads', $active, true );
|
482 |
|
483 |
+
$upload_array = wp_upload_dir();
|
484 |
+
$source_uploads_root = $upload_array['basedir'];
|
485 |
+
$target_uploads_root = 'wp-content-uploads';
|
486 |
+
$uploads_suffix = 'uploads';
|
487 |
+
|
488 |
+
$uploads_file_list = $backup_job->get_job_meta( 'backup_uploads_filelist_remaining' );
|
489 |
+
$uploads_file_list_count = count( $uploads_file_list );
|
490 |
+
|
491 |
+
$batch_size = $WPBackitup->backup_batch_size();
|
492 |
+
|
493 |
+
//exclude zip files from backup
|
494 |
+
$uploads_remaining_files = $wp_backup->backup_file_list( $source_uploads_root, $target_uploads_root, $uploads_suffix, $uploads_file_list,$batch_size,'.zip' );
|
495 |
+
if ( $uploads_remaining_files == 'error' ) {
|
496 |
+
//ERROR
|
497 |
+
$logger->log( 'Error backing up uploads.' );
|
498 |
+
$backup_job->set_task_error( '122' );
|
499 |
+
write_fatal_error_status( '122' );
|
500 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
501 |
+
end_backup( 122, false );
|
502 |
+
} else {
|
503 |
+
//update the file list with remaining files
|
504 |
+
$backup_job->update_job_meta( 'backup_uploads_filelist_remaining', wp_slash($uploads_remaining_files) );
|
505 |
+
|
506 |
+
$uploads_remaining_files_count = count( $uploads_remaining_files );
|
507 |
+
$uploads_batch_count = $uploads_file_list_count - $uploads_remaining_files_count;
|
508 |
+
$logger->log( 'Backed up in this batch:' . $uploads_batch_count );
|
509 |
+
$logger->log( 'Remaining Uploads:' . $uploads_remaining_files_count );
|
510 |
+
if ( $uploads_remaining_files_count > 0 ) {
|
511 |
+
//CONTINUE
|
512 |
+
$logger->log( 'Continue backing up uploads.' );
|
513 |
+
$backup_job->set_task_queued();
|
514 |
|
515 |
+
} else {
|
516 |
+
//COMPLETE
|
517 |
+
$logger->log( 'All uploads backed up.' );
|
518 |
set_status( 'backup_uploads', $complete, false );
|
519 |
$backup_job->set_task_complete();
|
520 |
+
$logger->log( '**END BACKUP UPLOADS TASK**' );
|
521 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
}
|
523 |
|
524 |
return;
|
525 |
}
|
526 |
|
527 |
//Backup all the other content in the wp-content root
|
528 |
+
if ('task_backup_other'==$current_task) {
|
529 |
$logger->log( '**BACKUP OTHER TASK**' );
|
530 |
write_response_processing( "Backup other files " );
|
531 |
set_status( 'backup_other', $active, true );
|
532 |
|
533 |
+
$source_others_root = WPBACKITUP__CONTENT_PATH;
|
534 |
+
$target_others_root = 'wp-content-other';
|
535 |
+
$others_suffix = 'others';
|
536 |
+
|
537 |
+
$others_file_list = $backup_job->get_job_meta( 'backup_others_filelist_remaining' );
|
538 |
+
$others_file_list_count = count( $others_file_list );
|
539 |
+
|
540 |
+
$batch_size = $WPBackitup->backup_batch_size();
|
541 |
+
|
542 |
+
//exclude zip files from backup
|
543 |
+
$others_remaining_files = $wp_backup->backup_file_list( $source_others_root, $target_others_root, $others_suffix, $others_file_list, $batch_size,'.zip' );
|
544 |
+
if ( $others_remaining_files == 'error' ) {
|
545 |
+
//ERROR
|
546 |
+
$logger->log( 'Error backing up others.' );
|
547 |
+
$backup_job->set_task_error( '123' );
|
548 |
+
|
549 |
+
write_fatal_error_status( '123' );
|
550 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
551 |
+
end_backup( 123, false );
|
552 |
+
} else {
|
553 |
+
//update the file list with remaining files
|
554 |
+
$backup_job->update_job_meta( 'backup_others_filelist_remaining', wp_slash($others_remaining_files) );
|
555 |
+
|
556 |
+
$others_remaining_files_count = count( $others_remaining_files );
|
557 |
+
$others_batch_count = $others_file_list_count - $others_remaining_files_count;
|
558 |
+
$logger->log( 'Backed up in this batch:' . $others_batch_count );
|
559 |
+
$logger->log( 'Remaining Others:' . $others_remaining_files_count );
|
560 |
+
if ( $others_remaining_files_count > 0 ) {
|
561 |
+
//CONTINUE
|
562 |
+
$logger->log( 'Continue backing up others.' );
|
563 |
+
$backup_job->set_task_queued();
|
564 |
+
} else {
|
565 |
+
//COMPLETE
|
566 |
+
$logger->log( 'All others backed up.' );
|
567 |
|
568 |
+
set_status( 'backup_other', $complete, false );
|
569 |
$backup_job->set_task_complete();
|
570 |
+
$logger->log( '**END BACKUP OTHER TASK**' );
|
571 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
572 |
|
|
|
|
|
|
|
|
|
573 |
}
|
574 |
|
575 |
return;
|
|
|
576 |
}
|
577 |
|
|
|
578 |
//ENCRYPT CONTENT TASK
|
579 |
//wp-config.php
|
580 |
//db backup
|
581 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
//Validate the backup IF logging is turned on - reporting only
|
583 |
+
if ('task_validate_backup'==$current_task) {
|
584 |
//Validate the content if logging is on
|
585 |
$logger->log('**VALIDATE CONTENT**');
|
586 |
|
588 |
set_status( 'validate_backup', $active, true );
|
589 |
|
590 |
if ($WPBackitup->logging()){
|
591 |
+
//$wp_backup->validate_backup(); --HOW DO I DO THIS
|
|
|
592 |
}
|
593 |
|
594 |
+
sleep(5);//temp UI only
|
595 |
+
|
596 |
set_status( 'validate_backup', $complete, false );
|
597 |
$backup_job->set_task_complete();
|
598 |
$logger->log('**END VALIDATE CONTENT**');
|
600 |
return;
|
601 |
}
|
602 |
|
603 |
+
//Zip up the backup folder
|
604 |
+
if ('task_finalize_backup'==$current_task) {
|
605 |
+
$logger->log( '**FINALIZE BACKUP**' );
|
606 |
+
write_response_processing( "Compress Backup " );
|
607 |
+
set_status( 'finalize_backup', $active, true );
|
608 |
+
|
609 |
+
//Generate manifest
|
610 |
+
if ( ! $wp_backup->create_backup_manifest()) {
|
611 |
+
$backup_job->set_task_error('109');
|
612 |
|
613 |
+
write_fatal_error_status( '109' );
|
614 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
615 |
+
end_backup( 109, false );
|
616 |
+
}
|
|
|
617 |
|
618 |
if ( ! $wp_backup->cleanup_current_backup() ) {
|
619 |
//Warning - no need to error job
|
620 |
write_warning_status( '106' );
|
621 |
}
|
622 |
|
623 |
+
//Rename backup folder
|
624 |
+
if ( ! $wp_backup->rename_backup_folder()) {
|
625 |
+
$backup_job->set_task_error('109');
|
626 |
|
627 |
+
write_fatal_error_status( '109' );
|
628 |
+
//cleanup_on_failure( $wp_backup->backup_project_path );
|
629 |
+
end_backup( 109, false );
|
630 |
+
}
|
631 |
+
|
632 |
+
set_status( 'finalize_backup', $complete, false );
|
633 |
$backup_job->set_task_complete();
|
634 |
|
635 |
+
$logger->log( '**END FINALIZE BACKUP**' );
|
636 |
+
|
637 |
}
|
638 |
|
639 |
+
//If we get this far we have a finalized backup so change the path
|
640 |
+
$wp_backup->set_final_backup_path();
|
641 |
+
|
642 |
+
//Cleanup work folders - handled in cleanup jobs now
|
643 |
+
//if ('task_cleanup_current'==$current_task) {
|
644 |
+
// $logger->log( '**CLEANUP**' );
|
645 |
+
//
|
646 |
+
// write_response_processing( "Cleanup after Backup " );
|
647 |
+
// set_status( 'cleanup', $active, true );
|
648 |
+
//
|
649 |
+
// //Check retention limits and cleanup
|
650 |
+
// $wp_backup->purge_old_files();
|
651 |
+
//
|
652 |
+
// set_status( 'cleanup', $complete, false );
|
653 |
+
// $backup_job->set_task_complete();
|
654 |
+
//
|
655 |
+
// $logger->log( '**END CLEANUP**' );
|
656 |
+
//}
|
657 |
+
|
658 |
+
if ($backup_job->get_job_status()=='complete') {
|
659 |
//SUCCESS- End Job!
|
660 |
set_status_success();
|
661 |
write_response_file_success();
|
662 |
$WPBackitup->increment_successful_backup_count();
|
663 |
+
end_backup( null, true );
|
664 |
+
}
|
665 |
|
666 |
+
exit();
|
667 |
/******************/
|
668 |
/*** Functions ***/
|
669 |
/******************/
|
687 |
$logger->log('Zip up all the logs.');
|
688 |
//Zip up all the logs in the log folder
|
689 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
690 |
+
$zip_file_path = $wp_backup->backup_project_path .'logs_' .$backup_job->backup_id . '.zip';
|
691 |
|
692 |
+
//copy/replace WP debug file
|
693 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
694 |
$logger->log_info(__METHOD__,"Copy WP Debug: " .$wpdebug_file_path);
|
695 |
if (file_exists($wpdebug_file_path)) {
|
727 |
$logger->close_file();
|
728 |
|
729 |
//Move the log if it exists
|
730 |
+
$newlogFilePath = $wp_backup->backup_project_path .$logFileName;
|
731 |
if (null!=$success && file_exists($logFilePath)){
|
732 |
+
rename($logFilePath,$newlogFilePath);
|
|
|
733 |
}
|
734 |
|
735 |
echo('Backup has completed');
|
828 |
$logger->log('Cleanup On Fail suspended: debug on.');
|
829 |
}
|
830 |
else{
|
831 |
+
$wp_backup->cleanup_backups_by_prefix('TMP_');
|
832 |
}
|
833 |
}
|
834 |
|
945 |
$jsonResponse = new stdClass();
|
946 |
$jsonResponse->backupStatus = 'success';
|
947 |
$jsonResponse->backupMessage = 'success';
|
948 |
+
$jsonResponse->backupName = $wp_backup->backup_name;
|
949 |
$jsonResponse->backupLicense = $WPBackitup->license_active();
|
950 |
$jsonResponse->backupRetained = $wp_backup->backup_retained_number;
|
951 |
|
lib/includes/job_cleanup.php
CHANGED
@@ -30,6 +30,10 @@ if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
|
30 |
include_once 'class-backup.php';
|
31 |
}
|
32 |
|
|
|
|
|
|
|
|
|
33 |
// include logger class
|
34 |
if( !class_exists( 'WPBackItUp_Zip' ) ) {
|
35 |
include_once 'class-zip.php';
|
@@ -78,25 +82,24 @@ if (!WPBackItUp_Backup::start()) {
|
|
78 |
}
|
79 |
//**************************//
|
80 |
|
81 |
-
|
82 |
//**************************//
|
83 |
// Task Handling //
|
84 |
//**************************//
|
85 |
-
global $
|
86 |
-
$
|
87 |
$current_task= null;
|
88 |
|
89 |
$backup_error=false;
|
90 |
|
91 |
|
92 |
-
$
|
93 |
$logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Check for available job');
|
94 |
-
if ($
|
95 |
|
96 |
//Get the next task in the stack
|
97 |
-
$next_task = $
|
98 |
if (false!==$next_task){
|
99 |
-
$backup_id=$
|
100 |
$current_task=$next_task;
|
101 |
|
102 |
//If task contains error then timeout has occurred
|
@@ -127,7 +130,7 @@ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Run Backup task
|
|
127 |
//*************************//
|
128 |
|
129 |
//Get the backup ID
|
130 |
-
$job_name = get_job_name($
|
131 |
|
132 |
global $logger;
|
133 |
$logger = new WPBackItUp_Logger(false,null,$job_name);
|
@@ -139,7 +142,7 @@ $wp_backup = new WPBackItUp_Backup($logger,$job_name,$WPBackitup->backup_type);
|
|
139 |
//*** SCHEDULED TASKS ***//
|
140 |
|
141 |
//Run cleanup task
|
142 |
-
if ('
|
143 |
|
144 |
//Init
|
145 |
$logger->log('***BEGIN JOB***');
|
@@ -148,9 +151,26 @@ if ('scheduled_cleanup'==$current_task) {
|
|
148 |
$logger->log('Scheduled Cleanup requested');
|
149 |
|
150 |
$logger->log( '**CLEAN UNFINISHED BACKUPS**' );
|
151 |
-
|
|
|
152 |
$logger->log( '**END CLEAN UNFINISHED BACKUPS**' );
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
$logger->log( '**PURGE OLD FILES**' );
|
155 |
$wp_backup->purge_old_files();
|
156 |
$logger->log( '**END PURGE OLD FILES**' );
|
@@ -172,7 +192,7 @@ if ('scheduled_cleanup'==$current_task) {
|
|
172 |
$file_system->secure_folder( $logs_dir);
|
173 |
$logger->log( '**END SECURE FOLDERS**' );
|
174 |
|
175 |
-
$
|
176 |
|
177 |
}
|
178 |
|
@@ -194,7 +214,7 @@ function get_job_name($timestamp){
|
|
194 |
}
|
195 |
|
196 |
function end_job($err=null, $success=null){
|
197 |
-
global $WPBackitup, $logger, $
|
198 |
$logger->log_info(__METHOD__,"Begin");
|
199 |
|
200 |
WPBackItUp_Backup::end(); //Release the lock
|
@@ -202,7 +222,7 @@ function end_job($err=null, $success=null){
|
|
202 |
$WPBackitup->set_cleanup_lastrun_date($current_datetime);
|
203 |
|
204 |
$util = new WPBackItUp_Utility($logger);
|
205 |
-
$seconds = $util->timestamp_diff_seconds($
|
206 |
|
207 |
$processing_minutes = round($seconds / 60);
|
208 |
$processing_seconds = $seconds % 60;
|
30 |
include_once 'class-backup.php';
|
31 |
}
|
32 |
|
33 |
+
if( !class_exists( 'WPBackItUp_Restore' ) ) {
|
34 |
+
include_once 'class-restore.php';
|
35 |
+
}
|
36 |
+
|
37 |
// include logger class
|
38 |
if( !class_exists( 'WPBackItUp_Zip' ) ) {
|
39 |
include_once 'class-zip.php';
|
82 |
}
|
83 |
//**************************//
|
84 |
|
|
|
85 |
//**************************//
|
86 |
// Task Handling //
|
87 |
//**************************//
|
88 |
+
global $cleanup_job;
|
89 |
+
$cleanup_job=null;
|
90 |
$current_task= null;
|
91 |
|
92 |
$backup_error=false;
|
93 |
|
94 |
|
95 |
+
$cleanup_job = WPBackItUp_Job::get_job('cleanup');
|
96 |
$logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Check for available job');
|
97 |
+
if ($cleanup_job){
|
98 |
|
99 |
//Get the next task in the stack
|
100 |
+
$next_task = $cleanup_job->get_next_task();
|
101 |
if (false!==$next_task){
|
102 |
+
$backup_id=$cleanup_job->backup_id;
|
103 |
$current_task=$next_task;
|
104 |
|
105 |
//If task contains error then timeout has occurred
|
130 |
//*************************//
|
131 |
|
132 |
//Get the backup ID
|
133 |
+
$job_name = get_job_name($cleanup_job->backup_id);
|
134 |
|
135 |
global $logger;
|
136 |
$logger = new WPBackItUp_Logger(false,null,$job_name);
|
142 |
//*** SCHEDULED TASKS ***//
|
143 |
|
144 |
//Run cleanup task
|
145 |
+
if ('task_scheduled_cleanup'==$current_task) {
|
146 |
|
147 |
//Init
|
148 |
$logger->log('***BEGIN JOB***');
|
151 |
$logger->log('Scheduled Cleanup requested');
|
152 |
|
153 |
$logger->log( '**CLEAN UNFINISHED BACKUPS**' );
|
154 |
+
//cleanup any folders that have the TMP_ prefix
|
155 |
+
$wp_backup->cleanup_backups_by_prefix('TMP_');
|
156 |
$logger->log( '**END CLEAN UNFINISHED BACKUPS**' );
|
157 |
|
158 |
+
$logger->log( '**CLEAN DELETED BACKUPS**' );
|
159 |
+
//cleanup any folders that have the DLT_ prefix
|
160 |
+
$wp_backup->cleanup_backups_by_prefix('DLT_');
|
161 |
+
$logger->log( '**END CLEAN DELETED BACKUPS**' );
|
162 |
+
|
163 |
+
$logger->log( '**CLEAN OLD BACKUPS**' );
|
164 |
+
//Cleanup any folders that exceed retention limit
|
165 |
+
$wp_backup->cleanup_old_backups();
|
166 |
+
$logger->log( '**END CLEAN OLD BACKUPS**' );
|
167 |
+
|
168 |
+
$logger->log( '**CLEAN OLD RESTORES**' );
|
169 |
+
//Cleanup any folders that exceed retention limit
|
170 |
+
$wp_restore = new WPBackItUp_Restore($logger,$job_name,null);
|
171 |
+
$wp_restore->delete_restore_folder();
|
172 |
+
$logger->log( '**END CLEAN OLD RESTORES**' );
|
173 |
+
|
174 |
$logger->log( '**PURGE OLD FILES**' );
|
175 |
$wp_backup->purge_old_files();
|
176 |
$logger->log( '**END PURGE OLD FILES**' );
|
192 |
$file_system->secure_folder( $logs_dir);
|
193 |
$logger->log( '**END SECURE FOLDERS**' );
|
194 |
|
195 |
+
$cleanup_job->set_task_complete();
|
196 |
|
197 |
}
|
198 |
|
214 |
}
|
215 |
|
216 |
function end_job($err=null, $success=null){
|
217 |
+
global $WPBackitup, $logger, $cleanup_job;
|
218 |
$logger->log_info(__METHOD__,"Begin");
|
219 |
|
220 |
WPBackItUp_Backup::end(); //Release the lock
|
222 |
$WPBackitup->set_cleanup_lastrun_date($current_datetime);
|
223 |
|
224 |
$util = new WPBackItUp_Utility($logger);
|
225 |
+
$seconds = $util->timestamp_diff_seconds($cleanup_job->get_job_start_time(),$cleanup_job->get_job_end_time());
|
226 |
|
227 |
$processing_minutes = round($seconds / 60);
|
228 |
$processing_seconds = $seconds % 60;
|
lib/includes/job_restore.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (restore)');
|
2 |
-
@set_time_limit(
|
3 |
|
4 |
/**
|
5 |
* WP Backitup Restore Functions
|
@@ -12,27 +12,30 @@
|
|
12 |
|
13 |
/*** Includes ***/
|
14 |
|
15 |
-
// include backup class
|
16 |
if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
17 |
include_once 'class-backup.php';
|
18 |
}
|
19 |
|
20 |
-
// include backup class
|
21 |
if( !class_exists( 'WPBackItUp_Restore' ) ) {
|
22 |
include_once 'class-restore.php';
|
23 |
}
|
24 |
|
25 |
-
// include file system class
|
26 |
if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
|
27 |
include_once 'class-filesystem.php';
|
28 |
}
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
if( !class_exists( 'WPBackItUp_SQL' ) ) {
|
32 |
include_once 'class-sql.php';
|
33 |
}
|
34 |
|
35 |
-
//Include Job class
|
36 |
if( !class_exists( 'WPBackItUp_Job' ) ) {
|
37 |
include_once 'class-job.php';
|
38 |
}
|
@@ -42,9 +45,9 @@ if( !class_exists( 'WPBackItUp_Job' ) ) {
|
|
42 |
global $WPBackitup;
|
43 |
global $table_prefix; //this is from wp-config
|
44 |
|
45 |
-
global $
|
46 |
-
global $backup_file_path; //full path to zip file on server
|
47 |
global $RestorePoint_SQL; //path to restore point
|
|
|
48 |
|
49 |
global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
|
50 |
$inactive=0;
|
@@ -60,890 +63,760 @@ $status_array = array(
|
|
60 |
'preparing' =>$inactive ,
|
61 |
'unzipping' =>$inactive ,
|
62 |
'validation'=>$inactive,
|
|
|
63 |
'restore_point'=>$inactive,
|
64 |
-
'
|
65 |
-
'
|
66 |
-
'
|
67 |
-
'
|
68 |
-
'
|
69 |
-
'
|
|
|
70 |
);
|
71 |
|
72 |
-
|
73 |
-
|
|
|
74 |
|
75 |
-
|
76 |
-
$
|
77 |
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
|
82 |
//*****************//
|
83 |
//*** MAIN CODE ***//
|
84 |
//*****************//
|
85 |
-
$logger->log('***BEGIN RESTORE***');
|
86 |
-
$logger->log_sysinfo();
|
87 |
|
88 |
-
//
|
89 |
-
|
90 |
-
$logger->log_info(__METHOD__,'Restore job cant acquire job lock.');
|
91 |
-
write_fatal_error_status('error250');
|
92 |
-
die();
|
93 |
-
}else{
|
94 |
-
$logger->log_info(__METHOD__,'Restore job lock acquired.');
|
95 |
-
}
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
write_fatal_error_status('error225');
|
100 |
-
die();
|
101 |
-
}
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
write_fatal_error_status('error201');
|
107 |
-
|
108 |
}
|
109 |
|
110 |
//Get user ID
|
111 |
-
$user_id = $
|
112 |
if( empty($user_id)) {
|
|
|
113 |
write_fatal_error_status('error201');
|
114 |
-
|
115 |
}
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
-
//
|
|
|
|
|
|
|
119 |
|
120 |
-
|
|
|
121 |
|
122 |
-
|
123 |
|
124 |
-
|
125 |
-
$
|
|
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
$
|
|
|
130 |
|
131 |
-
$logger->log('
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
135 |
|
136 |
-
$logger->log('
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
$logger->log('
|
141 |
|
142 |
-
$logger->log('
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
|
148 |
-
|
149 |
-
$
|
150 |
-
|
151 |
-
$
|
152 |
-
|
153 |
-
$
|
|
|
154 |
|
155 |
-
$
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
-
$
|
162 |
-
|
163 |
-
$
|
164 |
-
|
165 |
-
$user_pass
|
166 |
-
|
167 |
-
$logger->log('**END GET SITE VALUES FROM DB**');
|
168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
-
|
171 |
-
$logger->log('**GET backupsiteinfo.txt VALUES**');
|
172 |
-
$import_siteinfo_lines = file($site_data_path .'backupsiteinfo.txt');
|
173 |
-
$import_siteurl = str_replace("\n", '',trim($import_siteinfo_lines[0]));
|
174 |
-
$current_siteurl = trim($siteurl ,'/');
|
175 |
-
$import_table_prefix = str_replace("\n", '',$import_siteinfo_lines[1]);
|
176 |
-
$import_wp_version = str_replace("\n", '',$import_siteinfo_lines[2]);
|
177 |
-
$logger->log($import_siteinfo_lines);
|
178 |
-
|
179 |
-
//Check table prefix values FATAL
|
180 |
-
if($table_prefix !=$import_table_prefix) {
|
181 |
-
$logger->log('Error: Table prefix different from restore.');
|
182 |
-
write_warning_status('error221');
|
183 |
-
}
|
184 |
-
|
185 |
-
$logger->log('**END GET backupsiteinfo.txt VALUES**');
|
186 |
-
|
187 |
-
|
188 |
-
$logger->log('**CREATE RESTORE POINT**');
|
189 |
-
//Create restore point for DB
|
190 |
-
set_status('validation',$complete,false);
|
191 |
-
set_status('restore_point',$active,true);
|
192 |
-
$RestorePoint_SQL = backup_database($wp_restore->backup_folder_path); //Save in backup folder
|
193 |
-
set_status('restore_point',$complete,false);
|
194 |
-
$logger->log('**END CREATE RESTORE POINT**');
|
195 |
-
|
196 |
|
197 |
-
$
|
198 |
-
|
199 |
-
|
200 |
-
import_backedup_database($backupSQLFile,$RestorePoint_SQL);
|
201 |
-
$logger->log('**END RESTORE DATABASE**');
|
202 |
|
203 |
-
|
204 |
-
|
205 |
-
WPBackItUp_Job::cancel_all_jobs();
|
206 |
-
update_user_credentials($import_table_prefix, $user_login, $user_pass, $user_email, $user_id);
|
207 |
-
update_siteurl($import_table_prefix, $current_siteurl);
|
208 |
-
update_homeurl($import_table_prefix, $homeurl);
|
209 |
-
$logger->log('**END UPDATE DATABASE VALUES**');
|
210 |
|
211 |
-
|
212 |
-
set_status('database',$complete,false);
|
213 |
|
|
|
214 |
|
215 |
-
|
|
|
216 |
|
217 |
-
|
218 |
-
$
|
219 |
-
|
220 |
-
$
|
221 |
-
|
222 |
-
$
|
223 |
-
|
224 |
-
$logger->log('**RESTORE PLUGINS**');
|
225 |
-
restore_folder($plugins_path,$target_plugins_path);
|
226 |
-
set_status('plugins',$complete,false);
|
227 |
-
$logger->log('**END RESTORE PLUGINS**');
|
228 |
-
|
229 |
-
$logger->log('**DELETE THEMES**');
|
230 |
-
$target_themes_path=WPBACKITUP__THEMES_ROOT_PATH;
|
231 |
-
set_status('themes',$active,true);
|
232 |
-
delete_folder_content($target_themes_path);
|
233 |
-
$logger->log('**END DELETE THEMES**');
|
234 |
-
|
235 |
-
$logger->log('**RESTORE THEMES**');
|
236 |
-
restore_folder($themes_path,$target_themes_path);
|
237 |
-
set_status('themes',$complete,false);
|
238 |
-
$logger->log('**END RESTORE THEMES**');
|
239 |
-
|
240 |
-
$logger->log('**DELETE UPLOADS**');
|
241 |
-
$upload_array = wp_upload_dir();
|
242 |
-
$target_uploads_path = $upload_array['basedir'];
|
243 |
-
set_status('uploads',$active,true);
|
244 |
-
delete_folder_content($target_uploads_path);
|
245 |
-
$logger->log('**END DELETE UPLOADS**');
|
246 |
-
|
247 |
-
$logger->log('**RESTORE UPLOADS**');
|
248 |
-
restore_folder($uploads_path,$target_uploads_path);
|
249 |
-
set_status('uploads',$complete,false);
|
250 |
-
$logger->log('**END RESTORE UPLOADS**');
|
251 |
-
|
252 |
-
|
253 |
-
$logger->log('**DELETE OTHER**');
|
254 |
-
$other_ignore = array(WPBACKITUP__BACKUP_FOLDER,WPBACKITUP__RESTORE_FOLDER,basename($target_plugins_path),basename($target_themes_path),basename($target_uploads_path),'debug.log');
|
255 |
-
set_status('other',$active,true);
|
256 |
-
delete_folder_content(WPBACKITUP__CONTENT_PATH,$other_ignore);
|
257 |
-
$logger->log('**END DELETE OTHER**');
|
258 |
-
|
259 |
-
$logger->log('**RESTORE OTHER**');
|
260 |
-
restore_other_folders($other_path,WPBACKITUP__CONTENT_PATH,$other_ignore);
|
261 |
-
set_status('other',$complete,false);
|
262 |
-
$logger->log('**END RESTORE OTHER**');
|
263 |
-
|
264 |
-
$logger->log('**VALIDATE WP-CONTENT**');
|
265 |
-
$logger->log('--VALIDATE PLUGINS--');
|
266 |
-
validate_wpcontent($plugins_path,$target_plugins_path);
|
267 |
-
$logger->log('--VALIDATE THEMES--');
|
268 |
-
validate_wpcontent($themes_path,$target_themes_path);
|
269 |
-
$logger->log('--VALIDATE UPLOADS--');
|
270 |
-
validate_wpcontent($uploads_path,$target_uploads_path);
|
271 |
-
$logger->log('--VALIDATE OTHER--');
|
272 |
-
validate_other_folders($other_path,WPBACKITUP__CONTENT_PATH,$other_ignore);
|
273 |
-
$logger->log('**END VALIDATE WPCONTENT**');
|
274 |
-
|
275 |
-
$logger->log('**CLEANUP**');
|
276 |
-
set_status('cleanup',$active,true);
|
277 |
-
cleanup_restore_folder($restoration_dir_path);
|
278 |
-
set_status('cleanup',$complete,false);
|
279 |
-
$logger->log('**END CLEANUP**');
|
280 |
-
|
281 |
-
set_status_success();
|
282 |
-
$logger->log('Restore completed successfully');
|
283 |
-
$logger->log('***END RESTORE***');
|
284 |
-
|
285 |
-
$logger->log('**UPDATE PERMALINKS**');
|
286 |
-
update_permalinks();
|
287 |
-
$logger->log('**END UPDATE PERMALINKS**');
|
288 |
-
|
289 |
-
|
290 |
-
WPBackItUp_Backup::end(); //release lock
|
291 |
-
|
292 |
-
echo('Restore has completed successfully.');
|
293 |
-
exit;
|
294 |
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
|
300 |
-
|
301 |
-
$localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
|
302 |
-
$job_log_name = 'job_restore_' .$localDateTime;
|
303 |
|
304 |
-
return
|
305 |
|
306 |
}
|
307 |
|
308 |
-
//
|
309 |
-
|
310 |
-
|
311 |
|
312 |
-
$
|
313 |
-
|
314 |
-
return $filesystem->get_file_handle($status_file_path);
|
315 |
|
316 |
-
|
317 |
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
|
|
|
|
325 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
}
|
327 |
|
328 |
-
//
|
329 |
-
$
|
330 |
-
|
331 |
-
}
|
332 |
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
$status_array[$status_code]=$warning;
|
338 |
-
write_restore_status();
|
339 |
-
}
|
340 |
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
}
|
348 |
-
|
349 |
-
}
|
350 |
|
351 |
-
|
352 |
-
|
353 |
-
$
|
354 |
-
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
}
|
357 |
|
358 |
-
function set_status_success(){
|
359 |
-
global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
|
360 |
-
global $active;
|
361 |
|
362 |
-
|
363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
}
|
365 |
|
366 |
-
//Create an empty restore folder
|
367 |
-
function create_restore_folder($path) {
|
368 |
-
global $logger;
|
369 |
-
$logger->log('Create restore folder:' .$path);
|
370 |
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
}
|
|
|
|
|
377 |
|
378 |
-
|
379 |
-
$fileSystem->secure_folder( $path);
|
380 |
|
381 |
-
|
382 |
-
$logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
|
383 |
-
$fileSystem->secure_folder( $logs_dir);
|
384 |
|
385 |
-
|
386 |
}
|
387 |
|
388 |
-
//Delete restore folder and contents
|
389 |
-
function delete_restore_folder() {
|
390 |
-
global $logger;
|
391 |
-
global $wp_restore;
|
392 |
-
//Delete the existing restore directory
|
393 |
-
$logger->log('Delete existing restore folder:' .$wp_restore->restore_folder_path);
|
394 |
-
$fileSystem = new WPBackItUp_FileSystem($logger);
|
395 |
-
return $fileSystem->recursive_delete($wp_restore->restore_folder_path);
|
396 |
-
}
|
397 |
|
398 |
-
//
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
$
|
403 |
-
$
|
404 |
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
|
|
410 |
}
|
|
|
411 |
|
412 |
-
$
|
413 |
-
$
|
414 |
-
if (
|
415 |
-
|
416 |
-
|
417 |
-
delete_restore_folder();
|
418 |
-
die();
|
419 |
-
}
|
420 |
-
|
421 |
-
//Unzip to extract folder
|
422 |
-
try {
|
423 |
-
$zip = new ZipArchive;
|
424 |
-
$res = $zip->open($backup_file_path);
|
425 |
-
if ($res === TRUE) {
|
426 |
-
if (true===$zip->extractTo($zip_extract_root_path)){
|
427 |
-
$zip->close();
|
428 |
-
} else {
|
429 |
-
$zip->close();
|
430 |
-
$logger->log('Error: Cant unzip backup:'.$backup_file_path);
|
431 |
-
write_fatal_error_status('error203');
|
432 |
-
delete_restore_folder();
|
433 |
-
die();
|
434 |
-
}
|
435 |
-
} else {
|
436 |
-
$logger->log('Error: Cant open backup archive:'.$backup_file_path);
|
437 |
-
write_fatal_error_status('error203');
|
438 |
-
delete_restore_folder();
|
439 |
-
die();
|
440 |
-
}
|
441 |
-
$logger->log('Backup file unzipped: ' .$zip_extract_root_path);
|
442 |
-
} catch(Exception $e) {
|
443 |
-
$logger->log('An Unexpected Error has happened: ' .$e);
|
444 |
-
write_fatal_error_status('error203');
|
445 |
-
delete_restore_folder();
|
446 |
-
die();
|
447 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
}
|
449 |
|
450 |
-
//
|
451 |
-
|
452 |
-
global $logger;
|
453 |
-
$restoration_dir_path='';
|
454 |
|
455 |
-
$logger->log('
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
}
|
462 |
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
die();
|
468 |
-
}
|
469 |
-
|
470 |
-
//Validate the restoration
|
471 |
-
$logger->log('Validate restoration directory: ' . $restoration_dir_path .'backupsiteinfo.txt');
|
472 |
-
if(!glob($restoration_dir_path .'site-data/backupsiteinfo.txt') ){
|
473 |
-
$logger->log('Error: backupsiteinfo.txt missing from restore folder: ' .$restoration_dir_path);
|
474 |
-
write_fatal_error_status('error204');
|
475 |
-
delete_restore_folder(); //delete the restore folder if bad
|
476 |
-
die();
|
477 |
-
}
|
478 |
-
$logger->log('Restoration directory validated: ' .$restoration_dir_path);
|
479 |
-
return $restoration_dir_path;
|
480 |
-
}
|
481 |
-
|
482 |
-
// Backup the current database try dump first
|
483 |
-
function backup_database($restore_folder_root){
|
484 |
-
global $logger;
|
485 |
-
$date = date_i18n('Y-m-d-Hi',current_time( 'timestamp' ));
|
486 |
-
$backup_file = $restore_folder_root . 'db-backup-' . $date .'.cur';
|
487 |
-
$logger->log('Backup the current database: ' .$backup_file);
|
488 |
-
|
489 |
-
$dbc = new WPBackItUp_SQL($logger);
|
490 |
-
if(!$dbc->mysqldump_export($backup_file)) {
|
491 |
-
//Try a manual restore since dump didnt work
|
492 |
-
if(!$dbc->manual_export($backup_file)) {
|
493 |
-
$logger->log('Error: Cant backup database:'.$backup_file);
|
494 |
-
write_fatal_error_status('error205');
|
495 |
-
delete_restore_folder();
|
496 |
-
die();
|
497 |
-
}
|
498 |
}
|
499 |
-
$logger->log('Current database backed up: ' .$backup_file);
|
500 |
-
return $backup_file;
|
501 |
-
}
|
502 |
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
$logger->log('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
507 |
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
delete_restore_folder();
|
512 |
-
die();
|
513 |
}
|
514 |
-
|
|
|
515 |
}
|
516 |
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
|
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
}
|
533 |
-
write_fatal_error_status('error224');
|
534 |
-
$logger->log('Database restored to previous state.');
|
535 |
}
|
536 |
|
537 |
-
|
538 |
-
|
539 |
-
global $logger;
|
540 |
|
541 |
-
$logger->
|
542 |
-
//Try SQL Import first
|
543 |
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
$logger->log('Error: Database import error.');
|
549 |
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
write_fatal_error_status('error230');
|
554 |
|
555 |
-
|
556 |
-
else {
|
557 |
-
$logger->log('Database NOT restored to checkpoint.');
|
558 |
-
write_fatal_error_status('error212');
|
559 |
-
}
|
560 |
|
561 |
-
|
562 |
-
|
|
|
|
|
|
|
|
|
563 |
}
|
564 |
}
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
//get siteurl
|
569 |
-
function get_siteurl(){
|
570 |
-
global $logger;
|
571 |
-
global $table_prefix;
|
572 |
-
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
|
573 |
-
|
574 |
-
$dbc = new WPBackItUp_SQL($logger);
|
575 |
-
$siteurl = $dbc->get_sql_scalar($sql);
|
576 |
-
if (empty($siteurl)) {
|
577 |
-
$logger->log('Error: Siteurl not found');
|
578 |
-
write_fatal_error_status('error207');
|
579 |
-
delete_restore_folder();
|
580 |
-
die();
|
581 |
-
}
|
582 |
-
$logger->log('Siteurl found:' .$siteurl);
|
583 |
-
return $siteurl;
|
584 |
-
}
|
585 |
-
|
586 |
-
//get homeurl
|
587 |
-
function get_homeurl(){
|
588 |
-
global $logger;
|
589 |
-
global $table_prefix;
|
590 |
-
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
|
591 |
-
$dbc = new WPBackItUp_SQL($logger);
|
592 |
-
$homeurl = $dbc->get_sql_scalar($sql);
|
593 |
-
if (empty($homeurl)) {
|
594 |
-
$logger->log('Error: Homeurl not found.');
|
595 |
-
write_fatal_error_status('error208');
|
596 |
-
delete_restore_folder();
|
597 |
-
die();
|
598 |
-
}
|
599 |
-
$logger->log('homeurl found:' . $homeurl);
|
600 |
-
return $homeurl;
|
601 |
-
}
|
602 |
-
|
603 |
-
//get user login
|
604 |
-
function get_user_login($user_id){
|
605 |
-
global $logger;
|
606 |
-
global $table_prefix;
|
607 |
-
$sql = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
608 |
-
|
609 |
-
$dbc = new WPBackItUp_SQL($logger);
|
610 |
-
$user_login = $dbc->get_sql_scalar($sql);
|
611 |
-
if (empty($user_login)) {
|
612 |
-
$logger->log('Error: user_login not found.');
|
613 |
-
write_fatal_error_status('error209');
|
614 |
-
delete_restore_folder();
|
615 |
-
die();
|
616 |
-
}
|
617 |
-
$logger->log('user_login found.');
|
618 |
-
return $user_login;
|
619 |
-
}
|
620 |
-
|
621 |
-
//get user pass
|
622 |
-
function get_user_pass($user_id){
|
623 |
-
global $logger;
|
624 |
-
global $table_prefix;
|
625 |
-
$sql = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
626 |
-
|
627 |
-
$dbc = new WPBackItUp_SQL($logger);
|
628 |
-
$user_pass = $dbc->get_sql_scalar($sql);
|
629 |
-
if (empty($user_pass)) {
|
630 |
-
$logger->log('Error: user_pass not found.');
|
631 |
-
write_fatal_error_status('error210');
|
632 |
-
delete_restore_folder();
|
633 |
-
die();
|
634 |
-
}
|
635 |
-
$logger->log('user_pass found.');
|
636 |
-
return $user_pass;
|
637 |
-
}
|
638 |
-
|
639 |
-
//get user email
|
640 |
-
function get_user_email($user_id){
|
641 |
-
global $logger;
|
642 |
-
global $table_prefix;
|
643 |
-
$sql = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
|
644 |
-
|
645 |
-
$dbc = new WPBackItUp_SQL($logger);
|
646 |
-
$user_email = $dbc->get_sql_scalar($sql);
|
647 |
-
if (empty($user_email)) {
|
648 |
-
$logger->log('Error: user_email not found.');
|
649 |
-
write_fatal_error_status('error211');
|
650 |
-
delete_restore_folder();
|
651 |
-
die();
|
652 |
-
}
|
653 |
-
$logger->log('user_email found.' . $user_email);
|
654 |
-
return $user_email;
|
655 |
-
}
|
656 |
-
|
657 |
-
//Update user credentials
|
658 |
-
function update_user_credentials($table_prefix, $user_login, $user_pass, $user_email, $user_id){
|
659 |
-
global $logger;
|
660 |
-
$sql = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
|
661 |
-
|
662 |
-
$dbc = new WPBackItUp_SQL($logger);
|
663 |
-
if (!$dbc->run_sql_command($sql)){
|
664 |
-
$logger->log('Error: User Credential database update failed..');
|
665 |
-
write_warning_status('error215');
|
666 |
-
restore_database();
|
667 |
-
delete_restore_folder();
|
668 |
-
die();
|
669 |
-
}
|
670 |
-
$logger->log('User Credential updated in database.');
|
671 |
-
}
|
672 |
-
|
673 |
-
//update the site URL in the restored database
|
674 |
-
function update_siteurl($table_prefix, $current_siteurl){
|
675 |
-
global $logger;
|
676 |
-
$sql = "UPDATE ". $table_prefix ."options SET option_value='" .$current_siteurl ."' WHERE option_name='siteurl'";
|
677 |
-
|
678 |
-
$dbc = new WPBackItUp_SQL($logger);
|
679 |
-
if (!$dbc->run_sql_command($sql)){
|
680 |
-
$logger->log('Error: SiteURL updated failed.');
|
681 |
-
write_warning_status('error213');
|
682 |
-
restore_database();
|
683 |
-
delete_restore_folder();
|
684 |
-
die();
|
685 |
-
}
|
686 |
-
$logger->log('SiteURL updated in database.');
|
687 |
-
}
|
688 |
-
|
689 |
-
//Update homeURL
|
690 |
-
function update_homeurl($table_prefix, $homeurl){
|
691 |
-
global $logger;
|
692 |
-
$sql = "UPDATE ". $table_prefix ."options SET option_value='" .$homeurl ."' WHERE option_name='home'";
|
693 |
-
$dbc = new WPBackItUp_SQL($logger);
|
694 |
-
if (!$dbc->run_sql_command($sql)){
|
695 |
-
$logger->log('Error: HomeURL database update failed..');
|
696 |
-
write_warning_status('error214');
|
697 |
-
restore_database();
|
698 |
-
delete_restore_folder();
|
699 |
-
die();
|
700 |
-
}
|
701 |
-
$logger->log('HomeURL updated in database.');
|
702 |
-
}
|
703 |
-
|
704 |
-
//Delete wp-content content
|
705 |
-
function delete_wpcontent_content($root_folder){
|
706 |
-
global $logger;
|
707 |
-
$logger->log('Delete the wp_content contents:' .$root_folder);
|
708 |
-
$ignore = array(WPBACKITUP__PLUGIN_FOLDER,WPBACKITUP__RESTORE_FOLDER,WPBACKITUP__BACKUP_FOLDER,'debug.log');
|
709 |
-
$filesystem = new WPBackItUp_FileSystem($logger);
|
710 |
-
if(!$filesystem->recursive_delete($root_folder,$ignore)) {
|
711 |
-
$logger->log('Error: Cant delete WPContent:' .$root_folder);
|
712 |
-
write_warning_status('error217');
|
713 |
-
restore_database();
|
714 |
-
delete_restore_folder();
|
715 |
-
die();
|
716 |
-
}
|
717 |
-
$logger->log('wp-content has been deleted:' .$root_folder);
|
718 |
-
}
|
719 |
-
|
720 |
-
//Delete plugins content
|
721 |
-
function delete_plugins_content(){
|
722 |
-
global $logger;
|
723 |
-
$plugins_folder=WPBACKITUP__PLUGINS_ROOT_PATH;
|
724 |
-
$logger->log('Delete the plugins contents:' .$plugins_folder);
|
725 |
-
$ignore = array(WPBACKITUP__PLUGIN_FOLDER);
|
726 |
-
$filesystem = new WPBackItUp_FileSystem($logger);
|
727 |
-
if(!$filesystem->recursive_delete($plugins_folder,$ignore)) {
|
728 |
-
$logger->log('Error: Cant delete old WPContent:' .$plugins_folder );
|
729 |
-
write_warning_status('error217');
|
730 |
-
restore_database();
|
731 |
-
delete_restore_folder();
|
732 |
-
die();
|
733 |
-
}
|
734 |
-
$logger->log('Plugins content deleted:' .$plugins_folder);
|
735 |
-
}
|
736 |
-
|
737 |
-
|
738 |
-
//Delete themes content
|
739 |
-
function delete_themes_content(){
|
740 |
-
global $logger;
|
741 |
-
$themes_folder=WPBACKITUP__THEMES_ROOT_PATH ;
|
742 |
-
$logger->log('Delete the themes contents:' .$themes_folder);
|
743 |
-
$filesystem = new WPBackItUp_FileSystem($logger);
|
744 |
-
if(!$filesystem->recursive_delete($themes_folder)) {
|
745 |
-
$logger->log('Error: Cant delete old WPContent:' .$themes_folder );
|
746 |
-
write_warning_status('error217');
|
747 |
-
restore_database();
|
748 |
-
delete_restore_folder();
|
749 |
-
die();
|
750 |
-
}
|
751 |
-
$logger->log('Themes content deleted:' .$themes_folder);
|
752 |
-
}
|
753 |
-
|
754 |
-
//Delete folder content
|
755 |
-
function delete_folder_content($target_path,$ignore = array('')){
|
756 |
-
global $logger;
|
757 |
-
//add the / if needed
|
758 |
-
//$target_path =rtrim($target_path, '/') . '/';
|
759 |
-
$logger->log('Delete the folder contents:' .$target_path);
|
760 |
-
$filesystem = new WPBackItUp_FileSystem($logger);
|
761 |
-
if(!$filesystem->recursive_delete($target_path,$ignore)) {
|
762 |
-
$logger->log('Error: Cant delete old WPContent:' .$target_path );
|
763 |
-
write_warning_status('error217');
|
764 |
-
restore_database();
|
765 |
-
delete_restore_folder();
|
766 |
-
die();
|
767 |
-
}
|
768 |
-
$logger->log('Folder content deleted:' .$target_path);
|
769 |
}
|
770 |
|
771 |
-
//
|
772 |
-
function
|
773 |
-
|
774 |
-
|
775 |
-
$
|
776 |
-
$
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
write_warning_status('error219');
|
781 |
-
restore_database();
|
782 |
-
delete_restore_folder();
|
783 |
-
die();
|
784 |
-
}
|
785 |
-
$logger->log('Content folder copied successfully');
|
786 |
}
|
787 |
|
|
|
|
|
788 |
|
789 |
-
|
790 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
791 |
global $logger;
|
792 |
-
$logger->log_info(__METHOD__,'Begin');
|
793 |
|
794 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
795 |
|
796 |
-
|
797 |
-
|
798 |
-
$logger
|
799 |
-
$
|
|
|
|
|
|
|
800 |
|
801 |
-
|
802 |
-
$source_other_folder=$dir .'/';
|
803 |
-
$target_other_folder = $target_other_root .basename($dir);
|
804 |
|
805 |
-
|
806 |
-
|
807 |
-
|
|
|
|
|
|
|
|
|
808 |
|
809 |
-
|
810 |
-
|
811 |
-
}
|
812 |
|
813 |
-
|
814 |
-
|
815 |
-
|
|
|
|
|
816 |
$filesystem = new WPBackItUp_FileSystem($logger);
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
delete_restore_folder();
|
829 |
-
die();
|
830 |
-
}
|
831 |
}
|
832 |
}
|
833 |
|
834 |
-
|
|
|
|
|
835 |
}
|
836 |
|
837 |
-
//validate other content folders
|
838 |
-
function validate_other_folders($source_path,$target_other_root,$ignore) {
|
839 |
-
global $logger;
|
840 |
-
//$logger->log_info(__METHOD__,'Begin');
|
841 |
|
842 |
-
$target_other_root =rtrim($target_other_root, '/') . '/';
|
843 |
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
|
|
|
|
|
|
|
|
|
|
848 |
|
849 |
-
|
850 |
-
|
851 |
-
$target_other_folder = $target_other_root .basename($dir);
|
852 |
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
|
857 |
-
|
858 |
-
|
859 |
-
}
|
860 |
|
861 |
-
|
862 |
-
$
|
863 |
-
|
864 |
-
$target_other_file = $target_other_root .basename($file);
|
865 |
|
866 |
-
if( ! in_array(basename($file), $ignore) ) {
|
867 |
-
// $logger->log_info( __METHOD__, 'Validate file from:' . $file );
|
868 |
-
// $logger->log_info( __METHOD__, 'Validate file to:' . $target_other_file );
|
869 |
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
}
|
874 |
-
}
|
875 |
|
|
|
|
|
876 |
}
|
877 |
|
878 |
-
|
879 |
-
|
880 |
-
global $logger;
|
881 |
-
$logger->log('Copy content folder from:' .$source_path);
|
882 |
-
$logger->log('Copy content folder to:' .$target_path);
|
883 |
|
884 |
-
|
885 |
-
|
886 |
|
887 |
-
$
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
$logger->log('Content folder copied successfully');
|
907 |
-
}
|
908 |
-
|
909 |
-
//Restore all wp content from zip
|
910 |
-
function validate_wpcontent($source_dir_path,$target_dir_path){
|
911 |
-
global $logger;
|
912 |
-
// $logger->log('Validate content folder TO:' .$source_dir_path);
|
913 |
-
// $logger->log('Validate content folder FROM:' .$target_dir_path);
|
914 |
-
|
915 |
-
$ignore = array(WPBACKITUP__PLUGIN_FOLDER,'debug.log','backupsiteinfo.txt','db-backup.sql');
|
916 |
-
$filesystem = new WPBackItUp_FileSystem($logger);
|
917 |
-
if(!$filesystem->recursive_validate($source_dir_path. '/', $target_dir_path . '/',$ignore)) {
|
918 |
-
$logger->log_error(__METHOD__,'Content folder is not the same as backup.');
|
919 |
-
}else{
|
920 |
-
$logger->log_info(__METHOD__,'Success: No differences in content folder:' .$target_dir_path);
|
921 |
-
}
|
922 |
-
|
923 |
-
//$logger->log('Content folder validation complete.');
|
924 |
-
}
|
925 |
-
|
926 |
-
//Delete the restoration directory
|
927 |
-
function cleanup_restore_folder($restoration_dir_path){
|
928 |
-
global $logger;
|
929 |
-
$logger->log('Cleanup the restore folder: ' .$restoration_dir_path);
|
930 |
-
if(!delete_restore_folder()) {
|
931 |
-
$logger->log('Error: Cleanup restore folder failed: ' .$restoration_dir_path);
|
932 |
-
write_warning_status('error220'); //NOT fatal
|
933 |
-
} else {
|
934 |
-
$logger->log('Restore folder cleaned successfully: ' .$restoration_dir_path);
|
935 |
-
}
|
936 |
-
}
|
937 |
-
function update_permalinks(){
|
938 |
-
global $wp_rewrite, $logger;
|
939 |
-
try {
|
940 |
-
|
941 |
-
$wp_rewrite->flush_rules( true );//Update permalinks - hard flush
|
942 |
-
|
943 |
-
}catch(Exception $e) {
|
944 |
-
$logger->log_error(__METHOD__,'Exception: ' .$e);
|
945 |
-
return false;
|
946 |
-
}
|
947 |
-
$logger->log_info(__METHOD__,'Permalinks updated.');
|
948 |
-
return true;
|
949 |
-
}
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (restore)');
|
2 |
+
@set_time_limit(WPBACKITUP__SCRIPT_TIMEOUT_SECONDS);
|
3 |
|
4 |
/**
|
5 |
* WP Backitup Restore Functions
|
12 |
|
13 |
/*** Includes ***/
|
14 |
|
|
|
15 |
if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
16 |
include_once 'class-backup.php';
|
17 |
}
|
18 |
|
|
|
19 |
if( !class_exists( 'WPBackItUp_Restore' ) ) {
|
20 |
include_once 'class-restore.php';
|
21 |
}
|
22 |
|
|
|
23 |
if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
|
24 |
include_once 'class-filesystem.php';
|
25 |
}
|
26 |
|
27 |
+
if( !class_exists( 'WPBackItUp_Zip' ) ) {
|
28 |
+
include_once 'class-zip.php';
|
29 |
+
}
|
30 |
+
|
31 |
+
if( !class_exists( 'WPBackItUp_Utility' ) ) {
|
32 |
+
include_once 'class-utility.php';
|
33 |
+
}
|
34 |
+
|
35 |
if( !class_exists( 'WPBackItUp_SQL' ) ) {
|
36 |
include_once 'class-sql.php';
|
37 |
}
|
38 |
|
|
|
39 |
if( !class_exists( 'WPBackItUp_Job' ) ) {
|
40 |
include_once 'class-job.php';
|
41 |
}
|
45 |
global $WPBackitup;
|
46 |
global $table_prefix; //this is from wp-config
|
47 |
|
48 |
+
global $backup_name; //name of the backup file
|
|
|
49 |
global $RestorePoint_SQL; //path to restore point
|
50 |
+
global $logger;
|
51 |
|
52 |
global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
|
53 |
$inactive=0;
|
63 |
'preparing' =>$inactive ,
|
64 |
'unzipping' =>$inactive ,
|
65 |
'validation'=>$inactive,
|
66 |
+
'deactivate_plugins' =>$inactive ,
|
67 |
'restore_point'=>$inactive,
|
68 |
+
'stage_wpcontent'=>$inactive,
|
69 |
+
'restore_wpcontent'=>$inactive,
|
70 |
+
'restore_database'=>$inactive,
|
71 |
+
'update_user'=>$inactive,
|
72 |
+
'update_site_info'=>$inactive,
|
73 |
+
'activate_plugins'=>$inactive,
|
74 |
+
'update_permalinks'=>$inactive,
|
75 |
);
|
76 |
|
77 |
+
//**************************//
|
78 |
+
// SINGLE THREAD RESTORE //
|
79 |
+
//**************************//
|
80 |
|
81 |
+
$logger_tasks = new WPBackItUp_Logger(false,null,'debug_restore_tasks');
|
82 |
+
$process_id = uniqid();
|
83 |
|
84 |
+
//Is restore running
|
85 |
+
if ( ! WPBackItUp_Backup::start()) {
|
86 |
+
$logger_tasks->log_info(__METHOD__,'Restore job cant acquire job lock.');
|
87 |
+
return; // do nothing.
|
88 |
+
}else{
|
89 |
+
$logger_tasks->log_info(__METHOD__,'Restore job lock acquired.');
|
90 |
+
}
|
91 |
+
|
92 |
+
|
93 |
+
//**************************//
|
94 |
+
// Task Handling //
|
95 |
+
//**************************//
|
96 |
+
global $restore_job;
|
97 |
+
$restore_job=null;
|
98 |
+
$current_task= null;
|
99 |
+
|
100 |
+
$restore_error=false;
|
101 |
+
$restore_job = WPBackItUp_Job::get_job('restore');
|
102 |
+
$logger_tasks->log_info(__METHOD__.'(' .$process_id .')','Check for available job');
|
103 |
+
if ($restore_job){
|
104 |
+
|
105 |
+
//Get the next task in the stack
|
106 |
+
$next_task = $restore_job->get_next_task();
|
107 |
+
if (false!==$next_task){
|
108 |
+
$restore_id=$restore_job->backup_id;
|
109 |
+
$current_task=$next_task;
|
110 |
+
|
111 |
+
//If task contains error then timeout has occurred
|
112 |
+
if (strpos($current_task,'error') !== false){
|
113 |
+
$logger_tasks->log_info(__METHOD__.'(' .$process_id .')','Restore Error Found:' .$current_task);
|
114 |
+
$restore_error=true;
|
115 |
+
}
|
116 |
+
|
117 |
+
$logger_tasks->log_info(__METHOD__.'(' .$process_id .')','Available Task Found:' . $current_task);
|
118 |
+
|
119 |
+
}else{
|
120 |
+
$logger_tasks->log_info(__METHOD__.'(' .$process_id .')','No available tasks found.');
|
121 |
+
WPBackItUp_Backup::end(); //release lock
|
122 |
+
return;
|
123 |
+
}
|
124 |
+
}else {
|
125 |
+
$logger_tasks->log_info(__METHOD__.'(' .$process_id .')','No job available.');
|
126 |
+
|
127 |
+
//wp_clear_scheduled_hook( 'wpbackitup_run_restore_tasks');
|
128 |
+
WPBackItUp_Backup::end(); //release lock
|
129 |
+
return;
|
130 |
+
}
|
131 |
+
|
132 |
+
//Should only get here when there is a task to run
|
133 |
+
$logger_tasks->log_info(__METHOD__.'(' .$process_id .')','Run Restore task:' .$current_task);
|
134 |
|
135 |
|
136 |
//*****************//
|
137 |
//*** MAIN CODE ***//
|
138 |
//*****************//
|
|
|
|
|
139 |
|
140 |
+
//Get the job name
|
141 |
+
$job_log_name = get_job_log_name($restore_job->backup_id);
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
+
global $logger;
|
144 |
+
$logger = new WPBackItUp_Logger(false,null,$job_log_name,true);
|
|
|
|
|
|
|
145 |
|
146 |
+
$backup_name = $restore_job->get_job_meta('backup_name');
|
147 |
+
if( empty($backup_name)) {
|
148 |
+
$logger->log_error(__METHOD__,'Backup name not found in job meta.');
|
149 |
write_fatal_error_status('error201');
|
150 |
+
end_restore();
|
151 |
}
|
152 |
|
153 |
//Get user ID
|
154 |
+
$user_id = $restore_job->get_job_meta('user_id');
|
155 |
if( empty($user_id)) {
|
156 |
+
$logger->log_error(__METHOD__,'User Id not found in job meta.');
|
157 |
write_fatal_error_status('error201');
|
158 |
+
end_restore();
|
159 |
}
|
160 |
|
161 |
+
global $wp_restore; //Eventually everything will be migrated to this class
|
162 |
+
$wp_restore = new WPBackItUp_Restore($logger,$backup_name,$restore_job->backup_id);
|
163 |
+
|
164 |
+
//*************************//
|
165 |
+
//*** RESTORE TASKS ***//
|
166 |
+
//*************************//
|
167 |
+
//An error has occurred on the previous tasks
|
168 |
+
if ($restore_error) {
|
169 |
+
$error_task = substr( $current_task, 6 );
|
170 |
+
|
171 |
+
//Check for error type
|
172 |
+
switch ( $error_task ) {
|
173 |
+
case "task_preparing":
|
174 |
+
fatal_error( 'preparing', '2001', 'Task ended in error:'.$error_task );
|
175 |
+
break;
|
176 |
+
|
177 |
+
case "task_unzip_backup_set":
|
178 |
+
fatal_error( 'unzipping', '2002', 'Task ended in error:'.$error_task );
|
179 |
+
break;
|
180 |
+
|
181 |
+
case "task_validate_backup":
|
182 |
+
fatal_error( 'validation', '2003', 'Task ended in error:'.$error_task );
|
183 |
+
break;
|
184 |
+
|
185 |
+
case "task_create_checkpoint":
|
186 |
+
fatal_error( 'restore_point', '2004', 'Task ended in error:'.$error_task );
|
187 |
+
break;
|
188 |
+
|
189 |
+
case "task_stage_wpcontent":
|
190 |
+
fatal_error( 'stage_wpcontent', '2005', 'Task ended in error:'.$error_task );
|
191 |
+
break;
|
192 |
+
|
193 |
+
case "task_restore_wpcontent":
|
194 |
+
fatal_error( 'restore_wpcontent', '2006', 'Task ended in error:'.$error_task );
|
195 |
+
break;
|
196 |
+
|
197 |
+
case "task_restore_database":
|
198 |
+
fatal_error( 'restore_database', '2007', 'Task ended in error:'.$error_task );
|
199 |
+
break;
|
200 |
+
|
201 |
+
default:
|
202 |
+
fatal_error( 'unknown', '2999', 'Task ended in error:'.$error_task );
|
203 |
+
break;
|
204 |
+
}
|
205 |
+
}
|
206 |
|
207 |
+
//Cleanup Task
|
208 |
+
if ('task_preparing'==$current_task) {
|
209 |
+
$logger->log('***BEGIN RESTORE***');
|
210 |
+
$logger->log_sysinfo();
|
211 |
|
212 |
+
$task = 'preparing';
|
213 |
+
start_status($task);
|
214 |
|
215 |
+
$logger->log('**PREPARING FOR RESTORE**');
|
216 |
|
217 |
+
if (! $this->license_active()){
|
218 |
+
fatal_error($task,'225','Restore is not available because license is not active.');
|
219 |
+
}
|
220 |
|
221 |
+
//PREPARE TASK
|
222 |
+
if (! class_exists('ZipArchive')){
|
223 |
+
fatal_error($task,'235','Zip Archive Class is not available.');
|
224 |
+
}
|
225 |
|
226 |
+
$logger->log('*DELETE RESTORE FOLDER*');
|
227 |
+
if ( ! $wp_restore->delete_restore_folder()){
|
228 |
+
fatal_error($task,'222','Restore folder could not be deleted.');
|
229 |
+
}
|
230 |
+
$logger->log('*END DELETE RESTORE FOLDER*');
|
231 |
|
232 |
+
$logger->log('*CREATE ROOT RESTORE FOLDER*');
|
233 |
+
if ( ! $wp_restore->create_restore_root_folder()){
|
234 |
+
fatal_error($task,'222','Root Restore folder could not be created.');
|
235 |
+
}
|
236 |
+
$logger->log('*END CREATE RESTORE FOLDER*');
|
237 |
|
238 |
+
$logger->log('*DELETE STAGED FOLDER*');
|
239 |
+
if ( ! $wp_restore->delete_staged_folders()){
|
240 |
+
fatal_error($task, '222','Staged folders could not be deleted.');
|
241 |
+
}
|
242 |
+
$logger->log('*END DELETE STAGED FOLDER*');
|
243 |
+
|
244 |
+
$logger->log('*UPDATE ZIP JOB META*');
|
245 |
+
//Get the zip list
|
246 |
+
$backup_path_pattern = $wp_restore->get_backup_folder_path() . '/' .$wp_restore->get_backup_name() . '*.zip' ;
|
247 |
+
$logger->log_info(__METHOD__,'Fetch backups pattern:' .$backup_path_pattern);
|
248 |
+
$backup_set = glob( $backup_path_pattern);
|
249 |
+
if ( count($backup_set)>0){
|
250 |
+
$restore_job->update_job_meta('backup_set',wp_slash($backup_set));
|
251 |
+
$restore_job->update_job_meta('backup_set_remaining',wp_slash($backup_set));
|
252 |
+
}else{
|
253 |
+
fatal_error($task,'222','No zip files found (pattern):' . $backup_path_pattern);
|
254 |
+
}
|
255 |
+
$logger->log('*END UPDATE ZIP JOB META*');
|
256 |
|
257 |
|
258 |
+
$logger->log( '*UPDATE SITE VALUES META*' );
|
259 |
+
$siteurl = $wp_restore->get_siteurl();
|
260 |
+
if (false===$siteurl){
|
261 |
+
fatal_error($task,'207','Unable to fetch site url.');
|
262 |
+
}else {
|
263 |
+
$restore_job->update_job_meta('current_siteurl',$siteurl);
|
264 |
+
}
|
265 |
|
266 |
+
$homeurl = $wp_restore->get_homeurl();
|
267 |
+
if (false===$homeurl){
|
268 |
+
fatal_error($task, '208','Unable to fetch home url.');
|
269 |
+
}else{
|
270 |
+
$restore_job->update_job_meta('current_homeurl',$homeurl);
|
271 |
+
}
|
272 |
|
273 |
+
$user_login = $wp_restore->get_user_login( $user_id );
|
274 |
+
if (false===$user_login) {
|
275 |
+
fatal_error($task,'209','Unable to fetch user login.');
|
276 |
+
}else{
|
277 |
+
$restore_job->update_job_meta('current_user_login',$user_login);
|
278 |
+
}
|
279 |
|
280 |
+
$user_pass = $wp_restore->get_user_pass( $user_id );
|
281 |
+
if (false===$user_pass){
|
282 |
+
fatal_error($task,'210','Unable to fetch user password.');
|
283 |
+
}else{
|
284 |
+
$restore_job->update_job_meta('current_user_pass_hash',$user_pass);
|
285 |
+
}
|
|
|
286 |
|
287 |
+
$user_email = $wp_restore->get_user_email( $user_id );
|
288 |
+
if (false===$user_email){
|
289 |
+
fatal_error($task,'211','Unable to fetch user email.');
|
290 |
+
} else{
|
291 |
+
$restore_job->update_job_meta('current_user_email',$user_email);
|
292 |
+
}
|
293 |
|
294 |
+
$logger->log( '*END UPDATE SITE VALUES META*' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
+
end_status($task);
|
297 |
+
$restore_job->set_task_complete();
|
298 |
+
$logger->log('**END PREPARING FOR RESTORE**');
|
|
|
|
|
299 |
|
300 |
+
return;
|
301 |
+
}
|
|
|
|
|
|
|
|
|
|
|
302 |
|
303 |
+
if ('task_unzip_backup_set'==$current_task) {
|
|
|
304 |
|
305 |
+
$logger->log( '**UNZIP BACKUP**' );
|
306 |
|
307 |
+
$task = 'unzipping';
|
308 |
+
start_status($task );
|
309 |
|
310 |
+
//get the list of plugins zips in folder
|
311 |
+
$backup_set_list=$restore_job->get_job_meta('backup_set_remaining');
|
312 |
+
$logger->log_info(__METHOD__,'Begin - Backup set list:');
|
313 |
+
$logger->log($backup_set_list);
|
314 |
+
if ( ! $wp_restore->unzip_archive_file( $backup_set_list) ) {
|
315 |
+
fatal_error($task,'203','Unable to unzip archive.');
|
316 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
+
array_shift( $backup_set_list ); //remove from list
|
319 |
+
$restore_job->update_job_meta('backup_set_remaining',wp_slash($backup_set_list));
|
320 |
+
|
321 |
+
if (count($backup_set_list)>0){
|
322 |
+
//CONTINUE
|
323 |
+
$logger->log('Continue unzipping backup set.');
|
324 |
+
$restore_job->set_task_queued();
|
325 |
+
} else{
|
326 |
+
//COMPLETE
|
327 |
+
$logger->log('Complete - All archives restored.');
|
328 |
+
end_status( $task);
|
329 |
+
$restore_job->set_task_complete();
|
330 |
+
$logger->log( '**END UNZIP BACKUP**' );
|
331 |
+
}
|
332 |
|
333 |
+
}
|
|
|
|
|
334 |
|
335 |
+
return;
|
336 |
|
337 |
}
|
338 |
|
339 |
+
//Validate the backup folder
|
340 |
+
if ('task_validate_backup'==$current_task) {
|
341 |
+
$logger->log_info(__METHOD__, '**VALIDATE BACKUP**' );
|
342 |
|
343 |
+
$task = 'validation';
|
344 |
+
start_status($task);
|
|
|
345 |
|
346 |
+
//Validate the restore folder
|
347 |
|
348 |
+
if ( ! $wp_restore->validate_restore_folder( )){
|
349 |
+
fatal_error($task,'204','Restore directory INVALID.');
|
350 |
+
}
|
351 |
+
|
352 |
+
$logger->log( '*VALIDATE MANIFEST*' );
|
353 |
+
$backup_set_list=$restore_job->get_job_meta('backup_set');
|
354 |
+
if ( $wp_restore->validate_manifest_file($backup_set_list,$error_code)===false){
|
355 |
+
if ($error_code==1){
|
356 |
+
fatal_error($task,'251','Empty manifest.');
|
357 |
}
|
358 |
+
|
359 |
+
if ($error_code==2){
|
360 |
+
fatal_error($task,'252','Missing zip file.');
|
361 |
+
}
|
362 |
+
|
363 |
+
if ($error_code==3){
|
364 |
+
fatal_error($task,'253','Zip file not in manifest.');
|
365 |
+
}
|
366 |
+
|
367 |
+
//shouldnt get here
|
368 |
+
fatal_error($task,'999','Unexpected error code:' . $error_code);
|
369 |
+
|
370 |
+
}
|
371 |
+
$logger->log( '*END VALIDATE MANIFEST*' );
|
372 |
+
|
373 |
+
$logger->log( '*VALIDATE SITEDATA FILE*' );
|
374 |
+
//validate the site data file
|
375 |
+
$site_info = $wp_restore->validate_siteinfo_file();
|
376 |
+
if ( $site_info===false){
|
377 |
+
fatal_error($task,'204','Site Data file INVALID.');
|
378 |
+
}else{
|
379 |
+
//save restore info to meta
|
380 |
+
$restore_job->update_job_meta('restore_site_info',$site_info);
|
381 |
}
|
382 |
|
383 |
+
//Check table prefix values FATAL - need to add link to article
|
384 |
+
if ( $table_prefix != $site_info['restore_table_prefix'] ) {
|
385 |
+
fatal_error($task,'221','Table prefix different from restore.');
|
386 |
+
}
|
387 |
|
388 |
+
//Check wordpress version
|
389 |
+
if ( get_bloginfo( 'version') != $site_info['restore_wp_version'] ) {
|
390 |
+
fatal_error($task,'226','Backup was created using different version of wordpress');
|
391 |
+
}
|
|
|
|
|
|
|
392 |
|
393 |
+
|
394 |
+
//Check wpbackitup version
|
395 |
+
//Only major versions differences should fail
|
396 |
+
//1.9.2.8 and 1.9.2.9 are ok
|
397 |
+
//1.9.2 and 1.10 are NOT
|
398 |
+
//Even minor numbers are final releases
|
399 |
+
//Odd minor numbers are pre-releases
|
400 |
+
$restore_wpbackitup_version = $site_info['restore_wpbackitup_version'];
|
401 |
+
$restore_wpbackitup_version = explode('.', $restore_wpbackitup_version);
|
402 |
+
$current_wpbackitup_version = explode('.', WPBACKITUP__VERSION);
|
403 |
+
|
404 |
+
$logger->log_info(__METHOD__,'Backup Created with WP BackItUp Version :');
|
405 |
+
$logger->log($restore_wpbackitup_version);
|
406 |
+
|
407 |
+
//Check version if not 1.9
|
408 |
+
if ("1" != $restore_wpbackitup_version[0] || "9" !=$restore_wpbackitup_version[1]){
|
409 |
+
//If major version is different
|
410 |
+
if ($restore_wpbackitup_version[0] != $current_wpbackitup_version[0] ||
|
411 |
+
$restore_wpbackitup_version[1] != $current_wpbackitup_version[1] ) {
|
412 |
+
fatal_error($task,'227','Backup was created using different version of WP BackItUp');
|
413 |
+
}
|
414 |
}
|
415 |
+
$logger->log( '*END VALIDATE SITEDATA FILE*' );
|
|
|
416 |
|
417 |
+
|
418 |
+
$logger->log( '*VALIDATE SQL FILE EXISTS*' );
|
419 |
+
if ( ! $wp_restore->validate_SQL_exists( )){
|
420 |
+
fatal_error($task,'216','NO Database backups in backup.');
|
421 |
+
}
|
422 |
+
$logger->log( '*END VALIDATE SQL FILE EXISTS*' );
|
423 |
+
end_status($task);
|
424 |
+
|
425 |
+
$logger->log('*DEACTIVATE ACTIVE PLUGINS*');
|
426 |
+
$task='deactivate_plugins';
|
427 |
+
start_status($task);
|
428 |
+
$wp_restore->deactivate_plugins();
|
429 |
+
end_status($task);
|
430 |
+
$logger->log('*END DEACTIVATE ACTIVE PLUGINS*');
|
431 |
+
|
432 |
+
$restore_job->set_task_complete();
|
433 |
+
$logger->log( '**END VALIDATE BACKUP**' );
|
434 |
+
|
435 |
+
return;
|
436 |
}
|
437 |
|
|
|
|
|
|
|
438 |
|
439 |
+
//Create the DB restore point
|
440 |
+
if ('task_create_checkpoint'==$current_task) {
|
441 |
+
|
442 |
+
$logger->log('**CREATE RESTORE POINT**');
|
443 |
+
$task = 'restore_point';
|
444 |
+
start_status($task);
|
445 |
+
|
446 |
+
if ( ! $wp_restore->export_database()){
|
447 |
+
fatal_error($task,'205','Cant backup database.');
|
448 |
+
}
|
449 |
+
|
450 |
+
$restore_job->set_task_complete();
|
451 |
+
end_status($task);
|
452 |
+
$logger->log('**END CREATE RESTORE POINT**');
|
453 |
+
|
454 |
+
return;
|
455 |
}
|
456 |
|
|
|
|
|
|
|
|
|
457 |
|
458 |
+
//Stage WP content folders
|
459 |
+
if ('task_stage_wpcontent'==$current_task) {
|
460 |
+
|
461 |
+
$logger->log('*STAGE WP-CONTENT*');
|
462 |
+
$task = 'stage_wpcontent';
|
463 |
+
|
464 |
+
start_status($task);
|
465 |
+
|
466 |
+
$folder_stage_suffix = $wp_restore->get_restore_staging_suffix();
|
467 |
+
|
468 |
+
//Stage all but plugins
|
469 |
+
|
470 |
+
$logger->log('*STAGE THEMES*');
|
471 |
+
$from_folder_name = $wp_restore->get_restore_root_folder_path() .'/' .$wp_restore::THEMESPATH;
|
472 |
+
$to_folder_name = WPBACKITUP__THEMES_ROOT_PATH . $folder_stage_suffix;
|
473 |
+
if (! $wp_restore->rename_folder($from_folder_name,$to_folder_name)){
|
474 |
+
fatal_error($task,'219','Cant stage themes.',false);
|
475 |
+
$wp_restore->delete_staged_folders();
|
476 |
+
end_restore();
|
477 |
+
}
|
478 |
+
$logger->log('*END STAGE THEMES*');
|
479 |
+
|
480 |
+
$logger->log('*STAGE UPLOADS*');
|
481 |
+
$from_folder_name = $wp_restore->get_restore_root_folder_path() .'/' .$wp_restore::UPLOADPATH;
|
482 |
+
$upload_array = wp_upload_dir();
|
483 |
+
$uploads_root_path = $upload_array['basedir'];
|
484 |
+
$to_folder_name = $uploads_root_path . $folder_stage_suffix;
|
485 |
+
if (! $wp_restore->rename_folder($from_folder_name,$to_folder_name)){
|
486 |
+
fatal_error($task,'219','Cant stage uploads.',false);
|
487 |
+
$wp_restore->delete_staged_folders();
|
488 |
+
end_restore();
|
489 |
+
}
|
490 |
+
$logger->log('*END STAGE UPLOADS*');
|
491 |
+
|
492 |
+
$logger->log('*STAGE OTHER FOLDERS*');
|
493 |
+
$other_list = glob($wp_restore->get_restore_root_folder_path() .'/' .$wp_restore::OTHERPATH .'/*',GLOB_ONLYDIR|GLOB_NOSORT);
|
494 |
+
foreach ( $other_list as $from_folder_name ) {
|
495 |
+
$to_folder_name = WPBACKITUP__CONTENT_PATH .'/' .basename($from_folder_name) . $folder_stage_suffix;
|
496 |
+
if (! $wp_restore->rename_folder($from_folder_name,$to_folder_name)) {
|
497 |
+
fatal_error($task,'219','Cant stage other.',false);
|
498 |
+
$wp_restore->delete_staged_folders();
|
499 |
+
end_restore();
|
500 |
+
}
|
501 |
}
|
502 |
+
$logger->log('*END STAGE OTHER FOLDERS*');
|
503 |
+
end_status($task);
|
504 |
|
505 |
+
$restore_job->set_task_complete();
|
|
|
506 |
|
507 |
+
$logger->log('**END STAGE WP-CONTENT**');
|
|
|
|
|
508 |
|
509 |
+
return;
|
510 |
}
|
511 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
512 |
|
513 |
+
//Rename the staged folders to current
|
514 |
+
if ('task_restore_wpcontent'==$current_task) {
|
515 |
+
|
516 |
+
$logger->log('**RESTORE WPCONTENT**');
|
517 |
+
$task ='restore_wpcontent';
|
518 |
+
start_status($task);
|
519 |
|
520 |
+
$logger->log('*RESTORE MAIN WPCONTENT*');
|
521 |
+
$wpcontent_restore =$wp_restore->restore_wpcontent();
|
522 |
+
if (! $wpcontent_restore===true) {
|
523 |
+
//array with failed list returned
|
524 |
+
//If any of them fail call it done.
|
525 |
+
warning('300','Cant restore all WP content.');
|
526 |
}
|
527 |
+
$logger->log('*END RESTORE MAIN WPCONTENT*');
|
528 |
|
529 |
+
$logger->log('*RESTORE PLUGINS*');
|
530 |
+
$plugin_restore = $wp_restore->restore_plugins();
|
531 |
+
if (! $plugin_restore ===true) {
|
532 |
+
//array with fail list returned
|
533 |
+
warning('305', 'Couldnt restore all plugins.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
534 |
}
|
535 |
+
|
536 |
+
$logger->log('*END RESTORE PLUGINS*');
|
537 |
+
|
538 |
+
$restore_job->set_task_complete();
|
539 |
+
end_status($task);
|
540 |
+
$logger->log('**END RESTORE WPCONTENT**');
|
541 |
+
|
542 |
+
return;
|
543 |
}
|
544 |
|
545 |
+
//restore the DB
|
546 |
+
if ('task_restore_database'==$current_task) {
|
|
|
|
|
547 |
|
548 |
+
$logger->log('**RESTORE DATABASE**');
|
549 |
+
$task ='restore_database';
|
550 |
+
start_status($task);
|
551 |
+
|
552 |
+
$current_siteurl= $restore_job->get_job_meta('current_siteurl');
|
553 |
+
$current_homeurl= $restore_job->get_job_meta('current_homeurl');
|
554 |
+
|
555 |
+
$current_user_id=$restore_job->get_job_meta('user_id');
|
556 |
+
$current_user_login=$restore_job->get_job_meta('current_user_login');
|
557 |
+
$current_user_pass_hash= $restore_job->get_job_meta('current_user_pass_hash');
|
558 |
+
$current_user_email=$restore_job->get_job_meta('current_user_email');
|
559 |
+
|
560 |
+
$user_full_name='';
|
561 |
+
$current_user = get_user_by('id',$current_user_id);
|
562 |
+
if (false!==$current_user){
|
563 |
+
$user_full_name = $current_user->first_name . ' ' .$current_user->last_name;
|
564 |
}
|
565 |
|
566 |
+
//Not going to use the restore Point SQL because IF the import failed then DB may be intact
|
567 |
+
if ( ! $wp_restore->restore_database()) {
|
568 |
+
fatal_error($task,'212','Database NOT restored.');
|
569 |
+
//Do we want to recover the DB ?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
570 |
}
|
|
|
|
|
|
|
571 |
|
572 |
+
end_status($task);
|
573 |
+
$logger->log('**END RESTORE DATABASE**');
|
574 |
+
|
575 |
+
$logger->log('*UPDATE DATABASE VALUES*');
|
576 |
+
|
577 |
+
//update the session cookie
|
578 |
+
wp_set_auth_cookie( $user_id, true);
|
579 |
+
|
580 |
+
WPBackItUp_Job::cancel_all_jobs(); //Cancel any jobs that were in the restored DB
|
581 |
+
|
582 |
+
start_status('update_user');
|
583 |
+
//Restored DB so current user may not be there.
|
584 |
+
//If current user id doesnt exist then create it
|
585 |
+
//if exists update to current properties
|
586 |
+
if ( ! $wp_restore->update_credentials($user_id, $user_full_name, $current_user_login, $current_user_pass_hash, $current_user_email,$table_prefix)){
|
587 |
+
warning('215', 'Cant update user credentials.');
|
588 |
+
}
|
589 |
+
end_status('update_user');
|
590 |
+
|
591 |
+
start_status('update_site_info');
|
592 |
+
if ( ! $wp_restore->update_siteurl($table_prefix,$current_siteurl)){
|
593 |
+
warning('213', 'Cant update site url.');
|
594 |
+
}
|
595 |
+
|
596 |
+
if ( ! $wp_restore->update_homeurl($table_prefix, $current_homeurl)){
|
597 |
+
warning('214', 'Cant update home url.');
|
598 |
+
}
|
599 |
+
end_status('update_site_info');
|
600 |
+
|
601 |
+
//DONT NEED TO UPDATE TASKS - DB RESTORED
|
602 |
+
|
603 |
+
$logger->log('*ACTIVATE PLUGINS*');
|
604 |
+
start_status('activate_plugins');
|
605 |
+
$wp_restore->activate_plugins();
|
606 |
+
end_status('activate_plugins');
|
607 |
+
$logger->log('*END ACTIVATE PLUGINS*');
|
608 |
+
|
609 |
|
610 |
+
start_status('update_permalinks');
|
611 |
+
if (! $wp_restore->update_permalinks()){
|
612 |
+
//dont do anything
|
|
|
|
|
613 |
}
|
614 |
+
end_status('update_permalinks');
|
615 |
+
$logger->log('*END UPDATE DATABASE VALUES*');
|
616 |
}
|
617 |
|
618 |
+
//**************************************************************
|
619 |
+
// After the database is restored all the job data will be gone
|
620 |
+
//
|
621 |
+
// NO MORE TASKS OR JOB DATA AFTER THIS POINT
|
622 |
+
//
|
623 |
+
//**************************************************************
|
624 |
|
625 |
+
|
626 |
+
//schedule a cleanup? with job id? for staged folder
|
627 |
+
set_status_success();
|
628 |
+
$logger->log('Restore completed successfully');
|
629 |
+
$logger->log('***END RESTORE***');
|
630 |
+
|
631 |
+
echo('Restore has completed successfully.');
|
632 |
+
end_restore(null,true);
|
633 |
+
|
634 |
+
exit;
|
635 |
+
|
636 |
+
/******************/
|
637 |
+
/*** Functions ***/
|
638 |
+
/******************/
|
639 |
+
function fatal_error($process,$error_code,$error_message, $end=true){
|
640 |
+
global $restore_job, $failure, $logger;
|
641 |
+
|
642 |
+
$logger->log_error(__METHOD__,$error_message);
|
643 |
+
$restore_job->set_task_error($error_code);
|
644 |
+
write_response_file_error($error_code,$error_message);
|
645 |
+
|
646 |
+
set_status($process,$failure,true);
|
647 |
+
write_fatal_error_status('error' .$error_code);
|
648 |
+
|
649 |
+
if ($end) {
|
650 |
+
end_restore();
|
651 |
}
|
|
|
|
|
652 |
}
|
653 |
|
654 |
+
function warning($error_code,$warning_message) {
|
655 |
+
global $logger, $status_array,$warning;
|
|
|
656 |
|
657 |
+
$logger->log_warning(__METHOD__, $warning_message);
|
|
|
658 |
|
659 |
+
//Add warning to array
|
660 |
+
$status_array['warning' .$error_code]=$warning;
|
661 |
+
write_restore_status();
|
662 |
+
}
|
|
|
663 |
|
664 |
+
function set_status($process,$status,$flush){
|
665 |
+
global $wp_restore,$logger;
|
666 |
+
global $status_array,$complete;
|
|
|
667 |
|
668 |
+
$status_array[$process]=$status;
|
|
|
|
|
|
|
|
|
669 |
|
670 |
+
//Mark all the others complete and flush
|
671 |
+
foreach ($status_array as $key => $value) {
|
672 |
+
if ($process==$key) {
|
673 |
+
break;
|
674 |
+
}else{
|
675 |
+
$status_array[$key]=$complete;
|
676 |
}
|
677 |
}
|
678 |
+
|
679 |
+
if ($flush) write_restore_status();
|
680 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
681 |
}
|
682 |
|
683 |
+
//write Response Log
|
684 |
+
function write_response_file_error($error_code,$error_message) {
|
685 |
+
|
686 |
+
$jsonResponse = new stdClass();
|
687 |
+
$jsonResponse->restoreStatus = 'error';
|
688 |
+
$jsonResponse->errorCode = $error_code;
|
689 |
+
$jsonResponse->restoreMessage = $error_message;
|
690 |
+
|
691 |
+
write_response_file($jsonResponse);
|
|
|
|
|
|
|
|
|
|
|
|
|
692 |
}
|
693 |
|
694 |
+
//write Response Log
|
695 |
+
function write_response_file_success() {
|
696 |
|
697 |
+
$jsonResponse = new stdClass();
|
698 |
+
$jsonResponse->backupStatus = 'success';
|
699 |
+
$jsonResponse->backupMessage = 'success';
|
700 |
+
|
701 |
+
write_response_file($jsonResponse);
|
702 |
+
}
|
703 |
+
|
704 |
+
|
705 |
+
//write Response Log
|
706 |
+
function write_response_file($JSON_Response) {
|
707 |
global $logger;
|
|
|
708 |
|
709 |
+
$json_response = json_encode($JSON_Response);
|
710 |
+
$logger->log('Write response file:' . $json_response);
|
711 |
+
|
712 |
+
$fh=get_response_file();
|
713 |
+
fwrite($fh, $json_response);
|
714 |
+
fclose($fh);
|
715 |
+
}
|
716 |
|
717 |
+
//Get Response Log
|
718 |
+
function get_response_file() {
|
719 |
+
global $logger;
|
720 |
+
$response_file_path = WPBACKITUP__PLUGIN_PATH .'logs/restore_response.log';
|
721 |
+
$filesytem = new WPBackItUp_FileSystem($logger);
|
722 |
+
return $filesytem->get_file_handle($response_file_path,false);
|
723 |
+
}
|
724 |
|
725 |
+
function get_job_log_name($timestamp){
|
|
|
|
|
726 |
|
727 |
+
$url = home_url();
|
728 |
+
$url = str_replace('http://','',$url);
|
729 |
+
$url = str_replace('https://','',$url);
|
730 |
+
$url = str_replace('/','-',$url);
|
731 |
+
$fileUTCDateTime=$timestamp;//current_time( 'timestamp' );
|
732 |
+
$localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
|
733 |
+
$job_log_name = 'Restore_' . $url .'_' .$localDateTime;
|
734 |
|
735 |
+
return $job_log_name;
|
736 |
+
}
|
|
|
737 |
|
738 |
+
//Get Status Log
|
739 |
+
function get_restore_Log() {
|
740 |
+
global $logger;
|
741 |
+
|
742 |
+
$status_file_path = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
|
743 |
$filesystem = new WPBackItUp_FileSystem($logger);
|
744 |
+
return $filesystem->get_file_handle($status_file_path);
|
745 |
+
|
746 |
+
}
|
747 |
+
|
748 |
+
function write_fatal_error_status($status_code) {
|
749 |
+
global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
|
750 |
+
|
751 |
+
//Find the active status and set to failure
|
752 |
+
foreach ($status_array as $key => $value) {
|
753 |
+
if ($value==$active){
|
754 |
+
$status_array[$key]=$failure;
|
|
|
|
|
|
|
755 |
}
|
756 |
}
|
757 |
|
758 |
+
//Add failure to array
|
759 |
+
$status_array[$status_code]=$failure;
|
760 |
+
write_restore_status();
|
761 |
}
|
762 |
|
|
|
|
|
|
|
|
|
763 |
|
|
|
764 |
|
765 |
+
function write_restore_status() {
|
766 |
+
global $status_array;
|
767 |
+
$fh=get_restore_Log();
|
768 |
+
|
769 |
+
foreach ($status_array as $key => $value) {
|
770 |
+
fwrite($fh, '<div class="' . $key . '">' . $value .'</div>');
|
771 |
+
}
|
772 |
+
fclose($fh);
|
773 |
+
}
|
774 |
|
775 |
+
function start_status($process){
|
776 |
+
global $wp_restore,$active;
|
|
|
777 |
|
778 |
+
set_status($process,$active,true);
|
779 |
+
$wp_restore->save_process_status($process,'started');
|
780 |
+
}
|
781 |
|
782 |
+
function end_status($process){
|
783 |
+
global $wp_restore,$complete;
|
|
|
784 |
|
785 |
+
set_status($process,$complete,false);
|
786 |
+
$wp_restore->save_process_status($process,'completed');
|
787 |
+
}
|
|
|
788 |
|
|
|
|
|
|
|
789 |
|
790 |
+
function set_status_success(){
|
791 |
+
global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
|
792 |
+
global $active;
|
|
|
|
|
793 |
|
794 |
+
$status_array['finalinfo']=$success;
|
795 |
+
write_restore_status();
|
796 |
}
|
797 |
|
798 |
+
function end_restore($err=null, $success=null){
|
799 |
+
global $WPBackitup, $wp_restore, $logger;
|
|
|
|
|
|
|
800 |
|
801 |
+
if (true===$success) $logger->log("Backup completed: SUCCESS");
|
802 |
+
if (false===$success) $logger->log("Backup completed: ERROR");
|
803 |
|
804 |
+
$logger->log("*** END BACKUP ***");
|
805 |
+
|
806 |
+
//Zip up all the logs
|
807 |
+
// $zip_file_path =$wp_restore->zip_logs();
|
808 |
+
|
809 |
+
//Email the log
|
810 |
+
// $notification_email = $WPBackitup->get_option('notification_email');
|
811 |
+
// $logs_attachment = array( $zip_file_path );
|
812 |
+
// $wp_restore->send_notification_email($err, $success,$logs_attachment,$notification_email);
|
813 |
+
|
814 |
+
//Release the lock
|
815 |
+
WPBackItUp_Backup::end();
|
816 |
+
|
817 |
+
//Close the logger
|
818 |
+
$logger->close_file();
|
819 |
+
|
820 |
+
echo('Backup has completed');
|
821 |
+
exit(0);
|
822 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/includes/listlogs.php
DELETED
@@ -1,71 +0,0 @@
|
|
1 |
-
<?php if (!defined ('ABSPATH')) die('No direct access allowed.');
|
2 |
-
|
3 |
-
//http://localhost/wp-390/wp-admin/admin-post.php?action=listlogs
|
4 |
-
//http://localhost/wp-390/wp-admin/admin-post.php?action=listlogs&log=test
|
5 |
-
|
6 |
-
$backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
|
7 |
-
$plugin_log_folder = WPBACKITUP__PLUGIN_PATH .'/logs/';
|
8 |
-
|
9 |
-
//List the log files
|
10 |
-
if (!isset($_REQUEST['viewlog_log']) && empty($_REQUEST['log']) ){
|
11 |
-
|
12 |
-
//Get Zip File List
|
13 |
-
$log_file_list = glob($backup_folder_root . "*.log");
|
14 |
-
if (!empty($log_file_list)) {
|
15 |
-
foreach ($log_file_list as $file)
|
16 |
-
{
|
17 |
-
$url='admin-post.php?action=listlogs&log=' .urlencode (basename($file,'.log'));
|
18 |
-
$filename = basename($file);
|
19 |
-
echo('<a href="' . $url .'" target="_blank">' .$filename .'</a></br>');
|
20 |
-
|
21 |
-
}
|
22 |
-
} else {
|
23 |
-
echo('No logs in backup folder<br>');
|
24 |
-
}
|
25 |
-
|
26 |
-
//Get logs in logs folder
|
27 |
-
$log_file_list = glob($plugin_log_folder . "*.log");
|
28 |
-
if (!empty($log_file_list)) {
|
29 |
-
foreach ($log_file_list as $file)
|
30 |
-
{
|
31 |
-
$url='admin-post.php?action=listlogs&log=' .urlencode (basename($file,'.log'));
|
32 |
-
$filename = basename($file);
|
33 |
-
echo('<a href="' . $url .'" target="_blank">' .$filename .'</a></br>');
|
34 |
-
|
35 |
-
}
|
36 |
-
} else {
|
37 |
-
echo('No logs in logs folder<br>');
|
38 |
-
}
|
39 |
-
die();
|
40 |
-
}
|
41 |
-
|
42 |
-
if (isset($_REQUEST['log']) && !empty($_REQUEST['log']) ){
|
43 |
-
|
44 |
-
//Check backups first
|
45 |
-
$log_filename = $_REQUEST['log'] . '.log';
|
46 |
-
$log_path = $backup_folder_root .$log_filename;
|
47 |
-
if(file_exists($log_path) ) {
|
48 |
-
stream_file($log_path, $log_filename);
|
49 |
-
} else {
|
50 |
-
//Check logs
|
51 |
-
$log_path = $plugin_log_folder .$log_filename;;
|
52 |
-
if(file_exists($log_path) ) {
|
53 |
-
stream_file($log_path, $log_filename);
|
54 |
-
} else {
|
55 |
-
echo('No log file found in folder<br>');
|
56 |
-
}
|
57 |
-
}
|
58 |
-
die();
|
59 |
-
}
|
60 |
-
|
61 |
-
|
62 |
-
//---------------FUNCTIONS ----------------------
|
63 |
-
function stream_file($log_path, $log_filename){
|
64 |
-
header ('Content-type: octet/stream');
|
65 |
-
header("Content-Disposition: attachment; filename=$log_filename");
|
66 |
-
header("Content-Length: ".filesize($log_path));
|
67 |
-
ob_get_clean();
|
68 |
-
readfile($log_path);
|
69 |
-
if (ob_get_level()>1) ob_end_flush();
|
70 |
-
}
|
71 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/includes/upload.php
DELETED
@@ -1,113 +0,0 @@
|
|
1 |
-
<?php if (!defined ('ABSPATH')) die('No direct access allowed (upload)');
|
2 |
-
/**
|
3 |
-
* WP BackItUp File Upload Handler
|
4 |
-
*
|
5 |
-
* @package WP BackItUp Pro
|
6 |
-
*
|
7 |
-
* @author cssimmon
|
8 |
-
*
|
9 |
-
*/
|
10 |
-
|
11 |
-
/*** Includes ***/
|
12 |
-
|
13 |
-
|
14 |
-
/*** Globals ***/
|
15 |
-
global $logger;
|
16 |
-
$logger = new WPBackItUp_Logger(true,null,'debug_upload');
|
17 |
-
$backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
|
18 |
-
|
19 |
-
//*****************//
|
20 |
-
//*** MAIN CODE ***//
|
21 |
-
//*****************//
|
22 |
-
$logger->log('***BEGIN UPLOAD***');
|
23 |
-
|
24 |
-
//Initialize return class
|
25 |
-
$rtnData = new stdClass();
|
26 |
-
$rtnData->file = '';
|
27 |
-
$rtnData->zip_link = '';
|
28 |
-
$rtnData->msg = '';
|
29 |
-
$rtnData->error = '';
|
30 |
-
|
31 |
-
|
32 |
-
if ( !wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-upload-file') || !check_admin_referer( WPBACKITUP__NAMESPACE .'-upload-file', '_wpnonce' )) {
|
33 |
-
$rtnData->error ='Invalid Nonce';
|
34 |
-
|
35 |
-
}else{
|
36 |
-
foreach ($_FILES as $key => $value)
|
37 |
-
{
|
38 |
-
//GET FILE CONTENT
|
39 |
-
$logger->log("File Uploaded Key: " . $key);
|
40 |
-
$logger->log("File Uploaded Value");
|
41 |
-
$logger->log($value);
|
42 |
-
|
43 |
-
$temp_file_path= $value['tmp_name'];
|
44 |
-
$original_file_name = $value['name'];
|
45 |
-
$save_to_file_path = $backup_folder_root . $original_file_name;
|
46 |
-
$error = $value['error'];
|
47 |
-
$size = $value['size'];
|
48 |
-
$error_message = get_error_message($error);
|
49 |
-
|
50 |
-
$logger->log("Temp File Uploaded: " . $temp_file_path);
|
51 |
-
$logger->log("Original File Name: " .$original_file_name);
|
52 |
-
$logger->log("Save to File path: " .$save_to_file_path);
|
53 |
-
$logger->log("Error: " .$error);
|
54 |
-
$logger->log("Size: " .$size);
|
55 |
-
$logger->log("Error Message:" . $error_message);
|
56 |
-
|
57 |
-
//Handle the file upload
|
58 |
-
if (is_uploaded_file($value['tmp_name'])) {
|
59 |
-
if (move_uploaded_file($value['tmp_name'], $save_to_file_path)) {
|
60 |
-
$rtnData->msg = 'success';
|
61 |
-
$rtnData->file = $original_file_name;
|
62 |
-
$rtnData->zip_link = WPBACKITUP__BACKUP_URL .'/' .$original_file_name;
|
63 |
-
} else {
|
64 |
-
$error_message='File could not be saved to backup folder.';
|
65 |
-
}
|
66 |
-
}
|
67 |
-
|
68 |
-
$rtnData->error = $error_message;
|
69 |
-
break; //Only one file is ever uploaded
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
echo json_encode($rtnData);
|
74 |
-
|
75 |
-
$logger->log('Upload completed successfully');
|
76 |
-
$logger->log('***END UPLOAD***');
|
77 |
-
die();
|
78 |
-
|
79 |
-
/******************/
|
80 |
-
/*** Functions ***/
|
81 |
-
/******************/
|
82 |
-
function get_error_message($code)
|
83 |
-
{
|
84 |
-
if (0==$code) return '';
|
85 |
-
|
86 |
-
switch ($code) {
|
87 |
-
case UPLOAD_ERR_INI_SIZE:
|
88 |
-
$message = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
|
89 |
-
break;
|
90 |
-
case UPLOAD_ERR_FORM_SIZE:
|
91 |
-
$message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
|
92 |
-
break;
|
93 |
-
case UPLOAD_ERR_PARTIAL:
|
94 |
-
$message = "The uploaded file was only partially uploaded";
|
95 |
-
break;
|
96 |
-
case UPLOAD_ERR_NO_FILE:
|
97 |
-
$message = "No file was uploaded";
|
98 |
-
break;
|
99 |
-
case UPLOAD_ERR_NO_TMP_DIR:
|
100 |
-
$message = "Missing a temporary folder";
|
101 |
-
break;
|
102 |
-
case UPLOAD_ERR_CANT_WRITE:
|
103 |
-
$message = "Failed to write file to disk";
|
104 |
-
break;
|
105 |
-
case UPLOAD_ERR_EXTENSION:
|
106 |
-
$message = "File upload stopped by extension";
|
107 |
-
break;
|
108 |
-
default:
|
109 |
-
$message = "Unknown upload error";
|
110 |
-
break;
|
111 |
-
}
|
112 |
-
return $message;
|
113 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== WP Backitup ===
|
2 |
Contributors: cssimmon,jcpeden
|
3 |
Donate link: http://www.wpbackitup.com
|
4 |
-
Tags:backup,back up,backups,backup wordpress,backup database,backup plugin,backup and restore,database backup,database restore,db backup,db restore,download database,full backup,restore,restore database,restore wordpress,restore wordpress backup,restoring wordpress,website backup,wordpress backup,wordpress restore
|
5 |
Requires at least: 3.8.0
|
6 |
-
Tested up to: 4.1
|
7 |
Stable tag: 1.9.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -151,6 +151,16 @@ Our online documentation and full list of FAQs can be found at [www.wpbackitup.c
|
|
151 |
|
152 |
|
153 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
= 1.9.2 =
|
155 |
* New Features: Added WordPress 4.0.1 support
|
156 |
* New Features: Major Security Enhancements
|
1 |
=== WP Backitup ===
|
2 |
Contributors: cssimmon,jcpeden
|
3 |
Donate link: http://www.wpbackitup.com
|
4 |
+
Tags: backup, back up, backups, backup wordpress, backup database, backup plugin, backup and restore, database, database backup, database restore, db, db backup, db restore, download database, full backup, mysql backup, restore, restore database,restore wordpress, restore wordpress backup,restoring wordpress, website backup, wordpress backup, wordpress restore, plugin, backup buddy
|
5 |
Requires at least: 3.8.0
|
6 |
+
Tested up to: 4.0.1
|
7 |
Stable tag: 1.9.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
151 |
|
152 |
|
153 |
== Changelog ==
|
154 |
+
= 1.10.0 =
|
155 |
+
* New Feature: Add support request to plugin
|
156 |
+
* New Feature: Add large backup support
|
157 |
+
* New Feature: Add drag and drop uploads
|
158 |
+
* New Feature: Split backup into separate archives(database,plugins,themes,uploads)
|
159 |
+
* New Feature: Add download popup to allow user to selectively download backup archives
|
160 |
+
* Updates: Security Enhancements
|
161 |
+
* Updates: Miscellaneous User Experience Improvements
|
162 |
+
* Updates: Significant Performance Improvements
|
163 |
+
|
164 |
= 1.9.2 =
|
165 |
* New Features: Added WordPress 4.0.1 support
|
166 |
* New Features: Major Security Enhancements
|
views/backup.php
CHANGED
@@ -25,7 +25,7 @@
|
|
25 |
$formatted_expired_date = date('F j, Y',strtotime($license_Expires));
|
26 |
|
27 |
// get retention number set
|
28 |
-
$
|
29 |
|
30 |
$lite_registration_first_name = $this->lite_registration_first_name();
|
31 |
$lite_registration_email = $this->lite_registration_email();
|
@@ -49,6 +49,71 @@
|
|
49 |
}else{
|
50 |
$backup_folder_exists=true;
|
51 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
?>
|
53 |
|
54 |
<?php //Add Notification to UI
|
@@ -75,8 +140,10 @@ if (!$backup_folder_exists) {
|
|
75 |
<script type="text/javascript">var __namespace = "<?php echo($namespace); ?>";</script>
|
76 |
<div class="wrap">
|
77 |
<h2><?php echo $page_title; ?></h2>
|
|
|
78 |
<div id="content">
|
79 |
|
|
|
80 |
<!--Manual Backups-->
|
81 |
<div class="widget">
|
82 |
<h3><i class="fa fa-cogs"></i> <?php _e('Backup', $namespace); ?></h3>
|
@@ -134,58 +201,28 @@ if (!$backup_folder_exists) {
|
|
134 |
<!--View Log Form-->
|
135 |
<form id = "viewlog" name = "viewlog" action="admin-post.php" method="post">
|
136 |
<input type="hidden" name="action" value="viewlog">
|
137 |
-
<input type="hidden" id="
|
138 |
<?php wp_nonce_field($this->namespace . "-viewlog"); ?>
|
139 |
</form>
|
140 |
|
141 |
<form id = "download_backup" name = "download_backup" action="admin-post.php" method="post">
|
142 |
<input type="hidden" name="action" value="download_backup">
|
143 |
-
<input type="hidden" id="
|
144 |
<?php wp_nonce_field($this->namespace . "-download_backup"); ?>
|
145 |
</form>
|
146 |
|
147 |
<table class="widefat" id="datatable">
|
148 |
<?php
|
149 |
-
|
150 |
-
//Get Zip File List
|
151 |
-
$file_list = glob($backup_folder_root . "/*.zip");
|
152 |
-
$backup_log_filelist = glob($backup_folder_root . "/*.log");
|
153 |
-
|
154 |
-
//$logs_log_filelist = glob($logs_folder_root . "/Backup_*.log");
|
155 |
-
//$file_list = array_merge($zip_filelist,$logs_log_filelist);
|
156 |
-
//print_r($file_list);
|
157 |
|
158 |
-
if (
|
159 |
{
|
160 |
-
//Sort by Date Time
|
161 |
-
usort($file_list, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
|
162 |
-
|
163 |
$i = 0;
|
164 |
-
foreach ($
|
165 |
{
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
$
|
170 |
-
$file_type= substr($filename, -3);
|
171 |
-
//Local Date Time
|
172 |
-
$file_datetime = get_date_from_gmt(date('Y-m-d H:i:s', filemtime($file)), 'Y-m-d g:i a');
|
173 |
-
|
174 |
-
$logExists = false;
|
175 |
-
if ('zip'==$file_type) {
|
176 |
-
$zip_exists = true;
|
177 |
-
$log_file = str_replace( '.zip', '.log', $file );
|
178 |
-
$log_filename = basename( $log_file );
|
179 |
-
if ( is_array( $backup_log_filelist ) && in_array( $log_file, $backup_log_filelist ) ) {
|
180 |
-
$logExists = true;
|
181 |
-
}
|
182 |
-
}else{
|
183 |
-
$zip_exists = false;
|
184 |
-
$log_file = $filename;
|
185 |
-
$log_filename = $filename;
|
186 |
-
$logExists = true;
|
187 |
-
}
|
188 |
-
//------
|
189 |
|
190 |
$class = $i % 2 == 0 ? 'class="alternate"' : '';
|
191 |
?>
|
@@ -193,21 +230,18 @@ if (!$backup_folder_exists) {
|
|
193 |
<tr <?php echo $class ?> id="row<?php echo $i; ?>">
|
194 |
<td><?php echo $file_datetime ?></td>
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
<?php else: ?>
|
201 |
-
<td> </td>
|
202 |
-
<?php endif; ?>
|
203 |
|
204 |
-
<?php if (($
|
205 |
-
<td><a class='viewloglink' href="<?php echo
|
206 |
<?php else: ?>
|
207 |
<td> </td>
|
208 |
<?php endif; ?>
|
209 |
|
210 |
-
<td><a href="#" title="<?php echo $
|
211 |
</tr>
|
212 |
|
213 |
<?php
|
@@ -216,7 +250,7 @@ if (!$backup_folder_exists) {
|
|
216 |
}
|
217 |
else
|
218 |
{
|
219 |
-
echo '<tr id="nofiles"><td colspan="3">No backup archives
|
220 |
}
|
221 |
?>
|
222 |
</table>
|
@@ -236,7 +270,6 @@ if (!$backup_folder_exists) {
|
|
236 |
<li><?php _e('Nothing to report', $namespace); ?></li>
|
237 |
</ul>
|
238 |
|
239 |
-
|
240 |
<!--backup status messages-->
|
241 |
<ul class="backup-status">
|
242 |
<li class="preparing"><?php _e('Preparing for backup', $namespace); ?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
@@ -246,9 +279,8 @@ if (!$backup_folder_exists) {
|
|
246 |
<li class='backup_plugins'><?php _e('Backing up plugins', $namespace); ?>...<span class='status-icon'><img class="backup_plugins-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
247 |
<li class='backup_uploads'><?php _e('Backing up uploads', $namespace); ?>...<span class='status-icon'><img class="backup_uploads-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
248 |
<li class='backup_other'><?php _e('Backing up everything else', $namespace); ?>...<span class='status-icon'><img class="backup_other-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
249 |
-
<li class='finalize_backup'><?php _e('Finalizing backup', $namespace); ?>...<span class='status-icon'><img class="finalize_backup-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
250 |
<li class='validate_backup'><?php _e('Validating backup', $namespace); ?>...<span class='status-icon'><img class="validate_backup-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
251 |
-
<li class='
|
252 |
</ul>
|
253 |
|
254 |
<!--Error status messages-->
|
@@ -265,34 +297,25 @@ if (!$backup_folder_exists) {
|
|
265 |
<!--Warning PlaceHolder-->
|
266 |
</ul>
|
267 |
|
268 |
-
</div>
|
269 |
-
|
270 |
-
<!--Debug Widget-->
|
271 |
-
<?php if (WP_DEBUG===true) :?>
|
272 |
-
<div class="widget">
|
273 |
-
<h3><i class="fa fa-wrench"></i> <?php _e('Debug', $namespace); ?></h3>
|
274 |
-
<div id="php"><p>Debugging is turned on in your wp-config.php file and should only be used when troubleshooting issues on your site.</p></div>
|
275 |
-
</div>
|
276 |
-
<?php endif; ?>
|
277 |
-
|
278 |
-
</div>
|
279 |
-
|
280 |
|
|
|
281 |
|
282 |
<div id="sidebar">
|
|
|
283 |
<!-- Display opt-in form if the user is unregistered -->
|
284 |
<?php if (!$license_active) : ?>
|
285 |
<?php if (!$is_lite_registered) : ?>
|
286 |
-
<form action="" method="post" id="<?php echo $namespace; ?>-form">
|
287 |
-
<?php wp_nonce_field($namespace . "-register-lite"); ?>
|
288 |
<div class="widget">
|
289 |
-
<h3 class="promo"><?php _e('Register WP BackItUp', $namespace); ?></h3>
|
290 |
-
<
|
|
|
|
|
291 |
<input type="text" name="first_name" id="first_name" placeholder="first name" value="<?php echo($lite_registration_first_name) ?>" /><br/>
|
292 |
<input type="text" name="email" id="email" placeholder="email address" value="<?php echo($lite_registration_email) ?>" />
|
293 |
<div class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e("Register", $namespace) ?>" /></div>
|
|
|
294 |
</div>
|
295 |
-
</form>
|
296 |
<?php else : ?>
|
297 |
<div class="widget">
|
298 |
<h3 class="promo"><?php _e('Get a license', $namespace); ?></h3>
|
@@ -302,12 +325,11 @@ if (!$backup_folder_exists) {
|
|
302 |
<?php endif ?>
|
303 |
<?php endif; ?>
|
304 |
|
305 |
-
|
306 |
-
<!-- Display license key widget -->
|
307 |
-
<form action="" method="post" id="<?php echo $namespace; ?>-form">
|
308 |
-
<?php wp_nonce_field($namespace . "-update-options"); ?>
|
309 |
<div class="widget">
|
310 |
<h3 class="promo"><?php _e('License v ' . $version, $namespace); ?></h3>
|
|
|
|
|
311 |
<?php
|
312 |
|
313 |
$fontColor='green';
|
@@ -324,13 +346,13 @@ if (!$backup_folder_exists) {
|
|
324 |
if (!empty($license_status)) {
|
325 |
$license_message=' License Status: ' . $license_status;
|
326 |
}
|
327 |
-
|
328 |
if($license_active)
|
329 |
echo '<p>' . $license_type_description .' License Key</p>';
|
330 |
else
|
331 |
echo '<p>Enter your license key to activate features.</p>';
|
332 |
-
?>
|
333 |
-
|
334 |
<input type="text" name="data[license_key]" id="license_key" value="<?php _e($license_key, $namespace); ?>" />
|
335 |
<div style="color:<?php _e($fontColor); ?>"><?php _e($license_message, $namespace); ?></div>
|
336 |
<div style="color:<?php _e($fontColor); ?>"><?php _e($license_status_message, $namespace); ?></div>
|
@@ -355,30 +377,65 @@ if (!$backup_folder_exists) {
|
|
355 |
<div>License expired? <?php echo($this->get_anchor_with_utm('Renew Now ','documentation/faqs/expired-license','license','license+expired'))?> and save 20%.</div>
|
356 |
<div>* Offer valid for a limited time!</div>
|
357 |
<?php endif; ?>
|
358 |
-
|
359 |
-
|
360 |
-
</div>
|
361 |
-
|
362 |
-
<!-- Display links widget -->
|
363 |
-
<div class="widget">
|
364 |
-
<h3 class="promo"><?php _e('Useful Links', $namespace); ?></h3>
|
365 |
-
<ul>
|
366 |
-
<?php if ($license_active) : ?>
|
367 |
-
<li><?php echo($this->get_anchor_with_utm('Your account','your-account','useful+links','your+account'))?></li>
|
368 |
-
<li><?php echo($this->get_anchor_with_utm('Upgrade your license','pricing-purchase','useful+links','upgrade+license'))?></li>
|
369 |
-
<?php endif; ?>
|
370 |
-
<li><?php echo($this->get_anchor_with_utm('Documentation','documentation','useful+links','help'))?></li>
|
371 |
|
372 |
-
|
373 |
-
|
374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
</div>
|
380 |
-
</form>
|
381 |
|
382 |
-
|
383 |
-
|
|
|
|
|
384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
$formatted_expired_date = date('F j, Y',strtotime($license_Expires));
|
26 |
|
27 |
// get retention number set
|
28 |
+
$number_retained_archives = $this->backup_retained_number();
|
29 |
|
30 |
$lite_registration_first_name = $this->lite_registration_first_name();
|
31 |
$lite_registration_email = $this->lite_registration_email();
|
49 |
}else{
|
50 |
$backup_folder_exists=true;
|
51 |
}
|
52 |
+
|
53 |
+
//Cleanup old backups - this can be removed in a few months.
|
54 |
+
//Get Zip File List
|
55 |
+
$file_list = glob($backup_folder_root . "/*.{zip,log}",GLOB_BRACE);
|
56 |
+
//If there are zip files then move them into their own folders
|
57 |
+
foreach($file_list as $file) {
|
58 |
+
|
59 |
+
//remove the suffix
|
60 |
+
$file_name = substr(basename($file),0,-4);
|
61 |
+
|
62 |
+
//strip off the suffix IF one exists
|
63 |
+
$folder_name = $file_name;
|
64 |
+
if ( ( $str_pos = strpos( $folder_name, '-main-' ) ) !== false ) {
|
65 |
+
$suffix = substr( $folder_name, $str_pos );
|
66 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
67 |
+
}
|
68 |
+
|
69 |
+
if ( ( $str_pos = strpos( $folder_name, '-others-' ) ) !== false ) {
|
70 |
+
$suffix = substr( $folder_name, $str_pos );
|
71 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( ( $str_pos = strpos( $folder_name, '-plugins-' ) ) !== false ) {
|
75 |
+
$suffix = substr( $folder_name, $str_pos );
|
76 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
77 |
+
}
|
78 |
+
|
79 |
+
if ( ( $str_pos = strpos( $folder_name, '-themes-' ) ) !== false ) {
|
80 |
+
$suffix = substr( $folder_name, $str_pos );
|
81 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
82 |
+
}
|
83 |
+
|
84 |
+
if ( ( $str_pos = strpos( $folder_name, '-uploads-' ) ) !== false ) {
|
85 |
+
$suffix = substr( $folder_name, $str_pos );
|
86 |
+
$folder_name = str_replace( $suffix, '', $folder_name );
|
87 |
+
}
|
88 |
+
|
89 |
+
//Does folder exist
|
90 |
+
$backup_archive_folder = $backup_dir . '/' . $folder_name;
|
91 |
+
if ( ! is_dir( $backup_archive_folder ) ) {
|
92 |
+
if (mkdir( $backup_archive_folder, 0755 )){
|
93 |
+
//print_r( "Folder Create.." );
|
94 |
+
}else{
|
95 |
+
//print_r( "Create Failed.." );
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
//make sure it exists before you move it
|
100 |
+
if ( is_dir( $backup_archive_folder ) ) {
|
101 |
+
//move the file to the archive folder
|
102 |
+
$target_file = $backup_archive_folder ."/" . basename($file);
|
103 |
+
if (rename ($file,$target_file)){
|
104 |
+
//print_r( "File Moved.." );
|
105 |
+
} else{
|
106 |
+
//print_r( "Move Failed.." );
|
107 |
+
}
|
108 |
+
|
109 |
+
} else {
|
110 |
+
//print_r( "NO FOLDER" );
|
111 |
+
}
|
112 |
+
|
113 |
+
}
|
114 |
+
|
115 |
+
$backup_list = $this->get_backup_list();
|
116 |
+
|
117 |
?>
|
118 |
|
119 |
<?php //Add Notification to UI
|
140 |
<script type="text/javascript">var __namespace = "<?php echo($namespace); ?>";</script>
|
141 |
<div class="wrap">
|
142 |
<h2><?php echo $page_title; ?></h2>
|
143 |
+
|
144 |
<div id="content">
|
145 |
|
146 |
+
<!--Manual Backups-->
|
147 |
<!--Manual Backups-->
|
148 |
<div class="widget">
|
149 |
<h3><i class="fa fa-cogs"></i> <?php _e('Backup', $namespace); ?></h3>
|
201 |
<!--View Log Form-->
|
202 |
<form id = "viewlog" name = "viewlog" action="admin-post.php" method="post">
|
203 |
<input type="hidden" name="action" value="viewlog">
|
204 |
+
<input type="hidden" id="backup_name" name="backup_name" value="">
|
205 |
<?php wp_nonce_field($this->namespace . "-viewlog"); ?>
|
206 |
</form>
|
207 |
|
208 |
<form id = "download_backup" name = "download_backup" action="admin-post.php" method="post">
|
209 |
<input type="hidden" name="action" value="download_backup">
|
210 |
+
<input type="hidden" id="backup_file" name="backup_file" value="">
|
211 |
<?php wp_nonce_field($this->namespace . "-download_backup"); ?>
|
212 |
</form>
|
213 |
|
214 |
<table class="widefat" id="datatable">
|
215 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
+
if ($backup_list!=false)
|
218 |
{
|
|
|
|
|
|
|
219 |
$i = 0;
|
220 |
+
foreach ($backup_list as $file)
|
221 |
{
|
222 |
+
|
223 |
+
$backup_name = $file["backup_name"];
|
224 |
+
$file_datetime = get_date_from_gmt(date('Y-m-d H:i:s', $file["date_time"]), 'Y-m-d g:i a');
|
225 |
+
$log_exists = $file["log_exists"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
$class = $i % 2 == 0 ? 'class="alternate"' : '';
|
228 |
?>
|
230 |
<tr <?php echo $class ?> id="row<?php echo $i; ?>">
|
231 |
<td><?php echo $file_datetime ?></td>
|
232 |
|
233 |
+
<!--Download Link-->
|
234 |
+
<td>
|
235 |
+
<a href="#TB_inline?width=600&height=550&inlineId=<?php echo preg_replace('/[^A-Za-z0-9\-]/', '', $backup_name) ?>" class="thickbox" title="<?php echo $backup_name ?>">Download</a>
|
236 |
+
</td>
|
|
|
|
|
|
|
237 |
|
238 |
+
<?php if (($log_exists)):?>
|
239 |
+
<td><a class='viewloglink' href="<?php echo $backup_name ?>">View Log</a></td>
|
240 |
<?php else: ?>
|
241 |
<td> </td>
|
242 |
<?php endif; ?>
|
243 |
|
244 |
+
<td><a href="#" title="<?php echo $backup_name; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
|
245 |
</tr>
|
246 |
|
247 |
<?php
|
250 |
}
|
251 |
else
|
252 |
{
|
253 |
+
echo '<tr id="nofiles"><td colspan="3">No backup archives found.</td></tr>';
|
254 |
}
|
255 |
?>
|
256 |
</table>
|
270 |
<li><?php _e('Nothing to report', $namespace); ?></li>
|
271 |
</ul>
|
272 |
|
|
|
273 |
<!--backup status messages-->
|
274 |
<ul class="backup-status">
|
275 |
<li class="preparing"><?php _e('Preparing for backup', $namespace); ?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
279 |
<li class='backup_plugins'><?php _e('Backing up plugins', $namespace); ?>...<span class='status-icon'><img class="backup_plugins-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
280 |
<li class='backup_uploads'><?php _e('Backing up uploads', $namespace); ?>...<span class='status-icon'><img class="backup_uploads-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
281 |
<li class='backup_other'><?php _e('Backing up everything else', $namespace); ?>...<span class='status-icon'><img class="backup_other-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
|
|
282 |
<li class='validate_backup'><?php _e('Validating backup', $namespace); ?>...<span class='status-icon'><img class="validate_backup-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
283 |
+
<li class='finalize_backup'><?php _e('Finalizing backup', $namespace); ?>...<span class='status-icon'><img class="finalize_backup-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
|
284 |
</ul>
|
285 |
|
286 |
<!--Error status messages-->
|
297 |
<!--Warning PlaceHolder-->
|
298 |
</ul>
|
299 |
|
300 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
|
302 |
+
</div> <!--content-->
|
303 |
|
304 |
<div id="sidebar">
|
305 |
+
|
306 |
<!-- Display opt-in form if the user is unregistered -->
|
307 |
<?php if (!$license_active) : ?>
|
308 |
<?php if (!$is_lite_registered) : ?>
|
|
|
|
|
309 |
<div class="widget">
|
310 |
+
<h3 class="promo"><?php _e('Register WP BackItUp Lite', $namespace); ?></h3>
|
311 |
+
<form action="" method="post" id="<?php echo $namespace; ?>-form">
|
312 |
+
<?php wp_nonce_field($namespace . "-register-lite"); ?>
|
313 |
+
<p><?php _e('Enter your email address to register WP BackItUp Lite. Registered users will receive <b>special offers</b> and access to our world class <b>support</b> team. <br /> <br />Premium customers only need to enter their license key in the section below. Registration is not required.', $namespace); ?></p>
|
314 |
<input type="text" name="first_name" id="first_name" placeholder="first name" value="<?php echo($lite_registration_first_name) ?>" /><br/>
|
315 |
<input type="text" name="email" id="email" placeholder="email address" value="<?php echo($lite_registration_email) ?>" />
|
316 |
<div class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e("Register", $namespace) ?>" /></div>
|
317 |
+
</form>
|
318 |
</div>
|
|
|
319 |
<?php else : ?>
|
320 |
<div class="widget">
|
321 |
<h3 class="promo"><?php _e('Get a license', $namespace); ?></h3>
|
325 |
<?php endif ?>
|
326 |
<?php endif; ?>
|
327 |
|
328 |
+
<!-- Display license key widget -->
|
|
|
|
|
|
|
329 |
<div class="widget">
|
330 |
<h3 class="promo"><?php _e('License v ' . $version, $namespace); ?></h3>
|
331 |
+
<form action="" method="post" id="<?php echo $namespace; ?>-form">
|
332 |
+
<?php wp_nonce_field($namespace . "-update-options"); ?>
|
333 |
<?php
|
334 |
|
335 |
$fontColor='green';
|
346 |
if (!empty($license_status)) {
|
347 |
$license_message=' License Status: ' . $license_status;
|
348 |
}
|
349 |
+
|
350 |
if($license_active)
|
351 |
echo '<p>' . $license_type_description .' License Key</p>';
|
352 |
else
|
353 |
echo '<p>Enter your license key to activate features.</p>';
|
354 |
+
?>
|
355 |
+
|
356 |
<input type="text" name="data[license_key]" id="license_key" value="<?php _e($license_key, $namespace); ?>" />
|
357 |
<div style="color:<?php _e($fontColor); ?>"><?php _e($license_message, $namespace); ?></div>
|
358 |
<div style="color:<?php _e($fontColor); ?>"><?php _e($license_status_message, $namespace); ?></div>
|
377 |
<div>License expired? <?php echo($this->get_anchor_with_utm('Renew Now ','documentation/faqs/expired-license','license','license+expired'))?> and save 20%.</div>
|
378 |
<div>* Offer valid for a limited time!</div>
|
379 |
<?php endif; ?>
|
380 |
+
</form>
|
381 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
|
383 |
+
<!-- Display links widget -->
|
384 |
+
<div class="widget">
|
385 |
+
<h3 class="promo"><?php _e('Useful Links', $namespace); ?></h3>
|
386 |
+
<ul>
|
387 |
+
<?php if ($license_active) : ?>
|
388 |
+
<li><?php echo($this->get_anchor_with_utm('Your account','your-account','useful+links','your+account'))?></li>
|
389 |
+
<li><?php echo($this->get_anchor_with_utm('Upgrade your license','pricing-purchase','useful+links','upgrade+license'))?></li>
|
390 |
+
<?php endif; ?>
|
391 |
+
<li><?php echo($this->get_anchor_with_utm('Documentation','documentation','useful+links','help'))?></li>
|
392 |
|
393 |
+
<?php if ($license_active || $is_lite_registered) : ?>
|
394 |
+
<li><?php echo($this->get_anchor_with_utm('Get support','support' ,'useful+links','get+support'))?></li>
|
395 |
+
<?php endif; ?>
|
|
|
|
|
396 |
|
397 |
+
<li><?php echo($this->get_anchor_with_utm('Feature request','feature-request' ,'useful+links','feature+request'))?></li>
|
398 |
+
<li>Have a suggestion? Why not submit a feature request.</li>
|
399 |
+
</ul>
|
400 |
+
</div>
|
401 |
|
402 |
+
</div><!--Sidebar-->
|
403 |
+
|
404 |
+
</div> <!--wrap-->
|
405 |
+
|
406 |
+
<!--File download lists-->
|
407 |
+
<span class="hidden">
|
408 |
+
<?php add_thickbox(); ?>
|
409 |
+
<!--File download lists-->
|
410 |
+
<?php if ($backup_list!=false) : ?>
|
411 |
+
<?php foreach ($backup_list as $folder) :
|
412 |
+
$backup_name = $folder["backup_name"];
|
413 |
+
$zip_files = $folder["zip_files"];
|
414 |
+
$count=0;
|
415 |
+
?>
|
416 |
+
<div id="<?php echo preg_replace('/[^A-Za-z0-9\-]/', '', $backup_name) ?>" style="display:none;">
|
417 |
+
<h2>WP BackItUp Backup Set</h2>
|
418 |
+
<p>Below are the archive files included in this backup set. Click the link to download.</p>
|
419 |
+
<table id="datatable" class="widefat">
|
420 |
+
<tbody>
|
421 |
+
<?php foreach ($zip_files as $file) :
|
422 |
+
++$count;
|
423 |
+
$class = $count % 2 == 0 ? '' : 'alternate';
|
424 |
+
$row_id="row".$count;
|
425 |
+
$zip_file = basename($file);
|
426 |
+
?>
|
427 |
+
<tr id="<?php echo $row_id ?>" class="<?php echo $class ?>">
|
428 |
+
<td><a href="<?php echo $zip_file ?>" class="downloadbackuplink"><?php echo $zip_file ?></a></td>
|
429 |
+
</tr>
|
430 |
+
<?php endforeach; ?>
|
431 |
+
</tbody>
|
432 |
+
</table>
|
433 |
+
<?php endforeach; ?>
|
434 |
+
</div>
|
435 |
+
<?php endif; ?>
|
436 |
+
<div id="new_backup" style="display:none;">
|
437 |
+
<h2>WP BackItUp Backup Set</h2>
|
438 |
+
<p>Please refresh this page to download your new backup files.</p>
|
439 |
+
</div>
|
440 |
+
</span>
|
441 |
+
<!--End File download lists-->
|
views/restore.php
CHANGED
@@ -30,6 +30,29 @@
|
|
30 |
$restore_folder_exists=true;
|
31 |
}
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
?>
|
34 |
|
35 |
<?php
|
@@ -59,29 +82,25 @@ if (!$restore_folder_exists) {
|
|
59 |
<h3><i class="fa fa-cloud-download"></i> <?php _e('Available Backups', $namespace); ?></h3>
|
60 |
<table class="widefat" id="datatable">
|
61 |
<?php
|
62 |
-
//Get Zip File List
|
63 |
-
$zipFileList = glob($backup_folder_root . "*.zip");
|
64 |
|
65 |
-
|
66 |
-
usort($zipFileList, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
|
67 |
-
|
68 |
-
if (glob($backup_folder_root . "*.zip"))
|
69 |
{
|
70 |
$i = 0;
|
71 |
-
foreach ($
|
72 |
{
|
73 |
-
$
|
74 |
-
$
|
|
|
75 |
$class = $i % 2 == 0 ? 'class="alternate"' : '';
|
76 |
?>
|
77 |
<tr <?php echo $class ?> id="row<?php echo $i; ?>">
|
78 |
-
<td><?php echo $
|
79 |
<td> </td>
|
80 |
-
<td><a href="#" title="<?php echo $
|
81 |
<?php
|
82 |
if ($this->license_active())
|
83 |
{
|
84 |
-
echo '<td><a href="#" title="' . $
|
85 |
}
|
86 |
?>
|
87 |
</tr>
|
@@ -91,7 +110,7 @@ if (!$restore_folder_exists) {
|
|
91 |
}
|
92 |
else
|
93 |
{
|
94 |
-
echo '<tr id="nofiles"><td colspan="3">No
|
95 |
}
|
96 |
?>
|
97 |
</table>
|
@@ -118,10 +137,11 @@ if (!$restore_folder_exists) {
|
|
118 |
{
|
119 |
?>
|
120 |
<div class="widget">
|
121 |
-
<h3
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
125 |
<?php
|
126 |
$max_upload = (int) (ini_get('upload_max_filesize'));
|
127 |
$max_post = (int) (ini_get('post_max_size'));
|
@@ -130,15 +150,40 @@ if (!$restore_folder_exists) {
|
|
130 |
$upload_bytes = $upload_mb * 1048576;
|
131 |
?>
|
132 |
<p>
|
133 |
-
|
134 |
-
<span style="color:green"><?php echo $upload_mb . 'MB.'; ?></span>
|
135 |
</p>
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
</div>
|
143 |
<?php } ?>
|
144 |
<!--End of Upload form-->
|
@@ -160,15 +205,17 @@ if (!$restore_folder_exists) {
|
|
160 |
<!--restore status messages-->
|
161 |
<ul class="restore-status">
|
162 |
<li class="preparing"><?php _e('Preparing for restore', $namespace); ?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
163 |
-
<li class="unzipping"><?php _e('Unzipping backup
|
164 |
<li class="validation"><?php _e('Validating backup file', $namespace); ?>...<span class='status-icon'><img class="validation-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
165 |
-
<li class="
|
166 |
-
<li class="
|
167 |
-
<li class="
|
168 |
-
<li class="
|
169 |
-
|
170 |
-
|
171 |
-
<li class="
|
|
|
|
|
172 |
</ul>
|
173 |
<p>
|
174 |
|
@@ -176,8 +223,8 @@ if (!$restore_folder_exists) {
|
|
176 |
<div class="restore-errors">
|
177 |
<span class="error201"><div class='isa_error'><?php _e('Error 201: No file selected', $namespace); ?>.</div></span>
|
178 |
<span class="error202"><div class='isa_error'><?php _e('Error 202: Your file could not be uploaded', $namespace); ?>.</div></span>
|
179 |
-
<span class="error203"><div class='isa_error'><?php _e('Error 203: Your backup
|
180 |
-
<span class="error204"><div class='isa_error'><?php _e('Error 204: Your backup
|
181 |
<span class="error205"><div class='isa_error'><?php _e('Error 205: Cannot create restore point', $namespace); ?>.</div></span>
|
182 |
<span class="error206"><div class='isa_error'><?php _e('Error 206: Unable to connect to your database', $namespace); ?>.</div></span>
|
183 |
<span class="error207"><div class='isa_error'><?php _e('Error 207: Unable to get current site URL from database. Please try again', $namespace); ?>.</div></span>
|
@@ -186,39 +233,51 @@ if (!$restore_folder_exists) {
|
|
186 |
<span class="error210"><div class='isa_error'><?php _e('Error 210: Unable to get current user password from database. Please try again', $namespace); ?>.</div></span>
|
187 |
<span class="error211"><div class='isa_error'><?php _e('Error 211: Unable to get current user email from database. Please try again', $namespace); ?>.</div></span>
|
188 |
<span class="error212"><div class='isa_error'><?php _e('Error 212: Unable to import your database. This may require importing the file manually', $namespace); ?>.</div></span>
|
189 |
-
<span class="
|
190 |
-
<span class="
|
191 |
-
<span class="
|
192 |
-
<span class="error216"><div class='isa_error'><?php _e('Error 216: Database not
|
193 |
-
<span class="
|
194 |
-
<span class="error218"><div class='isa_error'><?php _e('Error 218: Unable to create new wp-content directory
|
195 |
-
<span class="error219"><div class='
|
196 |
-
<span class="
|
197 |
-
<span class="error221"><div class='
|
198 |
<span class='error222'><div class='isa_error'><?php _e('Error 222: Unable to create restore folder', $namespace); ?>.</div></span>
|
199 |
-
<span class='error223'><div class='isa_error'><?php _e('Error 223: An error occurred during the restore.
|
200 |
<span class='error224'><div class='isa_error'><?php _e('Error 224: An error occurred during the restore, however, we have successfully restored your database to the previous state', $namespace); ?>.</div></span>
|
201 |
<span class='error225'><div class='isa_error'><?php _e('Error 225: Restore option is only available to licensed WP BackItUp users', $namespace); ?>.</div></span>
|
|
|
|
|
202 |
<span class="error230"><div class='isa_error'><?php _e('Error 230: WP BackItUp ran into unexpected errors during the database restore. However, we were able to successfully revert the database back to its original state . This error may require importing the database manually', $namespace); ?>.</div></span>
|
203 |
-
<span class="error235"><div class='isa_error'><?php _e('Error 235: WP BackItUp is not able to
|
204 |
-
<span class="error250"><div class='isa_error'><?php _e('Error 250: WP BackItUp is unable to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
</div>
|
207 |
|
208 |
<!--restore success messages-->
|
209 |
<div class="restore-success">
|
210 |
-
<span class='finalinfo'><div class='isa_success'><?php _e('Restore completed successfully.
|
211 |
</div>
|
212 |
|
213 |
</div>
|
214 |
|
215 |
-
<!--Debug Widget-->
|
216 |
-
<?php if (WP_DEBUG===true) :?>
|
217 |
-
<div class="widget">
|
218 |
-
<h3><i class="fa fa-wrench"></i> <?php _e('Debug', $namespace); ?></h3>
|
219 |
-
<div id="php"><p>Debugging is turned on in your wp-config.php file and should only be used when troubleshooting issues on your site.</p></div>
|
220 |
-
</div>
|
221 |
-
<?php endif; ?>
|
222 |
</div>
|
223 |
|
224 |
</div>
|
30 |
$restore_folder_exists=true;
|
31 |
}
|
32 |
|
33 |
+
$backup_list = $this->get_backup_list();
|
34 |
+
|
35 |
+
|
36 |
+
$chunk_size = min(wp_max_upload_size()-1024, 1024*1024*2);
|
37 |
+
$plupload_config = array(
|
38 |
+
'runtimes' => 'html5,flash,silverlight,html4',
|
39 |
+
'browse_button' => 'plupload-browse-button',
|
40 |
+
'container' => 'plupload-upload-ui',
|
41 |
+
'drop_element' => 'drag-drop-area',
|
42 |
+
'file_data_name' => 'async-upload',
|
43 |
+
'multiple_queues' => true,
|
44 |
+
'max_file_size' => '100Gb',
|
45 |
+
'chunk_size' => $chunk_size.'b',
|
46 |
+
'url' => admin_url('admin-ajax.php'),
|
47 |
+
'filters' => array(array('title' => __('Zip Files'), 'extensions' => 'zip')),
|
48 |
+
'multipart' => true,
|
49 |
+
'multi_selection' => true,
|
50 |
+
'urlstream_upload' => true,
|
51 |
+
'multipart_params' => array(
|
52 |
+
'_wpnonce' => wp_create_nonce($namespace . '-upload'),
|
53 |
+
'action' => 'wp-backitup_plupload_action')
|
54 |
+
);
|
55 |
+
|
56 |
?>
|
57 |
|
58 |
<?php
|
82 |
<h3><i class="fa fa-cloud-download"></i> <?php _e('Available Backups', $namespace); ?></h3>
|
83 |
<table class="widefat" id="datatable">
|
84 |
<?php
|
|
|
|
|
85 |
|
86 |
+
if ($backup_list!=false)
|
|
|
|
|
|
|
87 |
{
|
88 |
$i = 0;
|
89 |
+
foreach ($backup_list as $file)
|
90 |
{
|
91 |
+
$backup_name = $file["backup_name"];
|
92 |
+
$backup_datetime = get_date_from_gmt(date('Y-m-d H:i:s', $file["date_time"]), 'Y-m-d g:i a'); //Local Date Time
|
93 |
+
$log_exists = $file["log_exists"];
|
94 |
$class = $i % 2 == 0 ? 'class="alternate"' : '';
|
95 |
?>
|
96 |
<tr <?php echo $class ?> id="row<?php echo $i; ?>">
|
97 |
+
<td><?php echo $backup_name ?></td>
|
98 |
<td> </td>
|
99 |
+
<td><a href="#" title="<?php echo $backup_name; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
|
100 |
<?php
|
101 |
if ($this->license_active())
|
102 |
{
|
103 |
+
echo '<td><a href="#" title="' . $backup_name . '" class="restoreRow" id="restoreRow' . $i . '">Restore</a></td>';
|
104 |
}
|
105 |
?>
|
106 |
</tr>
|
110 |
}
|
111 |
else
|
112 |
{
|
113 |
+
echo '<tr id="nofiles"><td colspan="3">No backup archives found.</td></tr>';
|
114 |
}
|
115 |
?>
|
116 |
</table>
|
137 |
{
|
138 |
?>
|
139 |
<div class="widget">
|
140 |
+
<h3>
|
141 |
+
<i class="fa fa-upload"></i> <?php _e('Upload', $namespace); ?>
|
142 |
+
<i id="upload-backups-accordian" style="float:right" class="fa fa-angle-double-down"></i>
|
143 |
+
</h3>
|
144 |
+
<p><b><?php _e('Upload WP BackItUp archive(zip) files to add to your list of available backups.', $namespace); ?></b></p>
|
145 |
<?php
|
146 |
$max_upload = (int) (ini_get('upload_max_filesize'));
|
147 |
$max_post = (int) (ini_get('post_max_size'));
|
150 |
$upload_bytes = $upload_mb * 1048576;
|
151 |
?>
|
152 |
<p>
|
153 |
+
|
|
|
154 |
</p>
|
155 |
+
|
156 |
+
<script type="text/javascript">
|
157 |
+
var wpbackitup_plupload_config=<?php echo json_encode($plupload_config); ?>;
|
158 |
+
var site_url="<?php echo get_site_url(); ?>";
|
159 |
+
</script>
|
160 |
+
|
161 |
+
<div id="wpbackitup-plupload-modal" title="<?php _e('WP BackItUp - Upload backup files',$namespace); ?>" style="width: 75%; margin: 16px; display:none; margin-left: 100px;">
|
162 |
+
<p style="max-width: 610px;"><em><?php _e("Backup files may be uploaded into WP BackItUp with this form." ,$namespace);?> <?php echo htmlspecialchars(__('They may also be uploaded manually into the WP BackItUp directory (wp-content/wpbackitup_backups) using FTP. When done uploading all backup files refresh this page.',$namespace));?></em></p>
|
163 |
+
<?php
|
164 |
+
global $wp_version;
|
165 |
+
if (version_compare($wp_version, '3.3', '<')) {
|
166 |
+
echo '<em>'.sprintf(__('This feature requires %s version %s or later', $namespace), 'WordPress', '3.3').'</em>';
|
167 |
+
} else {
|
168 |
+
?>
|
169 |
+
<div id="plupload-upload-ui" class ="drag-drop" style="width: 100%;">
|
170 |
+
<div id="drag-drop-area">
|
171 |
+
<div class="drag-drop-inside">
|
172 |
+
<p class="drag-drop-info"><?php _e('Drop backup files here', $namespace); ?></p>
|
173 |
+
<p><?php _ex('or', 'Uploader: Drop backup files here - or - Select Files'); ?></p>
|
174 |
+
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p>
|
175 |
+
</div>
|
176 |
+
</div>
|
177 |
+
</div>
|
178 |
+
<p style="max-width: 100%;"><em><?php _e("* Reload this page when done uploading to see new backups appear in the Available Backups section above. " ,$namespace);?> </em></p>
|
179 |
+
|
180 |
+
<div id="filelist" class="media-item" style="width: 100%;"></div>
|
181 |
+
|
182 |
+
<?php } ?>
|
183 |
+
|
184 |
+
</div>
|
185 |
+
|
186 |
+
|
187 |
</div>
|
188 |
<?php } ?>
|
189 |
<!--End of Upload form-->
|
205 |
<!--restore status messages-->
|
206 |
<ul class="restore-status">
|
207 |
<li class="preparing"><?php _e('Preparing for restore', $namespace); ?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
208 |
+
<li class="unzipping"><?php _e('Unzipping backup set', $namespace); ?>...<span class='status-icon'><img class="unzipping-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
209 |
<li class="validation"><?php _e('Validating backup file', $namespace); ?>...<span class='status-icon'><img class="validation-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
210 |
+
<li class="deactivate_plugins"><?php _e('Deactivating plugins', $namespace); ?>...<span class='status-icon'><img class="deactivate_plugins-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
211 |
+
<li class="restore_point"><?php _e('Creating database restore point', $namespace); ?>...<span class='status-icon'><img class="restore_point-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
212 |
+
<li class="stage_wpcontent"><?php _e('Staging content files', $namespace); ?>...<span class='status-icon'><img class="stage_wpcontent-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
213 |
+
<li class="restore_wpcontent"><?php _e('Restoring content files', $namespace); ?>...<span class='status-icon'><img class="stage_wpcontent-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
214 |
+
<li class="restore_database"><?php _e('Restoring database', $namespace); ?>...<span class='status-icon'><img class="restore_database-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
215 |
+
<li class="update_user"><?php _e('Updating current user info', $namespace); ?>...<span class='status-icon'><img class="update_user-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
216 |
+
<li class="update_site_info"><?php _e('Updating site URL', $namespace); ?>...<span class='status-icon'><img class="update_site_info-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
217 |
+
<li class="activate_plugins"><?php _e('Activating plugins', $namespace); ?>...<span class='status-icon'><img class="activate_plugins-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
218 |
+
<li class="update_permalinks"><?php _e('Updating permalinks', $namespace); ?>...<span class='status-icon'><img class="update_permalinks-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
219 |
</ul>
|
220 |
<p>
|
221 |
|
223 |
<div class="restore-errors">
|
224 |
<span class="error201"><div class='isa_error'><?php _e('Error 201: No file selected', $namespace); ?>.</div></span>
|
225 |
<span class="error202"><div class='isa_error'><?php _e('Error 202: Your file could not be uploaded', $namespace); ?>.</div></span>
|
226 |
+
<span class="error203"><div class='isa_error'><?php _e('Error 203: Your backup could not be unzipped', $namespace); ?>.</div></span>
|
227 |
+
<span class="error204"><div class='isa_error'><?php _e('Error 204: Your backup appears to be invalid. Please ensure you selected a valid backup', $namespace); ?>.</div></span>
|
228 |
<span class="error205"><div class='isa_error'><?php _e('Error 205: Cannot create restore point', $namespace); ?>.</div></span>
|
229 |
<span class="error206"><div class='isa_error'><?php _e('Error 206: Unable to connect to your database', $namespace); ?>.</div></span>
|
230 |
<span class="error207"><div class='isa_error'><?php _e('Error 207: Unable to get current site URL from database. Please try again', $namespace); ?>.</div></span>
|
233 |
<span class="error210"><div class='isa_error'><?php _e('Error 210: Unable to get current user password from database. Please try again', $namespace); ?>.</div></span>
|
234 |
<span class="error211"><div class='isa_error'><?php _e('Error 211: Unable to get current user email from database. Please try again', $namespace); ?>.</div></span>
|
235 |
<span class="error212"><div class='isa_error'><?php _e('Error 212: Unable to import your database. This may require importing the file manually', $namespace); ?>.</div></span>
|
236 |
+
<span class="warning213"><div class='isa_warning'><?php _e('Warning 213: Unable to update your site URL value. Please check your Wordpress general settings to make sure your Site and Wordpress URLs are correct', $namespace); ?>.</div></span>
|
237 |
+
<span class="warning214"><div class='isa_warning'><?php _e('Warning 214: Unable to update your home URL value. Please check your Wordpress general settings to make sure your Site and Wordpress URLs are correct', $namespace); ?>.</div></span>
|
238 |
+
<span class="warning215"><div class='isa_warning'><?php _e('Warning 215: Unable to update your user information. This may require you to login with the admin username and password that was used when the backup was created', $namespace); ?>.</div></span>
|
239 |
+
<span class="error216"><div class='isa_error'><?php _e('Error 216: Database not found in backup', $namespace); ?>.</div></span>
|
240 |
+
<span class="warning217"><div class='isa_warning'><?php _e('Warning 217: Unable to remove existing wp-content directory', $namespace); ?>.</div></span>
|
241 |
+
<span class="error218"><div class='isa_error'><?php _e('Error 218: Unable to create new wp-content directory. Please check your CHMOD settings in /wp-content/', $namespace); ?>.</div></span>
|
242 |
+
<span class="error219"><div class='isa_error'><?php _e('Error 219: Unable to import wp-content. Please try again', $namespace); ?>.</div></span>
|
243 |
+
<span class="warning220"><div class='isa_warning'><?php _e('Warning 220: Unable to cleanup import directory. No action is required', $namespace); ?>.</div></span>
|
244 |
+
<span class="error221"><div class='isa_error'><?php _e('Error 221: Table prefix value in wp-config.php is different from backup. This MUST be changed in your wp-config.php file before you will be able to restore your site. See www.wpbackitup.com <a href ="http://www.wpbackitup.com/documentation/faqs/wordpress-table-prefix" target="_blank" > FAQs</a> for more info.', $namespace); ?>.</div></span>
|
245 |
<span class='error222'><div class='isa_error'><?php _e('Error 222: Unable to create restore folder', $namespace); ?>.</div></span>
|
246 |
+
<span class='error223'><div class='isa_error'><?php _e('Error 223: An error occurred during the restore. WP BackItUp attempted to restore the database to its previous state but were unsuccessful. Please contact WP BackItUp customer support and do not attempt to perform any further restores', $namespace); ?>.</div></span>
|
247 |
<span class='error224'><div class='isa_error'><?php _e('Error 224: An error occurred during the restore, however, we have successfully restored your database to the previous state', $namespace); ?>.</div></span>
|
248 |
<span class='error225'><div class='isa_error'><?php _e('Error 225: Restore option is only available to licensed WP BackItUp users', $namespace); ?>.</div></span>
|
249 |
+
<span class='error226'><div class='isa_error'><?php _e('Error 226: Restore cannot proceed because your backup was created using a different version of Wordpress', $namespace); ?>.</div></span>
|
250 |
+
<span class='error227'><div class='isa_error'><?php _e('Error 227: Restore cannot proceed because your backup was created using a different version of WP BackItUp. Please contact WP BackItUp support to help convert this backup to the current version', $namespace); ?>.</div></span>
|
251 |
<span class="error230"><div class='isa_error'><?php _e('Error 230: WP BackItUp ran into unexpected errors during the database restore. However, we were able to successfully revert the database back to its original state . This error may require importing the database manually', $namespace); ?>.</div></span>
|
252 |
+
<span class="error235"><div class='isa_error'><?php _e('Error 235: WP BackItUp is not able to proceed because there is no zip utility available. Please contact support', $namespace); ?>.</div></span>
|
253 |
+
<span class="error250"><div class='isa_error'><?php _e('Error 250: WP BackItUp is unable to begin the restore because a backup is running. Please wait for the backup to complete and then try again', $namespace); ?>.</div></span>
|
254 |
+
|
255 |
+
<span class="error251"><div class='isa_error'><?php _e('Error 251: WP BackItUp is unable to begin the restore because the backup manifest is empty', $namespace); ?>.</div></span>
|
256 |
+
<span class="error252"><div class='isa_error'><?php _e('Error 252: At least one zip file is missing from your backup set. Please make sure to upload all zip files that were part of this backup', $namespace); ?>.</div></span>
|
257 |
+
<span class="error253"><div class='isa_error'><?php _e('Error 253: Backup set contains a zip file that is not in the manifest. Please make sure to upload only zip files that were part of this backup', $namespace); ?>.</div></span>
|
258 |
+
|
259 |
+
<span class="warning300"><div class='isa_warning'><?php _e('Warning 300: Unable to restore all Wordpress content. Please review your restore logs to see what WP BackItUp was unable to restore', $namespace); ?>.</div></span>
|
260 |
+
<span class="warning305"><div class='isa_warning'><?php _e('Warning 305: Unable to restore all plugins. Please review your restore logs to see what WP BackItUp was unable to restore', $namespace); ?>.</div></span>
|
261 |
+
|
262 |
+
<span class="error2001"><div class='isa_error'><?php _e('Error 2001: Unable to prepare site for restore', $namespace); ?>.</div></span>
|
263 |
+
<span class="error2002"><div class='isa_error'><?php _e('Error 2002: Unable to unzip backup', $namespace); ?>.</div></span>
|
264 |
+
<span class="error2003"><div class='isa_error'><?php _e('Error 2003: Unable to validate backup', $namespace); ?>.</div></span>
|
265 |
+
<span class="error2004"><div class='isa_error'><?php _e('Error 2004: Unable to create restore point', $namespace); ?>.</div></span>
|
266 |
+
<span class="error2005"><div class='isa_error'><?php _e('Error 2005: Unable to stage wp-content', $namespace); ?>.</div></span>
|
267 |
+
<span class="error2006"><div class='isa_error'><?php _e('Error 2006: Unable to restore content files', $namespace); ?>.</div></span>
|
268 |
+
<span class="error2007"><div class='isa_error'><?php _e('Error 2007: Unable to restore database', $namespace); ?>.</div></span>
|
269 |
+
<span class="error2999"><div class='isa_error'><?php _e('Error 2999: Unexpected error encountered', $namespace); ?>.</div></span>
|
270 |
+
|
271 |
|
272 |
</div>
|
273 |
|
274 |
<!--restore success messages-->
|
275 |
<div class="restore-success">
|
276 |
+
<span class='finalinfo'><div class='isa_success'><?php _e('Restore completed successfully. If you are prompted to login please do so with your current username and password', $namespace); ?>.</div></span>
|
277 |
</div>
|
278 |
|
279 |
</div>
|
280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
</div>
|
282 |
|
283 |
</div>
|
views/support.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
$page_title = $this->friendly_name . ' Support';
|
4 |
+
$namespace = $this->namespace;
|
5 |
+
|
6 |
+
$license_active = $this->license_active();
|
7 |
+
$is_lite_registered = $this->is_lite_registered();
|
8 |
+
|
9 |
+
$support_email =$this->support_email();
|
10 |
+
|
11 |
+
$disabled='';
|
12 |
+
// if (!$license_active && !$is_lite_registered){
|
13 |
+
// $disabled='disabled';
|
14 |
+
// }
|
15 |
+
|
16 |
+
?>
|
17 |
+
<?php if (!empty($_GET["s"]) && '1' == $_GET["s"]) : ?>
|
18 |
+
<div class="updated">
|
19 |
+
<p><?php _e( 'Support email sent successfully!', $namespace ); ?></p>
|
20 |
+
</div>
|
21 |
+
<?php endif; ?>
|
22 |
+
|
23 |
+
<div class="wrap">
|
24 |
+
<h2><?php echo $page_title; ?></h2>
|
25 |
+
<div id="content">
|
26 |
+
|
27 |
+
|
28 |
+
<!-- Display Settings widget -->
|
29 |
+
<form action="admin-post.php" method="post" id="<?php echo $namespace; ?>-support-form">
|
30 |
+
<?php wp_nonce_field($namespace . "-support-form"); ?>
|
31 |
+
<div class="widget">
|
32 |
+
<h3 class="promo"><i class="fa fa-envelope"></i> Email Logs to Support</h3>
|
33 |
+
<p><b>Please use this form to send your log files to support. You may also use this form to open a support ticket.</b></p>
|
34 |
+
<p><?php _e('We will respond to this request via email using the email address you enter below.', $namespace); ?></p>
|
35 |
+
<p><input <?php echo($disabled) ; ?> type="text" name="support_email" value="<?php echo $support_email; ?>" size="30" placeholder="your email address">
|
36 |
+
<?php
|
37 |
+
if ( false !== ( $msg = get_transient('error-support-email') ) && $msg)
|
38 |
+
{
|
39 |
+
echo '<span class="error">'.$msg.'</span>';
|
40 |
+
delete_transient('error-support-email');
|
41 |
+
}
|
42 |
+
?>
|
43 |
+
</p>
|
44 |
+
|
45 |
+
<p><input <?php echo($disabled) ; ?> type="text" name="support_subject" value="<?php echo get_transient('support_subject'); ?>" size="30" placeholder="problem subject">
|
46 |
+
<?php
|
47 |
+
if ( false !== ( $msg = get_transient('error-support-subject') ) && $msg)
|
48 |
+
{
|
49 |
+
echo '<span class="error">'.$msg.'</span>';
|
50 |
+
delete_transient('error-support-subject');
|
51 |
+
}
|
52 |
+
?>
|
53 |
+
|
54 |
+
</p>
|
55 |
+
|
56 |
+
<p><textarea <?php echo($disabled) ; ?> name="support_body" rows="4" cols="50" style="width:450px;height:150px;" placeholder="problem description"><?php echo get_transient('support_body'); ?></textarea>
|
57 |
+
<?php
|
58 |
+
if ( false !== ( $msg = get_transient('error-support-body') ) && $msg)
|
59 |
+
{
|
60 |
+
echo '<span class="error">'.$msg.'</span>';
|
61 |
+
delete_transient('error-support-body');
|
62 |
+
}
|
63 |
+
?>
|
64 |
+
|
65 |
+
</p>
|
66 |
+
<input <?php echo($disabled) ; ?> type="checkbox" name="support_include_logs" id="support_include_logs" value="1" checked> <label for="support_include_logs">send logs</label><br>
|
67 |
+
|
68 |
+
<div class="submit"><input <?php echo($disabled) ; ?> type="submit" name="send_ticket" class="button-primary" value="<?php _e("Send", $namespace) ?>" />
|
69 |
+
<?php if (!$license_active) : ?>
|
70 |
+
* Premium customers receive priority support.
|
71 |
+
<?php endif; ?>
|
72 |
+
</div>
|
73 |
+
|
74 |
+
<?php
|
75 |
+
if ( false !== ( $msg = get_transient('settings-error-email') ) && $msg)
|
76 |
+
{
|
77 |
+
echo '<p class="error">'.$msg.'</p>';
|
78 |
+
delete_transient('settings-error-email');
|
79 |
+
}
|
80 |
+
?>
|
81 |
+
</div>
|
82 |
+
|
83 |
+
</form>
|
84 |
+
</div>
|
85 |
+
</div>
|
wp-backitup.php
CHANGED
@@ -12,7 +12,7 @@
|
|
12 |
Plugin Name: WP Backitup
|
13 |
Plugin URI: http://www.wpbackitup.com
|
14 |
Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
|
15 |
-
Version: 1.
|
16 |
Author: Chris Simmons
|
17 |
Author URI: http://www.wpbackitup.com
|
18 |
License: GPL3
|
@@ -34,7 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
34 |
*/
|
35 |
|
36 |
define( 'WPBACKITUP__NAMESPACE', 'wp-backitup' );
|
37 |
-
define( 'WPBACKITUP__VERSION', '1.
|
38 |
define( 'WPBACKITUP__DEBUG', false );
|
39 |
define( 'WPBACKITUP__MINIMUM_WP_VERSION', '3.0' );
|
40 |
define( 'WPBACKITUP__ITEM_NAME', 'WP Backitup' );
|
@@ -52,6 +52,8 @@ define( 'WPBACKITUP__PLUGIN_FOLDER',basename(dirname(__FILE__)));
|
|
52 |
define( 'WPBACKITUP__BACKUP_FOLDER', 'wpbackitup_backups' );
|
53 |
define( 'WPBACKITUP__BACKUP_URL', content_url() . "/" .WPBACKITUP__BACKUP_FOLDER);
|
54 |
define( 'WPBACKITUP__BACKUP_PATH',WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER);
|
|
|
|
|
55 |
|
56 |
define( 'WPBACKITUP__RESTORE_FOLDER', 'wpbackitup_restore' );
|
57 |
define( 'WPBACKITUP__RESTORE_PATH',WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER);
|
@@ -62,13 +64,18 @@ define( 'WPBACKITUP__THEMES_FOLDER',basename(get_theme_root()));
|
|
62 |
|
63 |
define( 'WPBACKITUP__SQL_DBBACKUP_FILENAME', 'db-backup.sql');
|
64 |
|
65 |
-
define( 'WPBACKITUP__BACKUP_IGNORE_LIST', WPBACKITUP__BACKUP_FOLDER .',' .WPBACKITUP__RESTORE_FOLDER .',updraft
|
66 |
define( 'WPBACKITUP__TASK_TIMEOUT_SECONDS', 300);//300 = 5 minutes
|
67 |
define( 'WPBACKITUP__SCRIPT_TIMEOUT_SECONDS', 900);//900 = 15 minutes
|
68 |
|
69 |
define( 'WPBACKITUP__BACKUP_RETAINED_DAYS', 5);//5 days
|
|
|
70 |
|
71 |
-
define( '
|
|
|
|
|
|
|
|
|
72 |
|
73 |
register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
|
74 |
register_deactivation_hook( __FILE__, array( 'WPBackitup_Admin', 'deactivate' ) );
|
12 |
Plugin Name: WP Backitup
|
13 |
Plugin URI: http://www.wpbackitup.com
|
14 |
Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
|
15 |
+
Version: 1.10.0
|
16 |
Author: Chris Simmons
|
17 |
Author URI: http://www.wpbackitup.com
|
18 |
License: GPL3
|
34 |
*/
|
35 |
|
36 |
define( 'WPBACKITUP__NAMESPACE', 'wp-backitup' );
|
37 |
+
define( 'WPBACKITUP__VERSION', '1.10.0');
|
38 |
define( 'WPBACKITUP__DEBUG', false );
|
39 |
define( 'WPBACKITUP__MINIMUM_WP_VERSION', '3.0' );
|
40 |
define( 'WPBACKITUP__ITEM_NAME', 'WP Backitup' );
|
52 |
define( 'WPBACKITUP__BACKUP_FOLDER', 'wpbackitup_backups' );
|
53 |
define( 'WPBACKITUP__BACKUP_URL', content_url() . "/" .WPBACKITUP__BACKUP_FOLDER);
|
54 |
define( 'WPBACKITUP__BACKUP_PATH',WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER);
|
55 |
+
define( 'WPBACKITUP__UPLOAD_FOLDER','TMP_Uploads');
|
56 |
+
define( 'WPBACKITUP__UPLOAD_PATH',WPBACKITUP__BACKUP_PATH . '/' .WPBACKITUP__UPLOAD_FOLDER);
|
57 |
|
58 |
define( 'WPBACKITUP__RESTORE_FOLDER', 'wpbackitup_restore' );
|
59 |
define( 'WPBACKITUP__RESTORE_PATH',WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER);
|
64 |
|
65 |
define( 'WPBACKITUP__SQL_DBBACKUP_FILENAME', 'db-backup.sql');
|
66 |
|
67 |
+
define( 'WPBACKITUP__BACKUP_IGNORE_LIST', WPBACKITUP__BACKUP_FOLDER .',' .WPBACKITUP__RESTORE_FOLDER .',updraft*,wp-clone*,backwpup*,backupwordpress*,cache,backupcreator*,backupbuddy*');
|
68 |
define( 'WPBACKITUP__TASK_TIMEOUT_SECONDS', 300);//300 = 5 minutes
|
69 |
define( 'WPBACKITUP__SCRIPT_TIMEOUT_SECONDS', 900);//900 = 15 minutes
|
70 |
|
71 |
define( 'WPBACKITUP__BACKUP_RETAINED_DAYS', 5);//5 days
|
72 |
+
define( 'WPBACKITUP__SUPPORT_EMAIL', 'support@wpbackitup.com');
|
73 |
|
74 |
+
define( 'WPBACKITUP__ZIP_MAX_FILE_SIZE', 524288000); //524288000; # 500Mb
|
75 |
+
define( 'WPBACKITUP__THEMES_BATCH_SIZE', 5000); //~100kb each = 5000*100 = 500000 kb = 500 mb
|
76 |
+
define( 'WPBACKITUP__PLUGINS_BATCH_SIZE', 5000); //~100kb each = 5000*100 = 500000 kb = 500 mb
|
77 |
+
define( 'WPBACKITUP__OTHERS_BATCH_SIZE', 500); //~100kb each = 5000*100 = 500000 kb = 500 mb
|
78 |
+
define( 'WPBACKITUP__UPLOADS_BATCH_SIZE', 500); //anyones guess here
|
79 |
|
80 |
register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
|
81 |
register_deactivation_hook( __FILE__, array( 'WPBackitup_Admin', 'deactivate' ) );
|