Backup and Restore WordPress – WPBackItUp Backup Plugin - Version 1.9.1

Version Description

  • New Features: Long running backups are now supported.
  • Update: Extensive Performance improvements
  • Update: User experience improvements to backup.
  • Update: Extensive updates to error handling and messaging
  • Update: Enhancements to backup email notification.
  • Update: Logging enhancements.
  • Update: Automated cleanup uses file retention limits for all logs.
  • Update: Security enhancements to prevent unwanted access to backup, restore and log folders.
  • Fix: IFrame css definition changed to use wp-backitup namespace.
Download this release

Release Info

Developer cssimmon
Plugin Icon 128x128 Backup and Restore WordPress – WPBackItUp Backup Plugin
Version 1.9.1
Comparing to
See all releases

Code changes from version 1.9 to 1.9.1

css/index.html ADDED
File without changes
css/wpbackitup_admin.css CHANGED
@@ -9,6 +9,7 @@
9
 
10
  .error { color: #ff0000;}
11
  .warning { color: #FEEFB3;}
 
12
 
13
  .isa_info, .isa_success, .isa_warning, .isa_error {
14
  border: 1px solid;
@@ -51,7 +52,7 @@ h3 {
51
  border-bottom: 1px solid #eee;
52
  }
53
 
54
- iframe {
55
  height: 0;
56
  margin: 0;
57
  padding: 0;
@@ -89,7 +90,10 @@ iframe {
89
 
90
  .backup-errors,
91
  .backup-errors div,
92
- .backup-unexpected-error,
 
 
 
93
 
94
  .backup-success,
95
  .backup-success div,
9
 
10
  .error { color: #ff0000;}
11
  .warning { color: #FEEFB3;}
12
+ .wpbackitup-warning { color: #FF8000;}
13
 
14
  .isa_info, .isa_success, .isa_warning, .isa_error {
15
  border: 1px solid;
52
  border-bottom: 1px solid #eee;
53
  }
54
 
55
+ .wp-backitup-iframe {
56
  height: 0;
57
  margin: 0;
58
  padding: 0;
90
 
91
  .backup-errors,
92
  .backup-errors div,
93
+ .backup-error,
94
+
95
+ .backup-warning,
96
+ .backup-warning div,
97
 
98
  .backup-success,
99
  .backup-success div,
images/index.html ADDED
File without changes
index.html ADDED
File without changes
js/index.html ADDED
File without changes
js/wpbackitup_admin.js CHANGED
@@ -9,8 +9,21 @@
9
  var namespace = 'wp-backitup';
10
 
11
  //Add View Log Click event to backup page
12
- add_viewlog_onclick();
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  $( "#scheduled-backups-accordian" ).click(function() {
16
 
@@ -51,17 +64,9 @@
51
  }
52
  });
53
 
54
- /* define logreader variables */
55
- var response_reader = {
56
- action: get_action_name('response_reader')
57
- };
58
 
59
- /* define logreader variables */
60
- var status_reader = {
61
- action: get_action_name('status_reader')
62
- };
63
 
64
- function add_viewlog_onclick(){
65
  $(".viewloglink").click(function(){
66
  var href = $(this).attr("href");
67
  $("#viewlog_log").val(href);
@@ -69,9 +74,10 @@
69
  return false;
70
  });
71
  }
72
- /* define display status function */
73
- function display_status() {
74
- $.post(ajaxurl, status_reader, function(response) {
 
75
  /* Get response from log reader */
76
  var xmlObj = $(response);
77
 
@@ -122,7 +128,7 @@
122
 
123
  //Warning
124
  if ( $(this).html() == -2 ) {
125
-
126
  $(attributename).find(".isa_warning").fadeIn(1500);
127
 
128
  }
@@ -141,53 +147,184 @@
141
  });
142
  }
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  /* define backup response_reader function */
145
- function get_backup_response() {
146
  //This function is required because of 504 gateway timeouts
147
 
148
  var jqxhr = $.ajax({
149
  url: ajaxurl,
150
  type: 'POST',
151
- data: {action: get_action_name('response_reader')},
152
  dataType: "json"
153
  });
154
 
155
  jqxhr.always(function(jsonData, textStatus, errorThrown) {
156
- console.log("Backup Response:" + JSON.stringify(errorThrown));
157
- console.log("Backup Response text status:" + textStatus);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
- if (jsonData) {
160
- if (jsonData.message=='success') {
161
- console.log("JSON response received.");
162
- processRow_backup(jsonData);
163
- $('.backup-success').show();
164
 
165
- } else { //Error
166
- console.log("JSON error response received.");
 
167
 
168
- var msg="process unavailable";
169
- if (jsonData.message !== undefined){
170
- msg= jsonData.message;
171
- }
172
- status_message='An unexpected error has occurred during process:  ' + msg;
173
 
174
- var unexpected_error= $('.backup-unexpected-error');
175
- unexpected_error.html(status_message);
176
- unexpected_error.addClass("isa_error");
177
- unexpected_error.show();
178
 
179
- //fade out all of the spinners
180
- $('.status-icon').fadeOut(200);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  }
183
 
184
  } else { //Didnt get any json back
185
  console.log("NON JSON response received.");
186
- status_message='An unexpected error has occurred during process:  ' + textStatus + ':' + JSON.stringify(errorThrown);
 
 
 
 
187
 
188
  $('.backup-status').hide();
189
 
190
- var unexpected_error= $('.backup-unexpected-error');
191
  unexpected_error.html(status_message);
192
  unexpected_error.addClass("isa_error");
193
  unexpected_error.show();
@@ -199,13 +336,15 @@
199
 
200
  //Save Schedule CLICK
201
  $("#wp-backitup-notification-close").click(function() {
202
- dismiss_message();
203
  });
 
 
204
  //Save Schedule CLICK
205
  $("#wp-backitup-save_schedule_form").submit(function() {
206
 
207
  var formData = new FormData();
208
- formData.append('action', get_action_name('update-schedule'));
209
  formData.append('_wpnonce', $('#wp-backitup_nonce-update-schedule').val());
210
  formData.append('_wp_http_referer',$("[name='_wp_http_referer']").val());
211
 
@@ -233,10 +372,10 @@
233
  switch (response)
234
  {
235
  case 'success':
236
- show_success_message("Scheduled has been saved.");
237
  break;
238
  case 'error':
239
- show_error_message("Scheduled was not saved.");
240
  break;
241
  default:
242
 
@@ -255,7 +394,7 @@
255
 
256
  });
257
 
258
- /*BACKUP button click */
259
  $(".backup-button").click(function(e) {
260
  e.preventDefault();
261
 
@@ -264,89 +403,102 @@
264
  var jqxhr = $.ajax({
265
  url: ajaxurl,
266
  type: 'POST',
267
- data: {action: get_action_name('backup')},
268
  cache: false,
269
  dataType: "json",
270
 
271
  beforeSend: function(jqXHR, settings) {
272
  console.log("BeforeSend:Nothing to report.");
273
-
274
- /* display processing icon */
275
- $('.backup-icon').css('visibility', 'visible');
276
- $('.backup-icon').show();
277
-
278
- /* hide default message, restore status and restore errors */
279
- $('.backup-success').hide();
280
- $('.default-status').hide();
281
- $('.backup-unexpected-error').hide();
282
-
283
- /* hide the status just incase this is the second run */
284
- $("ul.backup-status").children().children().hide();
285
- $(".backup-errors").children().children().hide();
286
- $(".backup-success").children().children().hide();
287
-
288
- /* show backup status, backup errors */
289
- $('.backup-status').show();
290
- window.intervalDefine = setInterval(display_status, 3000);
291
  }
292
  });
293
 
294
  //Fetch the JSON response file if it exists
295
  jqxhr.always(function(data, textStatus, errorThrown) {
296
  console.log("Backup Button Click - Always");
297
- clearInterval(window.intervalDefine);
298
- display_status(); //Fetch status one last time manually
299
- get_backup_response(); //fetch the response too
300
- $('.backup-icon').fadeOut(1000);
301
- $("#backup-button").removeAttr("disabled"); //enable button
302
  });
303
-
304
  });
305
 
306
- /* RESTORE button click */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  $('#datatable').on('click', 'a.restoreRow', function(e) {
308
  e.preventDefault();
309
 
310
  if (confirm('Are you sure you want to restore your site?'))
311
  {
312
-
313
  var filename = this.title;
314
  var row = this.id.replace('restoreRow', 'row');
315
  userid = $('input[name=user_id]').val();
316
 
317
- $.ajax({
318
  url: ajaxurl,
319
  type: 'post',
320
- data: {action: get_action_name('restore'), selected_file: filename,user_id: userid},
321
- success: function(response) {
322
- /* Return PHP messages, used for development */
323
- $("#php").html(response);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
 
325
- //clearInterval(window.intervalDefine);
326
- var data = $.parseJSON(response);
327
 
328
- },
329
- beforeSend: function () {
330
- /* display processing icon */
331
- $('.restore-icon').css('visibility', 'visible');
332
 
333
- /* hide default message, backup status and backup errors */
334
- $('.default-status, .upload-status').hide();
335
 
336
- $("ul.restore-status").children().children().hide();
337
- $(".restore-errors").children().children().hide();
338
- $(".restore-success").children().children().hide();
339
 
340
- /* show restore status messages */
341
- $('.restore-status, .restore-errors, .restore-success').show();
342
- $('.preparing-icon').css('visibility', 'visible');
343
- $('.preparing').find(".status-icon").fadeIn(1500);
344
 
345
- window.intervalDefine = setInterval(display_status, 3000);
346
- }
347
- });
348
- }
349
- });
350
 
351
  /*Upload form button*/
352
  $("#upload-form").submit(function() {
@@ -354,7 +506,7 @@
354
  //e.preventDefault();
355
 
356
  //CHECK ERRORS ON USER SIDE, IF TRUE, END OPERATIONS.
357
- if (upload_errors()){
358
  return false;
359
  }
360
 
@@ -362,7 +514,7 @@
362
  jQuery.each($('#wpbackitup-zip')[0].files, function(i, file) {
363
  formData.append('uploadFile-'+i, file);
364
  });
365
- formData.append('action', get_action_name('upload'));
366
  formData.append('_wpnonce', $('#_wpnonce').val());
367
  formData.append('_wp_http_referer',$("[name='_wp_http_referer']").val());
368
 
@@ -421,7 +573,7 @@
421
  if (data.msg == 'success')
422
  {
423
  status_message=data.file + ' file was uploaded successfully...';
424
- processRow_restore(data);
425
  $('.upload-status').addClass("isa_success");
426
  }else{
427
  status_message='Error:  ' + data.error;
@@ -456,7 +608,7 @@
456
  $.ajax({
457
  url: ajaxurl,
458
  type: 'post',
459
- data: {action: get_action_name('delete_file'), filed: filename},
460
  success: function(data) {
461
  if (data === 'deleted')
462
  {
@@ -476,7 +628,7 @@
476
  });
477
 
478
 
479
- function processRow_backup(data)
480
  {
481
  // decide class of row to be inserted dynamically
482
  var css_class;
@@ -491,22 +643,21 @@
491
  cur_row++;
492
 
493
  // built id of the row to be inserted dynamically
494
- if (data != undefined)
495
  {
496
- var restoreColumn = '<td><a href="#" title="' + data.file + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n';
497
 
498
  var viewColumn = '<td>&nbsp;</td>\n';
499
- if (typeof data.log_link !== 'undefined') {
500
- viewColumn = '<td><a class="viewloglink" href="' + data.log_link + '">View Log</a></td>\n';
501
  }
502
 
503
  var newRow =
504
  '<tr ' + css_class + ' id="row' + cur_row + '">\n\
505
  <td>New Backup!</td>\n\
506
- <td><i class="fa fa-long-arrow-right"></i>' + data.file +'</td>\n\
507
- <td><a href="' + data.zip_link + '">Download</a></td>\n';
508
  newRow +=viewColumn;
509
- newRow +='<td><a href="#" title="' + data.file + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n';
510
  newRow +='</tr>';
511
 
512
  if ($('#nofiles'))
@@ -516,15 +667,15 @@
516
  $('#datatable').prepend(newRow);
517
  $('#datatable tr:first').hide().show('slow'); // just an animation to show newly added row
518
 
519
- if(total_rows >= data.retained)
520
  $('#datatable tr:last').hide();
521
 
522
- add_viewlog_onclick();
523
 
524
  }
525
  }
526
 
527
- function processRow_restore(data)
528
  {
529
  // decide class of row to be inserted dynamically
530
  var css_class;
@@ -562,7 +713,7 @@
562
  }
563
  }
564
 
565
- function upload_errors()
566
  {
567
  if ($('#wpbackitup-zip').val() == '')
568
  {
@@ -581,16 +732,16 @@
581
  return false;
582
  }
583
 
584
- function get_action_name(action) {
585
  return namespace + '_' + action;
586
  }
587
 
588
- function dismiss_message(){
589
  notification_bar = $( "#wp-backitup-notification-parent");
590
  notification_bar.fadeOut( "slow" )
591
  }
592
 
593
- function show_success_message(message){
594
  notification_bar_message = $( "#wp-backitup-notification-message");
595
  notification_bar_message.html("<p>" + message + "</p>");
596
 
@@ -602,7 +753,7 @@
602
  $('html, body').animate({ scrollTop: 0 }, 'slow');
603
  }
604
 
605
- function show_error_message(message){
606
  notification_bar_message = $( "#wp-backitup-notification-message");
607
  notification_bar_message.html("<p>" + message + "</p>");
608
 
@@ -614,4 +765,10 @@
614
  $('html, body').animate({ scrollTop: 0 }, 'slow');
615
  }
616
 
 
 
 
 
 
 
617
  })(jQuery);
9
  var namespace = 'wp-backitup';
10
 
11
  //Add View Log Click event to backup page
12
+ wpbackitup_add_viewlog_onclick();
13
 
14
+ ///* define logreader variables */
15
+ //var wpbackitup_backup_response_reader = {
16
+ // action: wpbackitup_get_action_name('backup_response_reader')
17
+ //};
18
+
19
+ /* define logreader variables */
20
+ var wpbackitup_restore_status_reader = {
21
+ action: wpbackitup_get_action_name('restore_status_reader')
22
+ };
23
+
24
+ var wpbackitup_backup_status_reader = {
25
+ action: wpbackitup_get_action_name('backup_status_reader')
26
+ };
27
 
28
  $( "#scheduled-backups-accordian" ).click(function() {
29
 
64
  }
65
  });
66
 
 
 
 
 
67
 
 
 
 
 
68
 
69
+ function wpbackitup_add_viewlog_onclick(){
70
  $(".viewloglink").click(function(){
71
  var href = $(this).attr("href");
72
  $("#viewlog_log").val(href);
74
  return false;
75
  });
76
  }
77
+
78
+ /* get restore status */
79
+ function wpbackitup_get_restore_status() {
80
+ $.post(ajaxurl, wpbackitup_restore_status_reader, function(response) {
81
  /* Get response from log reader */
82
  var xmlObj = $(response);
83
 
128
 
129
  //Warning
130
  if ( $(this).html() == -2 ) {
131
+
132
  $(attributename).find(".isa_warning").fadeIn(1500);
133
 
134
  }
147
  });
148
  }
149
 
150
+ /* get backup status */
151
+ function wpbackitup_get_backup_status() {
152
+ $.post(ajaxurl, wpbackitup_backup_status_reader, function(response) {
153
+ /* Get response from log reader */
154
+ var xmlObj = $(response);
155
+
156
+ /* For each response */
157
+ xmlObj.each(function() {
158
+
159
+ /* Select correct status */
160
+ var attributename = "." + $(this).attr('class');
161
+ var icon_attributename = "." + $(this).attr('class') + '-icon';
162
+
163
+ //Hide all
164
+ if ( $(this).html() == 0 ) {
165
+
166
+ $(attributename).find(".status").hide();
167
+ $(attributename).find(".status-icon").hide();
168
+
169
+ }
170
+
171
+ //Processing
172
+ if ( $(this).html() == 1 ) {
173
+
174
+ $(icon_attributename).css('visibility', 'visible');
175
+ $(attributename).find(".status").fadeOut(200);
176
+ $(attributename).find(".status-icon").fadeIn(1500);
177
+
178
+ }
179
+
180
+ //Done
181
+ if ( $(this).html() == 2 ) {
182
+
183
+ $(attributename).find(".status-icon").fadeOut(200);
184
+ $(attributename).find(".status").fadeIn(1500);
185
+
186
+ }
187
+
188
+ //Fatal Error
189
+ if ( $(this).html() == -1 ) {
190
+
191
+ $(attributename).find(".status-icon").fadeOut(200);
192
+ $(attributename).find(".fail").fadeIn(1500);
193
+
194
+
195
+ /* Stop status reader */
196
+ clearInterval(window.intervalDefine);
197
+
198
+ //Show error status
199
+ wpbackitup_get_backup_response();
200
+ }
201
+
202
+ //Warning
203
+ if ( $(this).html() == -2 ) {
204
+
205
+ $(attributename).find(".status-icon").fadeOut(200);
206
+ $(attributename).find(".wpbackitup-warning").fadeIn(1500);
207
+
208
+ }
209
+
210
+ //success
211
+ if ( $(this).html() == 99 ) {
212
+
213
+ /* If status returns 1, display 'Done' or show detailed message */
214
+ $(attributename).find(".status-icon").fadeOut(200);
215
+ $(attributename).find(".status").fadeIn(1500);
216
+
217
+ /* Stop statusreader */
218
+ clearInterval(window.intervalDefine);
219
+
220
+ //Show error status
221
+ wpbackitup_get_backup_response();
222
+
223
+ }
224
+
225
+ });
226
+ });
227
+ }
228
+
229
  /* define backup response_reader function */
230
+ function wpbackitup_get_backup_response() {
231
  //This function is required because of 504 gateway timeouts
232
 
233
  var jqxhr = $.ajax({
234
  url: ajaxurl,
235
  type: 'POST',
236
+ data: {action: wpbackitup_get_action_name('backup_response_reader')},
237
  dataType: "json"
238
  });
239
 
240
  jqxhr.always(function(jsonData, textStatus, errorThrown) {
241
+ console.log("Backup Response:" + JSON.stringify(jsonData));
242
+
243
+ if (typeof jsonData.backupStatus !== 'undefined' && typeof jsonData.backupMessage !== 'undefined')
244
+ {
245
+ console.log("JSON Backup Status:" + jsonData.backupStatus);
246
+ console.log("JSON Backup Message:" + jsonData.backupMessage);
247
+
248
+ switch (jsonData.backupStatus) {
249
+ case 'success':
250
+ console.log("JSON success response received.");
251
+ //fade out all of the spinners
252
+ $('.status-icon').fadeOut(200);
253
+ $("#backup-button").removeAttr("disabled"); //enable button
254
+
255
+ $('.isa_success').show;
256
+ $('.backup-success').fadeIn(1500);
257
+
258
+ wpbackitup_processRow_backup(jsonData);
259
+
260
+ //Are there any warnings?
261
+ if (typeof jsonData.backupWarnings !== 'undefined'){
262
+ var warning = $('.backup-warning');
263
+
264
+ var $warningMessages = jsonData.backupWarnings;
265
+ $warningMessages.forEach(function(obj) {
266
+ var warningMessage = obj.warningMessage;
267
+ warning.append('<li class="isa_warning">Warning: '+ warningMessage + '</li>');
268
+ });
269
+
270
+ warning.fadeIn(1500);
271
+ }
272
+
273
+ break;
274
+
275
+ case 'error':
276
+ console.log("JSON error response received.");
277
+
278
+ var msg="(JS997) Unexpected error";
279
+ if (typeof jsonData.backupMessage !== 'undefined'){
280
+ msg= jsonData.backupMessage;
281
+ }
282
+ var status_message='Error: &nbsp;' + msg;
283
 
284
+ var backup_error= $('.backup-error');
285
+ backup_error.html(status_message);
286
+ backup_error.addClass("isa_error");
287
+ backup_error.fadeIn(1500);
 
288
 
289
+ //fade out all of the spinners
290
+ $('.status-icon').fadeOut(200);
291
+ $("#backup-button").removeAttr("disabled"); //enable button
292
 
293
+ break;
 
 
 
 
294
 
295
+ default:
296
+ console.log("Unexpected JSON response status received.");
 
 
297
 
298
+ var msg="(JS998) Unexpected error";
299
+ if (typeof jsonData.backupMessage !== 'undefined'){
300
+ msg= jsonData.backupMessage;
301
+ }
302
+ var status_message='Error(JS998) : &nbsp;' + msg;
303
+
304
+ var unexpected_error= $('.backup-error');
305
+ unexpected_error.html(status_message);
306
+ unexpected_error.addClass("isa_error");
307
+ unexpected_error.fadeIn(1500);
308
+
309
+ //fade out all of the spinners
310
+ $('.status-icon').fadeOut(200);
311
+ $("#backup-button").removeAttr("disabled"); //enable button
312
+
313
+ break;
314
 
315
  }
316
 
317
  } else { //Didnt get any json back
318
  console.log("NON JSON response received.");
319
+ console.log("Backup Response:" + errorThrown);
320
+ status_message='(JS999) An unexpected error has occurred: &nbsp;';
321
+ status_message+='</br>Response: &nbsp;' + JSON.stringify(jsonData);
322
+ status_message+='</br>Status: &nbsp;' + textStatus;
323
+ status_message+='</br>Error: &nbsp;' + JSON.stringify(errorThrown);
324
 
325
  $('.backup-status').hide();
326
 
327
+ var unexpected_error= $('.backup-error');
328
  unexpected_error.html(status_message);
329
  unexpected_error.addClass("isa_error");
330
  unexpected_error.show();
336
 
337
  //Save Schedule CLICK
338
  $("#wp-backitup-notification-close").click(function() {
339
+ wpbackitup_dismiss_message();
340
  });
341
+
342
+
343
  //Save Schedule CLICK
344
  $("#wp-backitup-save_schedule_form").submit(function() {
345
 
346
  var formData = new FormData();
347
+ formData.append('action', wpbackitup_get_action_name('update-schedule'));
348
  formData.append('_wpnonce', $('#wp-backitup_nonce-update-schedule').val());
349
  formData.append('_wp_http_referer',$("[name='_wp_http_referer']").val());
350
 
372
  switch (response)
373
  {
374
  case 'success':
375
+ wpbackitup_show_success_message("Scheduled has been saved.");
376
  break;
377
  case 'error':
378
+ wpbackitup_show_error_message("Scheduled was not saved.");
379
  break;
380
  default:
381
 
394
 
395
  });
396
 
397
+ // BACKUP button click
398
  $(".backup-button").click(function(e) {
399
  e.preventDefault();
400
 
403
  var jqxhr = $.ajax({
404
  url: ajaxurl,
405
  type: 'POST',
406
+ data: {action: wpbackitup_get_action_name('backup')},
407
  cache: false,
408
  dataType: "json",
409
 
410
  beforeSend: function(jqXHR, settings) {
411
  console.log("BeforeSend:Nothing to report.");
412
+ wpbackitup_show_backup();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  }
414
  });
415
 
416
  //Fetch the JSON response file if it exists
417
  jqxhr.always(function(data, textStatus, errorThrown) {
418
  console.log("Backup Button Click - Always");
419
+ console.log(data.message);//backup queued?
 
 
 
 
420
  });
 
421
  });
422
 
423
+ function wpbackitup_show_backup(){
424
+ /* display processing icon */
425
+ $('.backup-icon').css('visibility', 'visible');
426
+ $('.backup-icon').show();
427
+
428
+ /* hide default message */
429
+ $('.backup-success').hide();
430
+ $('.default-status').hide();
431
+ $('.backup-error').hide();
432
+
433
+ /* hide the status just incase this is the second run */
434
+ $("ul.backup-status").children().children().hide();
435
+ $(".backup-errors").children().children().hide();
436
+ $(".backup-success").children().children().hide();
437
+
438
+ /* show backup status, backup errors */
439
+ $('.backup-status').show();
440
+ window.intervalDefine = setInterval(wpbackitup_get_backup_status, 5000);
441
+ }
442
+
443
+
444
+ //RESTORE button click
445
  $('#datatable').on('click', 'a.restoreRow', function(e) {
446
  e.preventDefault();
447
 
448
  if (confirm('Are you sure you want to restore your site?'))
449
  {
 
450
  var filename = this.title;
451
  var row = this.id.replace('restoreRow', 'row');
452
  userid = $('input[name=user_id]').val();
453
 
454
+ var jqxhr = $.ajax({
455
  url: ajaxurl,
456
  type: 'post',
457
+ data: {action: wpbackitup_get_action_name('restore'), selected_file: filename,user_id: userid},
458
+ cache: false,
459
+ dataType: "json",
460
+
461
+ //success: function(response) {
462
+ // /* Return PHP messages, used for development */
463
+ // $("#php").html(response);
464
+ //
465
+ // //clearInterval(window.intervalDefine);
466
+ // var data = $.parseJSON(response);
467
+ //
468
+ //},
469
+ beforeSend: function () {
470
+ console.log("BeforeSend:Nothing to report.");
471
+ wpbackitup_show_restore();
472
+ }
473
+ });
474
+
475
+ //Fetch the JSON response file if it exists
476
+ jqxhr.always(function(data, textStatus, errorThrown) {
477
+ console.log("Restore Button Click - Always");
478
+ //console.log("Response:" + data);
479
+ });
480
+ }
481
+ });
482
 
 
 
483
 
484
+ function wpbackitup_show_restore(){
485
+ /* display processing icon */
486
+ $('.restore-icon').css('visibility', 'visible');
 
487
 
488
+ /* hide default message, backup status and backup errors */
489
+ $('.default-status, .upload-status').hide();
490
 
491
+ $("ul.restore-status").children().children().hide();
492
+ $(".restore-errors").children().children().hide();
493
+ $(".restore-success").children().children().hide();
494
 
495
+ /* show restore status messages */
496
+ $('.restore-status, .restore-errors, .restore-success').show();
497
+ $('.preparing-icon').css('visibility', 'visible');
498
+ $('.preparing').find(".status-icon").fadeIn(1500);
499
 
500
+ window.intervalDefine = setInterval(wpbackitup_get_restore_status, 5000);
501
+ }
 
 
 
502
 
503
  /*Upload form button*/
504
  $("#upload-form").submit(function() {
506
  //e.preventDefault();
507
 
508
  //CHECK ERRORS ON USER SIDE, IF TRUE, END OPERATIONS.
509
+ if (wpbackitup_upload_errors()){
510
  return false;
511
  }
512
 
514
  jQuery.each($('#wpbackitup-zip')[0].files, function(i, file) {
515
  formData.append('uploadFile-'+i, file);
516
  });
517
+ formData.append('action', wpbackitup_get_action_name('upload'));
518
  formData.append('_wpnonce', $('#_wpnonce').val());
519
  formData.append('_wp_http_referer',$("[name='_wp_http_referer']").val());
520
 
573
  if (data.msg == 'success')
574
  {
575
  status_message=data.file + ' file was uploaded successfully...';
576
+ wpbackitup_processRow_restore(data);
577
  $('.upload-status').addClass("isa_success");
578
  }else{
579
  status_message='Error: &nbsp;' + data.error;
608
  $.ajax({
609
  url: ajaxurl,
610
  type: 'post',
611
+ data: {action: wpbackitup_get_action_name('delete_file'), filed: filename},
612
  success: function(data) {
613
  if (data === 'deleted')
614
  {
628
  });
629
 
630
 
631
+ function wpbackitup_processRow_backup(data)
632
  {
633
  // decide class of row to be inserted dynamically
634
  var css_class;
643
  cur_row++;
644
 
645
  // built id of the row to be inserted dynamically
646
+ if (typeof data !== 'undefined')
647
  {
648
+ var restoreColumn = '<td><a href="#" title="' + data.backupFile + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n';
649
 
650
  var viewColumn = '<td>&nbsp;</td>\n';
651
+ if (typeof data.backupLogLink !== 'undefined') {
652
+ viewColumn = '<td><a class="viewloglink" href="' + data.backupLogLink + '">View Log</a></td>\n';
653
  }
654
 
655
  var newRow =
656
  '<tr ' + css_class + ' id="row' + cur_row + '">\n\
657
  <td>New Backup!</td>\n\
658
+ <td><a href="' + data.backupZipLink + '">Download</a></td>\n';
 
659
  newRow +=viewColumn;
660
+ newRow +='<td><a href="#" title="' + data.backupFile + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n';
661
  newRow +='</tr>';
662
 
663
  if ($('#nofiles'))
667
  $('#datatable').prepend(newRow);
668
  $('#datatable tr:first').hide().show('slow'); // just an animation to show newly added row
669
 
670
+ if(total_rows >= data.backupRetained)
671
  $('#datatable tr:last').hide();
672
 
673
+ wpbackitup_add_viewlog_onclick();
674
 
675
  }
676
  }
677
 
678
+ function wpbackitup_processRow_restore(data)
679
  {
680
  // decide class of row to be inserted dynamically
681
  var css_class;
713
  }
714
  }
715
 
716
+ function wpbackitup_upload_errors()
717
  {
718
  if ($('#wpbackitup-zip').val() == '')
719
  {
732
  return false;
733
  }
734
 
735
+ function wpbackitup_get_action_name(action) {
736
  return namespace + '_' + action;
737
  }
738
 
739
+ function wpbackitup_dismiss_message(){
740
  notification_bar = $( "#wp-backitup-notification-parent");
741
  notification_bar.fadeOut( "slow" )
742
  }
743
 
744
+ function wpbackitup_show_success_message(message){
745
  notification_bar_message = $( "#wp-backitup-notification-message");
746
  notification_bar_message.html("<p>" + message + "</p>");
747
 
753
  $('html, body').animate({ scrollTop: 0 }, 'slow');
754
  }
755
 
756
+ function wpbackitup_show_error_message(message){
757
  notification_bar_message = $( "#wp-backitup-notification-message");
758
  notification_bar_message.html("<p>" + message + "</p>");
759
 
765
  $('html, body').animate({ scrollTop: 0 }, 'slow');
766
  }
767
 
768
+
769
+ //**TEST METHODS**//
770
+
771
+ //wpbackitup_show_restore();
772
+ //wpbackitup_show_backup();
773
+
774
  })(jQuery);
lib/includes/backup.php DELETED
@@ -1,494 +0,0 @@
1
- <?php if (!defined ('ABSPATH')) die('No direct access allowed');
2
- //limit process to 15 minutes
3
- @set_time_limit(900);
4
-
5
- /**
6
- * WP Backitup Backup
7
- *
8
- * @package WP Backitup
9
- *
10
- * @author cssimmon
11
- *
12
- */
13
-
14
- /*** Includes ***/
15
-
16
- if( !class_exists( 'WPBackItUp_Logger' ) ) {
17
- include_once 'class-logger.php';
18
- }
19
-
20
- if( !class_exists( 'WPBackItUp_Utility' ) ) {
21
- include_once 'class-utility.php';
22
- }
23
-
24
-
25
- if( !class_exists( 'WPBackItUp_SQL' ) ) {
26
- include_once 'class-sql.php';
27
- }
28
-
29
- // include backup class
30
- if( !class_exists( 'WPBackItUp_Backup' ) ) {
31
- include_once 'class-backup.php';
32
- }
33
-
34
- // include logger class
35
- if( !class_exists( 'WPBackItUp_Zip' ) ) {
36
- include_once 'class-zip.php';
37
- }
38
-
39
- // include file system class
40
- if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
41
- include_once 'class-filesystem.php';
42
- }
43
-
44
- /*** Globals ***/
45
- global $WPBackitup;
46
-
47
- global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
48
- $inactive=0;
49
- $active=1;
50
- $complete=2;
51
- $failure=-1;
52
- $warning=-2;
53
- $success=99;
54
-
55
- //setup the status array
56
- global $status_array;
57
- $status_array = array(
58
- 'preparing' =>$inactive,
59
- 'backupdb' =>$inactive ,
60
- 'infofile'=>$inactive,
61
- 'backupfiles'=>$inactive,
62
- 'zipfile'=>$inactive,
63
- 'cleanup'=>$inactive
64
- );
65
-
66
- $backup_name = get_backup_name();
67
-
68
- global $logger;
69
- $logger = new WPBackItUp_Logger(false,null,$backup_name);
70
-
71
- global $wp_backup;
72
- $wp_backup = new WPBackItUp_Backup($logger,$backup_name,$WPBackitup->backup_type);
73
-
74
- //*****************//
75
- //*** MAIN CODE ***//
76
- //*****************//
77
- $logger->log('***BEGIN BACKUP***');
78
- $logger->logConstants();
79
-
80
- $logger->log('Backup Type:' .strtoupper($wp_backup->backup_type));
81
-
82
- //Check to see if a backup is already running
83
- if (!$wp_backup->start()) {
84
- $logger->log('Backup Already in progress');
85
- if ($wp_backup->backup_type=='manual'){
86
- $wp_backup->check_lock_status();
87
- }
88
- end_backup();
89
- }
90
-
91
- //Run cleanup only
92
- if ($wp_backup->backup_type=='cleanup'){
93
- $logger->log('Cleanup requested');
94
- $wp_backup->cleanup_unfinished_backups();
95
- $wp_backup->purge_old_files();
96
- $current_datetime = current_time( 'timestamp' );
97
- $WPBackitup->set_cleanup_lastrun_date($current_datetime);
98
- end_backup();
99
- }
100
-
101
- //This is neither a scheduled OR manual backup so just run some cleanup
102
- if ($wp_backup->backup_type!='scheduled' && $wp_backup->backup_type!='manual'){
103
- $logger->log('No backup requested - ending');
104
- end_backup();
105
- }
106
-
107
- // Run scheduled OR manual backup
108
-
109
- $WPBackitup->increment_backup_count();
110
-
111
- //Cleanup & Validate the backup folded is ready
112
- write_response_file("preparing for backup");
113
- set_status('preparing',$active,true);
114
- sleep(3);//For UI only
115
-
116
- //TESTS GO HERE
117
-
118
- //TEST END HERE
119
-
120
- $logger->log('**BEGIN CLEANUP**');
121
- write_response_file("Cleanup before backup");
122
-
123
- //Cleanup any backups that didnt finish normally
124
- $wp_backup->cleanup_unfinished_backups();
125
-
126
- //Make sure wpbackitup_backups exists
127
- if (!$wp_backup->backup_root_folder_exists()){
128
- write_fatal_error_status('error101');
129
- end_backup(101, false);
130
- }
131
-
132
- //Create the root folder for the current backup
133
- if (!$wp_backup->create_current_backup_folder()){
134
- write_fatal_error_status('error101');
135
- end_backup(101, false);
136
- }
137
-
138
- //Check to see if the directory exists and is writeable
139
- if (!$wp_backup->backup_folder_exists()){
140
- write_fatal_error_status('error102');
141
- end_backup(102,false);
142
- }
143
-
144
- set_status('preparing',$complete,false);
145
- $logger->log('**END CLEANUP**');
146
-
147
- //Backup the database
148
- $logger->log('**BEGIN SQL EXPORT**');
149
- write_response_file("Create SQL Export");
150
- set_status('backupdb',$active,true);
151
- sleep(3);//For UI only
152
- if (!$wp_backup->export_database()){
153
- write_fatal_error_status('error104');
154
- cleanup_on_failure($wp_backup->backup_project_path);
155
- end_backup(104,false);
156
- }
157
-
158
- set_status('backupdb',$complete,false);
159
- $logger->log('**END SQL EXPORT**');
160
-
161
- //Extract the site info
162
- $logger->log('**SITE INFO**');
163
- write_response_file("Retrieve Site Info");
164
- set_status('infofile',$active,true);
165
- sleep(3);//For UI only
166
-
167
- if (!$wp_backup->create_siteinfo_file()){
168
- write_fatal_error_status('error105');
169
- cleanup_on_failure($wp_backup->backup_project_path);
170
- end_backup(105,false);
171
- }
172
-
173
- set_status('infofile',$complete,false);
174
- $logger->log('**END SITE INFO**');
175
-
176
-
177
- //Backup the WP-Content
178
- $logger->log('**WP CONTENT**');
179
- write_response_file("Backup Content");
180
- set_status('backupfiles',$active,true);
181
- sleep(3);//For UI only
182
-
183
- if (!$wp_backup->backup_wpcontent()){
184
- write_fatal_error_status('error103');
185
- cleanup_on_failure($wp_backup->backup_project_path);
186
- end_backup(103,false);
187
- }
188
-
189
- //auditing only
190
- //If logging is turned on Validate
191
- if ($WPBackitup->logging()){
192
- $wp_backup->validate_wpcontent();
193
- }
194
- set_status('backupfiles',$complete,false);
195
- $logger->log('**END WP CONTENT**');
196
-
197
- //Zip up the backup folder
198
- $logger->log('**BACKUP ZIP**');
199
- write_response_file("Compress Backup ");
200
- set_status('zipfile',$active,true);
201
- sleep(3);//For UI only
202
- if (!$wp_backup->compress_backup()){
203
- write_fatal_error_status('error107');
204
- cleanup_on_failure($wp_backup->backup_project_path);
205
- end_backup(107,false);
206
- }
207
-
208
- set_status('zipfile',$complete,false);
209
- $logger->log('**END BACKUP ZIP**');
210
-
211
-
212
-
213
- //Cleanup
214
- $logger->log('**CLEANUP**');
215
- write_response_file("Cleanup after Backup ");
216
- set_status('cleanup',$active,true);
217
-
218
- if (!$wp_backup->cleanup_current_backup()){
219
- write_warning_status('error106');
220
- }
221
-
222
- //Check retention limits and cleanup
223
- $wp_backup->purge_old_files();
224
-
225
- set_status('cleanup',$complete,false);
226
- $logger->log('**END CLEANUP**');
227
-
228
- //DONE!
229
- set_status_success();
230
- write_response_file_success();
231
-
232
- $WPBackitup->increment_successful_backup_count();
233
-
234
- end_backup(null,true);
235
-
236
- /******************/
237
- /*** Functions ***/
238
- /******************/
239
- function get_backup_name(){
240
-
241
- $url = str_replace('http://','',home_url());
242
- $url = str_replace('/','-',$url);
243
- $fileUTCDateTime=current_time( 'timestamp' );
244
- $localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
245
- $backup_name = 'Backup_' . $url .'_' .$localDateTime;
246
-
247
- return $backup_name;
248
-
249
- }
250
- function end_backup($err=null, $success=null){
251
- global $wp_backup, $logger;
252
- $logger->log_info(__METHOD__,"Begin");
253
-
254
- $wp_backup->end(); //Release the lock
255
-
256
- $util = new WPBackItUp_Utility($logger);
257
- $seconds = $util->date_diff_seconds($wp_backup->backup_start_time,$wp_backup->backup_end_time);
258
-
259
- $processing_minutes = round($seconds / 60);
260
- $processing_seconds = $seconds % 60;
261
-
262
- $logger->log('Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
263
-
264
- //if null was passed then this was just a schedule check
265
- if (null!=$success){
266
- send_backup_notification_email($err, $success);
267
- }
268
-
269
- if ($success) $logger->log("Backup completed successfully");
270
- $logger->log("*** END BACKUP ***");
271
-
272
- $logFileName = $logger->logFileName;
273
- $logFilePath = $logger->logFilePath;
274
- $logger->close_file();
275
-
276
- //Move the log if it exists
277
- $newlogFilePath = $wp_backup->backup_folder_root .$logFileName;
278
- if (file_exists($logFilePath)){
279
- copy ($logFilePath,$newlogFilePath);
280
- unlink($logFilePath);
281
- }
282
-
283
- echo('Backup has completed');
284
- exit(0);
285
- }
286
-
287
- function send_backup_notification_email($err, $success) {
288
- global $WPBackitup, $wp_backup, $logger,$status_array;
289
- $logger->log_info(__METHOD__,"Begin");
290
-
291
- $utility = new WPBackItUp_Utility($logger);
292
-
293
- $util = new WPBackItUp_Utility($logger);
294
- $seconds = $util->date_diff_seconds($wp_backup->backup_start_time,$wp_backup->backup_end_time);
295
-
296
- $processing_minutes = round($seconds / 60);
297
- $processing_seconds = $seconds % 60;
298
-
299
- $status_description = array(
300
- 'preparing'=>'Preparing for backup...Done',
301
- 'backupdb'=>'Backing-up database...Done',
302
- 'infofile'=>'Creating backup information file...Done',
303
- 'backupfiles'=>'Backing up plugins, themes, and uploads...Done',
304
- 'zipfile'=>'Zipping backup directory...Done',
305
- 'cleanup'=>'Cleaning up...Done'
306
- );
307
-
308
- $error_description = array(
309
- '101' =>'Error 101: Unable to create a new directory for backup. Please check your CHMOD settings of your wp-backitup backup directory',
310
- '102'=> 'Error 102: Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory',
311
- '103'=> 'Error 103: Unable to backup your files. Please try again',
312
- '104'=> 'Error 104: Unable to backup your database. Please try again',
313
- '105'=> 'Error 105: Unable to create site information file. Please try again',
314
- '106'=> 'Warning 106: Unable to cleanup your backup directory',
315
- '107'=> 'Error 107: Unable to compress(zip) your backup. Please try again',
316
- '114'=> 'Error 114: Your database was accessible but an export could not be created. Please contact support by clicking the get support link on the right. Please let us know who your host is when you submit the request'
317
-
318
- );
319
-
320
- if($success)
321
- {
322
- $subject = 'WP BackItUp - Backup completed successfully.';
323
- $message = '<b>Your backup completed successfully.</b><br/><br/>';
324
-
325
- } else {
326
- $subject = 'WP BackItUp - Backup did not complete successfully.';
327
- $message = '<b>Your backup did not complete successfully.</b><br/><br/>';
328
- }
329
-
330
- $message .= 'Backup started: ' . $wp_backup->backup_start_time->format( 'Y-m-d H:i:s') . '<br/>';
331
- $message .= 'Backup ended: ' . $wp_backup->backup_end_time->format( 'Y-m-d H:i:s') . '<br/>';
332
- $message .= 'Processing Time: ' . $processing_minutes .' Minutes ' .$processing_seconds .' Seconds <br/>';
333
-
334
- $message .= '<br/>';
335
-
336
- $message .='<b>Steps Completed</b><br/>';
337
-
338
- //Add the completed statuses
339
- foreach ($status_array as $status_key => $status_value) {
340
- // echo($status_key. ':' .$status_value);
341
- if ($status_value==2) {
342
- foreach ($status_description as $msg_key => $msg_value) {
343
- // echo($status_key. ':' .$msg_key);
344
- if ($status_key==$msg_key) {
345
- $message .= $msg_value . '<br/>';
346
- break;
347
- }
348
- }
349
- }
350
- }
351
-
352
- //Add the errors
353
- if(!$success)
354
- {
355
- $message .= '<br/>';
356
- $message .= 'Errors:<br/>';
357
-
358
- foreach ($error_description as $key => $value) {
359
- if ($err==$key){
360
- $message .=$error_description[$key];
361
- }
362
- }
363
- }
364
-
365
- $term='success';
366
- if(!$success)$term='error';
367
- $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/>';
368
-
369
- $notification_email = $WPBackitup->get_option('notification_email');
370
- if($notification_email)
371
- $utility->send_email($notification_email,$subject,$message);
372
-
373
- $logger->log_info(__function__,"End");
374
- }
375
-
376
- function cleanup_on_failure($path){
377
- global $logger;
378
- global $wp_backup;
379
-
380
- if (WPBACKITUP__DEBUG===true){
381
- $logger->log('Cleanup On Fail suspended: debug on.');
382
- }
383
- else{
384
- $wp_backup->cleanup_unfinished_backups();
385
- }
386
- }
387
-
388
- function write_fatal_error_status($status_code) {
389
- global $status_array,$active,$failure;
390
-
391
- //Find the active status and set to failure
392
- foreach ($status_array as $key => $value) {
393
- if ($value==$active){
394
- $status_array[$key]=$failure;
395
- }
396
- }
397
-
398
- //Add failure to array
399
- $status_array[$status_code]=$failure;
400
- write_status();
401
- }
402
-
403
- function write_warning_status($status_code) {
404
- global $status_array,$warning;
405
-
406
- //Add warning to array
407
- $status_array[$status_code]=$warning;
408
- write_status();
409
- }
410
-
411
- function write_status() {
412
- global $status_array;
413
- $fh=getStatusLog();
414
-
415
- foreach ($status_array as $key => $value) {
416
- fwrite($fh, '<div class="' . $key . '">' . $value .'</div>');
417
- }
418
- fclose($fh);
419
- }
420
-
421
- function set_status($process,$status,$flush){
422
- global $status_array;
423
- $status_array[$process]=$status;
424
-
425
- if ($flush) write_status();
426
- }
427
-
428
- function set_status_success(){
429
- global $status_array,$success;
430
-
431
- $status_array['finalinfo']=$success;
432
- write_status();
433
- }
434
-
435
- //Get Status Log
436
- function getStatusLog() {
437
- $log = WPBACKITUP__PLUGIN_PATH .'/logs/status.log';
438
- if (file_exists($log)){
439
- unlink($log);
440
- }
441
- $fh = fopen($log, 'w') or die( "Can't write to log file" );
442
- return $fh;
443
- }
444
-
445
- //write Response Log
446
- function write_response_file($message) {
447
- global $wp_backup,$logger;
448
-
449
- $jsonResponse = new stdClass();
450
- $jsonResponse->message = $message;
451
- $jsonResponse->server_time=$wp_backup->backup_start_time->format('U');
452
-
453
- $json_response = json_encode($jsonResponse);
454
- $logger->log('Write response file:' . $json_response);
455
-
456
- $fh=get_response_file();
457
- fwrite($fh, $json_response);
458
- fclose($fh);
459
- }
460
-
461
- //write Response Log
462
- function write_response_file_success() {
463
- global $WPBackitup,$wp_backup,$logger;
464
-
465
- //Send JSON response
466
- $jsonResponse = new stdClass();
467
- $jsonResponse->message = 'success';
468
- $jsonResponse->file = $wp_backup->backup_filename;
469
- $jsonResponse->zip_link = WPBACKITUP__BACKUP_URL . '/' . $wp_backup->backup_filename;
470
- $jsonResponse->license = $WPBackitup->license_active();
471
- $jsonResponse->retained = $wp_backup->backup_retained_number;
472
-
473
- if (file_exists($logger->logFilePath)) {
474
- $jsonResponse->log_link = basename($logger->logFileName,'.log');
475
- }
476
-
477
- $json_response = json_encode($jsonResponse);
478
- $logger->log('Write response file:' . $json_response);
479
-
480
- $fh=get_response_file();
481
- fwrite($fh, $json_response);
482
- fclose($fh);
483
- }
484
-
485
- //Get Response Log
486
- function get_response_file() {
487
- global $logger;
488
- $response_file_path = WPBACKITUP__PLUGIN_PATH .'logs/response.log';
489
- $filesytem = new WPBackItUp_FileSystem($logger);
490
- return $filesytem->get_file_handle($response_file_path,true);
491
- }
492
-
493
-
494
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/includes/class-backup.php CHANGED
@@ -28,14 +28,20 @@ class WPBackItUp_Backup {
28
  public $restore_folder_root;
29
  public $backup_retained_number;
30
  public $backup_retained_days;
 
31
 
32
  //scheduled,manual,none
33
  public $backup_type;
34
- public $backup_start_time;
35
- public $backup_end_time;
36
 
37
- private $lockFileName;
38
- private $lockFile;
 
 
 
 
 
 
 
39
 
40
  function __construct($logger,$backup_name, $backup_type) {
41
  global $WPBackitup;
@@ -43,8 +49,13 @@ class WPBackItUp_Backup {
43
  $this->logger = $logger;
44
 
45
  $this->backup_type=$backup_type;
 
 
 
 
 
46
  $this->backup_name=$backup_name;
47
- $this->backup_filename=$backup_name . '.zip';
48
 
49
  $backup_project_path = WPBACKITUP__BACKUP_PATH .'/'. $backup_name .'/';
50
 
@@ -55,10 +66,8 @@ class WPBackItUp_Backup {
55
  $this->backup_folder_root=$backup_folder_root;
56
  $this->restore_folder_root=$restore_folder_root;
57
 
58
- $this->lockFileName = WPBACKITUP__PLUGIN_PATH .'logs/wpbackitup_lock.lock';
59
-
60
  $this->backup_retained_number = $WPBackitup->backup_retained_number();
61
- $this->backup_retained_days = 5; //Prob need to move this to main propery
62
 
63
  } catch(Exception $e) {
64
  $this->logger->log_error(__METHOD__,'Constructor Exception: ' .$e);
@@ -76,21 +85,23 @@ class WPBackItUp_Backup {
76
  * Begin backup process - Only one may be running at a time
77
  * @return bool
78
  */
79
- public function start (){
 
80
  try {
81
- $this->logger->log_info(__METHOD__,'Begin - Lock File:' . $this->lockFileName);
82
- $this->backup_start_time= new datetime('now');
83
- $this->lockFile = fopen( $this->lockFileName ,"w"); // open it for WRITING ("w")
84
- if (flock( $this->lockFile, LOCK_EX | LOCK_NB)) {
85
- $this->logger->log_info(__METHOD__,'Process LOCK acquired');
 
86
  return true;
87
  } else {
88
- $this->logger->log_info(__METHOD__,'Process LOCK failed');
89
  return false;
90
  }
91
 
92
  } catch(Exception $e) {
93
- $this->logger->log_info(__METHOD__,'Process Lock error: ' .$e);
94
  return false;
95
  }
96
  }
@@ -99,21 +110,16 @@ class WPBackItUp_Backup {
99
  * End Backup Process
100
  * @return bool
101
  */
102
- public function end (){
103
- global $WPBackitup;
104
- $this->logger->log_info(__METHOD__,'Begin - Unlock File:' . $this->lockFileName);
105
-
106
- $current_datetime = current_time( 'timestamp' );
107
- $WPBackitup->set_backup_lastrun_date($current_datetime);
108
 
109
- $this->backup_end_time= new datetime('now');
110
  try{
111
- $this->logger->log_info(__METHOD__,'LOCK released - backup ending');
112
- flock( $this->lockFile, LOCK_UN); // unlock the file
113
  return true;
114
 
115
  }catch(Exception $e) {
116
- $this->logger->log_error(__METHOD__,'Cant unlock file: ' .$e);
117
  return false;
118
  }
119
  }
@@ -186,13 +192,31 @@ class WPBackItUp_Backup {
186
  //Check the retention
187
  $fileSystem->purge_FilesByDate($this->backup_retained_number,$this->backup_folder_root);
188
 
189
- //Purge logs older than 5 days
190
- $fileSystem->purge_files(WPBACKITUP__BACKUP_PATH .'/','*.log',$this->backup_retained_days);
 
 
191
 
192
- //Purge logs in logs older than 5 days
 
 
 
193
  $logs_path = WPBACKITUP__PLUGIN_PATH .'/logs/';
 
 
194
  $fileSystem->purge_files($logs_path,'Backup_*.log',$this->backup_retained_days);
195
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  $this->logger->log_info(__METHOD__,'End');
198
 
@@ -207,6 +231,13 @@ class WPBackItUp_Backup {
207
  return false;
208
  }
209
 
 
 
 
 
 
 
 
210
  $this->logger->log_info(__METHOD__,'End');
211
  return true;
212
  }
@@ -258,6 +289,14 @@ class WPBackItUp_Backup {
258
  }
259
  }
260
  $this->logger->log_info(__METHOD__,'Database Exported successfully');
 
 
 
 
 
 
 
 
261
  return true;
262
  }
263
 
@@ -301,54 +340,380 @@ class WPBackItUp_Backup {
301
  return false;
302
  }
303
 
304
- //BackUp WPContent
305
- public function backup_wpcontent(){
306
- $fromFolder = WPBACKITUP__CONTENT_PATH . '/';
307
- $ignore = array( WPBACKITUP__BACKUP_FOLDER,$this->backup_name,$this->restore_folder_root,'upgrade','cache' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
- $this->logger->log_info(__METHOD__,'Begin');
310
 
311
- $this->logger->log_info(__METHOD__,'Recursive Copy FROM:'.$fromFolder);
312
- $this->logger->log_info(__METHOD__,'Recursive Copy TO:'.$this->backup_project_path);
313
- $this->logger->log_info(__METHOD__,$ignore,'Ignore Array');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
 
315
- $fileSystem = new WPBackItUp_FileSystem($this->logger);
316
- if(!$fileSystem->recursive_copy($fromFolder, $this->backup_project_path, $ignore) ) {
317
- $this->logger->log_error(__METHOD__,'Site content was NOT copied successfully.');
318
- return false;
319
- }
320
- $this->logger->log_info(__METHOD__,'Site content copied successfully.');
321
- return true;
322
- }
323
 
324
- public function validate_wpcontent(){
325
- $this->logger->log_info(__METHOD__,'Begin - Validate WPContent');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
- $source_dir_path = WPBACKITUP__CONTENT_PATH . '/';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  $target_dir_path = $this->backup_project_path;
329
 
330
- $this->logger->log_info(__METHOD__,'Validate content folder TO:' .$source_dir_path);
331
  $this->logger->log_info(__METHOD__,'Validate content folder FROM:' .$target_dir_path);
 
332
 
333
- $ignore = array(WPBACKITUP__PLUGIN_FOLDER,'debug.log','backupsiteinfo.txt','db-backup.sql');
334
- $filesystem = new WPBackItUp_FileSystem($this->logger);
335
- if(!$filesystem->recursive_validate($source_dir_path. '/', $target_dir_path . '/',$ignore)) {
336
- $this->logger->log_error(__METHOD__,'Content folder is not the same as backup.');
337
- }
338
 
339
- $this->logger->log_info(__METHOD__,'End - Validate WPContent');
340
- }
341
 
342
- public function compress_backup(){
343
- $this->logger->log_info(__METHOD__, 'Begin - Compress the backup:'.$this->backup_project_path);
344
 
345
- $zip = new WPBackItUp_Zip($this->logger);
346
- if (!$zip->compress($this->backup_project_path, $this->backup_folder_root)){
347
- $this->logger->log_error(__METHOD__, 'Could not compress backup folder');
348
- return false;
 
 
 
 
349
  }
350
 
351
- $this->logger->log_info(__METHOD__, 'End - Compress the backup');
352
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  }
28
  public $restore_folder_root;
29
  public $backup_retained_number;
30
  public $backup_retained_days;
31
+ public $backup_batch_size;
32
 
33
  //scheduled,manual,none
34
  public $backup_type;
 
 
35
 
36
+ private static $lockFileName;
37
+ private static $lockFile;
38
+
39
+
40
+ //-------------STATIC FUNCTIONS-------------------//
41
+
42
+
43
+
44
+ //-------------END STATIC FUNCTIONS-------------------//
45
 
46
  function __construct($logger,$backup_name, $backup_type) {
47
  global $WPBackitup;
49
  $this->logger = $logger;
50
 
51
  $this->backup_type=$backup_type;
52
+
53
+ $this->backup_batch_size=1; //manual backups
54
+ if ('scheduled'==$this->backup_type){
55
+ $this->backup_batch_size=$WPBackitup->backup_batch_size(); //Scheduled
56
+ }
57
  $this->backup_name=$backup_name;
58
+ $this->backup_filename=$backup_name . '.tmp';
59
 
60
  $backup_project_path = WPBACKITUP__BACKUP_PATH .'/'. $backup_name .'/';
61
 
66
  $this->backup_folder_root=$backup_folder_root;
67
  $this->restore_folder_root=$restore_folder_root;
68
 
 
 
69
  $this->backup_retained_number = $WPBackitup->backup_retained_number();
70
+ $this->backup_retained_days = WPBACKITUP__BACKUP_RETAINED_DAYS; //Prob need to move this to main propery
71
 
72
  } catch(Exception $e) {
73
  $this->logger->log_error(__METHOD__,'Constructor Exception: ' .$e);
85
  * Begin backup process - Only one may be running at a time
86
  * @return bool
87
  */
88
+ public static function start (){
89
+ $logger = new WPBackItUp_Logger(false,null,'debug_lock');
90
  try {
91
+ self::$lockFileName = WPBACKITUP__PLUGIN_PATH .'logs/wpbackitup_lock.lock';
92
+ $logger->log_info(__METHOD__,'Begin - Lock File:' . self::$lockFileName);
93
+
94
+ self::$lockFile = fopen(self::$lockFileName ,"w"); // open it for WRITING ("w")
95
+ if (flock( self::$lockFile, LOCK_EX | LOCK_NB)) {
96
+ $logger->log_info(__METHOD__,'Process LOCK acquired');
97
  return true;
98
  } else {
99
+ $logger->log_info(__METHOD__,'Process LOCK failed');
100
  return false;
101
  }
102
 
103
  } catch(Exception $e) {
104
+ $logger->log_info(__METHOD__,'Process Lock error: ' .$e);
105
  return false;
106
  }
107
  }
110
  * End Backup Process
111
  * @return bool
112
  */
113
+ public static function end (){
114
+ //$this->logger->log_info(__METHOD__,'Begin - Unlock File:' . $this->lockFileName);
 
 
 
 
115
 
 
116
  try{
117
+ //$this->logger->log_info(__METHOD__,'LOCK released - backup ending');
118
+ flock( self::$lockFile, LOCK_UN); // unlock the file
119
  return true;
120
 
121
  }catch(Exception $e) {
122
+ //$this->logger->log_error(__METHOD__,'Cant unlock file: ' .$e);
123
  return false;
124
  }
125
  }
192
  //Check the retention
193
  $fileSystem->purge_FilesByDate($this->backup_retained_number,$this->backup_folder_root);
194
 
195
+ // --PURGE BACKUP FOLDER
196
+ //Purge logs in backup older than N days
197
+ $backup_path = WPBACKITUP__BACKUP_PATH .'/';
198
+ $fileSystem->purge_files($backup_path,'*.log',$this->backup_retained_days);
199
 
200
+ //Purge restore DB checkpoints older than 5 days
201
+ $fileSystem->purge_files($backup_path,'db*.cur',$this->backup_retained_days);
202
+
203
+ // --PURGE LOGS FOLDER
204
  $logs_path = WPBACKITUP__PLUGIN_PATH .'/logs/';
205
+
206
+ //Purge logs in logs older than 5 days
207
  $fileSystem->purge_files($logs_path,'Backup_*.log',$this->backup_retained_days);
208
 
209
+ //Purge debug logs in logs older than 5 days
210
+ $fileSystem->purge_files($logs_path,'*debug*.log',$this->backup_retained_days);
211
+
212
+ //Purge upload logs in logs older than 5 days
213
+ $fileSystem->purge_files($logs_path,'*upload*.log',$this->backup_retained_days);
214
+
215
+ //Purge cleanup logs in logs older than 5 days
216
+ $fileSystem->purge_files($logs_path,'*cleanup*.log',$this->backup_retained_days);
217
+
218
+ //Purge restore logs in logs older than 5 days
219
+ $fileSystem->purge_files($logs_path,'*restore*.log',$this->backup_retained_days);
220
 
221
  $this->logger->log_info(__METHOD__,'End');
222
 
231
  return false;
232
  }
233
 
234
+ //create index.html
235
+ $backup_index = $this->backup_folder_root .'/index.html';
236
+ if( !is_file($backup_index) ) {
237
+ $dfh = fopen( $backup_index, 'a' );
238
+ fclose( $dfh );
239
+ }
240
+
241
  $this->logger->log_info(__METHOD__,'End');
242
  return true;
243
  }
289
  }
290
  }
291
  $this->logger->log_info(__METHOD__,'Database Exported successfully');
292
+
293
+ // Uncomment when encryption is added
294
+ // backup wp.config
295
+ // $from_path = get_home_path() .'/wp-config.php';
296
+ // $to_path = $this->backup_project_path .'/wp-config.bak';
297
+ // $file_system = new WPBackItUp_FileSystem($this->logger);
298
+ // $file_system->copy_file($from_path,$to_path);
299
+
300
  return true;
301
  }
302
 
340
  return false;
341
  }
342
 
343
+ //BackUp plugins
344
+ public function backup_plugins(){
345
+ $this->logger->log_info(__METHOD__,'Begin');
346
+
347
+ $plugins_root_path = WPBACKITUP__PLUGINS_ROOT_PATH .'/';
348
+ $target_plugin_root = 'wp-content-plugins';
349
+ $zip_file_path = $this->backup_folder_root . $this->backup_filename;
350
+ $zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
351
+
352
+ //Get a list of files/folders in the plugins root
353
+ $plugin_copied=false;
354
+ $backup_item_count=0;
355
+ foreach(glob($plugins_root_path. '*',GLOB_ONLYDIR ) as $dir){
356
+ $source_plugin_folder=$dir .'/';
357
+ //This is the root target - needs to be hardcoded because we need to know where to find it on the restore.
358
+ $target_plugin_folder =$target_plugin_root . '/' .basename($dir);
359
+
360
+ //If target plugin doesnt exist backitup
361
+ if (!$zip->folder_exists($target_plugin_folder)) {
362
+ //If a plugin has already been backed up then this means there is more
363
+ if ($plugin_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
364
+
365
+ $this->logger->log_info(__METHOD__,'Backing up plugin:' .$target_plugin_folder);
366
+
367
+ //Backup the plugin folder
368
+ if (!$zip->compress_folder($source_plugin_folder,$target_plugin_folder)) {
369
+ $this->logger->log_error(__METHOD__,'Plugin NOT backed up successfully.');
370
+ return 'error';
371
+ }else{
372
+ $backup_item_count++;
373
+ $this->logger->log_info(__METHOD__,'Plugin backed up successfully:' .$backup_item_count);
374
+ $plugin_copied=true;
375
+ }
376
+ }
377
+ }
378
 
 
379
 
380
+ //If we get here then there are no more folders left to backup
381
+ $this->logger->log_info(__METHOD__,'Backup all files in plugin root');
382
+ $files = array_filter(glob($plugins_root_path. '*'), 'is_file');
383
+ foreach ($files as $file){
384
+ $this->logger->log_info(__METHOD__,'Backup file:' . $file);
385
+ if (!$zip->zip_file($file,$target_plugin_root)){
386
+ $this->logger->log_error(__METHOD__,'Plugin NOT backed up successfully.');
387
+ return 'error';
388
+ }
389
+ }
390
+
391
+ $this->logger->log_info(__METHOD__,'All Plugins backed up successfully.');
392
+ return 'complete';
393
+ }
394
+
395
+ //BackUp Themes
396
+ public function backup_themes(){
397
+ $this->logger->log_info(__METHOD__,'Begin');
398
+
399
+ $themes_root_path = WPBACKITUP__THEMES_ROOT_PATH .'/';
400
+ $target_theme_root = 'wp-content-themes';
401
+
402
+ $zip_file_path = $this->backup_folder_root . $this->backup_filename;
403
+ $zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
404
+
405
+ //Get a list of files/folders in the themes root
406
+ $theme_copied=false;
407
+ $backup_item_count=0;
408
+ foreach(glob($themes_root_path. '*',GLOB_ONLYDIR ) as $dir){
409
+ $source_theme_folder=$dir .'/';
410
+ $target_theme_folder = $target_theme_root . '/' .basename($dir);
411
+
412
+ //If target theme doesnt exist backitup
413
+ if (!$zip->folder_exists($target_theme_folder)){
414
+ //If a theme has already been backed up then this means there is more
415
+ if ($theme_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
416
+
417
+ $this->logger->log_info(__METHOD__,'Backing up theme:' .$target_theme_folder);
418
+
419
+ if (!$zip->compress_folder($source_theme_folder,$target_theme_folder)) {
420
+ $this->logger->log_error(__METHOD__,'Theme NOT backed up successfully.');
421
+ return 'error';
422
+ }else{
423
+ $backup_item_count++;
424
+ $this->logger->log_info(__METHOD__,'Theme backed up successfully:' .$backup_item_count);
425
+ $theme_copied=true;
426
+ }
427
+ }
428
+ }
429
+
430
+
431
+ //If we get here then there are no more folders left to backup
432
+ $this->logger->log_info(__METHOD__,'Backup all files in theme root');
433
+ $files = array_filter(glob($themes_root_path. '*'), 'is_file');
434
+ foreach ($files as $file){
435
+ $this->logger->log_info(__METHOD__,'Backup file:' . $file);
436
+ if (!$zip->zip_file($file,$target_theme_root)) {
437
+ $this->logger->log_error(__METHOD__,'Theme NOT backed up successfully.');
438
+ return 'error';
439
+ }
440
+ }
441
+
442
+
443
+ $this->logger->log_info(__METHOD__,'All Themes backed up successfuly.');
444
+ return 'complete';
445
+ }
446
 
 
 
 
 
 
 
 
 
447
 
448
+ //BackUp Uploads
449
+ public function backup_uploads(){
450
+ $this->logger->log_info(__METHOD__,'Begin');
451
+
452
+ $upload_array = wp_upload_dir();
453
+ $uploads_root_path = $upload_array['basedir'] .'/';
454
+
455
+ $target_uploads_root = 'wp-content-uploads';
456
+ $zip_file_path = $this->backup_folder_root . $this->backup_filename;
457
+ $zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
458
+
459
+ //Get a list of files/folders in the uploads root
460
+ $upload_copied=false;
461
+ $backup_item_count=0;
462
+ $this->logger->log_info(__METHOD__,'GLOB:' .$uploads_root_path);
463
+ foreach(glob($uploads_root_path. '*',GLOB_ONLYDIR ) as $dir){
464
+ $source_upload_folder=$dir .'/';
465
+ $target_upload_folder = $target_uploads_root .'/' .basename($dir);
466
+
467
+ //If target upload doesnt exist backitup
468
+ if (!$zip->folder_exists($target_upload_folder)) {
469
+ //If an upload has already been backed up then this means there is more
470
+ if ($upload_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
471
+
472
+ $this->logger->log_info(__METHOD__,'Backing up upload:' .$target_upload_folder);
473
+
474
+ if (!$zip->compress_folder($source_upload_folder,$target_upload_folder)) {
475
+ $this->logger->log_error(__METHOD__,'Upload NOT backed up successfully.');
476
+ return 'error';
477
+ }else{
478
+ $backup_item_count++;
479
+ $this->logger->log_info(__METHOD__,'Upload backed up successfully:'.$backup_item_count);
480
+ $upload_copied=true;
481
+ }
482
+ }
483
+ }
484
+
485
+
486
+ //If we get here then there are no more folders left to backup
487
+ $this->logger->log_info(__METHOD__,'Backup all files in upload root');
488
+ $files = array_filter(glob($uploads_root_path. '*'), 'is_file');
489
+ foreach ($files as $file){
490
+ $this->logger->log_info(__METHOD__,'Backup file:' . $file);
491
+ if (!$zip->zip_file($file,$target_uploads_root)){
492
+ $this->logger->log_error(__METHOD__,'Upload NOT backed up successfully.');
493
+ return 'error';
494
+ }
495
+ }
496
 
497
+
498
+ $this->logger->log_info(__METHOD__,'All Uploads backed up successfully.');
499
+ return 'complete';
500
+ }
501
+
502
+
503
+ //Backup everything else
504
+ public function backup_other(){
505
+ $this->logger->log_info(__METHOD__,'Begin');
506
+
507
+ $wpcontent_path = WPBACKITUP__CONTENT_PATH .'/';
508
+ $upload_array = wp_upload_dir();
509
+ $uploads_folder = basename ($upload_array['basedir']);
510
+ $themes_folder = basename (WPBACKITUP__THEMES_ROOT_PATH);
511
+ $plugins_folder = basename (WPBACKITUP__PLUGINS_ROOT_PATH);
512
+
513
+ $target_other_root = 'wp-content-other';
514
+
515
+ $wpback_ignore = explode(',',WPBACKITUP__BACKUP_IGNORE_LIST);
516
+ $wpcontent_ignore=array($uploads_folder, $themes_folder, $plugins_folder);
517
+ $ignore = array_merge($wpback_ignore,$wpcontent_ignore);
518
+
519
+ $this->logger->log_info(__METHOD__,'Ignore:');
520
+ $this->logger->log($ignore);
521
+
522
+ $zip_file_path = $this->backup_folder_root . $this->backup_filename;
523
+ $zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
524
+
525
+ $other_copied=false;
526
+ $backup_item_count=0;
527
+ $this->logger->log_info(__METHOD__,'Content Root Path:' .$wpcontent_path);
528
+ foreach(glob($wpcontent_path. '*',GLOB_ONLYDIR ) as $dir){
529
+ $source_other_folder=$dir .'/';
530
+ $target_other_folder = $target_other_root .'/' .basename($dir);
531
+
532
+ //If target other doesnt exist backitup
533
+ if( !$zip->folder_exists($target_other_folder) && !in_array(basename($dir), $ignore) ) {
534
+ //If a other has already been backed up then this means there is more
535
+ if ($other_copied && ($backup_item_count>=$this->backup_batch_size)) return 'continue';
536
+
537
+ $this->logger->log_info(__METHOD__,'Backing up other:' .$target_other_folder);
538
+
539
+ if (!$zip->compress_folder($source_other_folder,$target_other_folder)) {
540
+ $this->logger->log_error(__METHOD__,'Other NOT backed up successfully.');
541
+ return 'error';
542
+ }else{
543
+ $backup_item_count++;
544
+ $this->logger->log_info(__METHOD__,'Other backed up successfully:' .$backup_item_count);
545
+ $other_copied=true;
546
+ }
547
+ }
548
+ }
549
+
550
+ //If we get here then there are no more folders left to backup
551
+ $this->logger->log_info(__METHOD__,'Backup all files in wpcontent root');
552
+ $files = array_filter(glob($wpcontent_path. '*'), 'is_file');
553
+ foreach ($files as $file){
554
+ $this->logger->log_info(__METHOD__,'Backup file:' . $file);
555
+ if (!$zip->zip_file($file,$target_other_root)) {
556
+ $this->logger->log_error(__METHOD__,'Other NOT backed up successfully.');
557
+ return 'error';
558
+ }
559
+ }
560
+
561
+ $this->logger->log_info(__METHOD__,'All Others backed up successfully.');
562
+ return 'complete';
563
+ }
564
+
565
+ //backup all files in the site-data folder
566
+ public function backup_site_data(){
567
+ $this->logger->log_info(__METHOD__, 'Begin - Compress backup folder items:'.$this->backup_project_path);
568
+
569
+ $target_other_root = 'site-data';
570
+
571
+ $zip_file_path = $this->backup_folder_root . $this->backup_filename;
572
+ $zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
573
+
574
+ $this->logger->log_info(__METHOD__,'Backup all files in root of backup folder.');
575
+ $files = array_filter(glob($this->backup_project_path. '*'), 'is_file');
576
+ foreach ($files as $file){
577
+ $this->logger->log_info(__METHOD__,'Backup file:' . $file);
578
+ if (!$zip->zip_file($file,$target_other_root)){
579
+ return false;
580
+ }
581
+ }
582
+
583
+
584
+ $this->logger->log_info(__METHOD__, 'End - Compress backup folder items.');
585
+ return true;
586
+ }
587
+
588
+
589
+ public function validate_backup(){
590
+ $this->logger->log_info(__METHOD__,'Begin - Validate backup');
591
+
592
+ $source_dir_path = WPBACKITUP__CONTENT_PATH ;
593
  $target_dir_path = $this->backup_project_path;
594
 
 
595
  $this->logger->log_info(__METHOD__,'Validate content folder FROM:' .$target_dir_path);
596
+ $this->logger->log_info(__METHOD__,'Validate content folder TO:' .$source_dir_path);
597
 
 
 
 
 
 
598
 
 
 
599
 
600
+ $zip_file_path = $this->backup_folder_root . $this->backup_filename;
601
+ $zip = new WPBackItUp_Zip($this->logger,$zip_file_path);
602
 
603
+ //Validate plugins
604
+ //Check the plugins folder
605
+ $plugins_root_path = WPBACKITUP__PLUGINS_ROOT_PATH;
606
+ $target_plugin_root = 'wp-content-plugins';
607
+ if(! $zip->validate_folder($plugins_root_path, $target_plugin_root)) {
608
+ $this->logger->log_error(__METHOD__,'Plugins Validation:FAIL');
609
+ }else{
610
+ $this->logger->log_info(__METHOD__,'Plugins Validation:SUCCESS');
611
  }
612
 
613
+ //Validate Themes
614
+ $themes_root_path = WPBACKITUP__THEMES_ROOT_PATH .'/';
615
+ $target_theme_root = 'wp-content-themes';
616
+ if(! $zip->validate_folder($themes_root_path, $target_theme_root)) {
617
+ $this->logger->log_error(__METHOD__,'Themes Validation:FAIL');
618
+ }else{
619
+ $this->logger->log_info(__METHOD__,'Themes Validation:SUCCESS');
620
+ }
621
+
622
+ //Validate Uploads
623
+ $upload_array = wp_upload_dir();
624
+ $uploads_root_path = $upload_array['basedir'] .'/';
625
+ $target_uploads_root = 'wp-content-uploads';
626
+ if(! $zip->validate_folder($uploads_root_path, $target_uploads_root)) {
627
+ $this->logger->log_error(__METHOD__,'Uploads Validation:FAIL');
628
+ }else{
629
+ $this->logger->log_info(__METHOD__,'Uploads Validation:SUCCESS');
630
+ }
631
+
632
+ //Validate everything on the that was in the backup temp folder
633
+ $site_data_root_path = $this->backup_project_path .'/';
634
+ $target_site_data_root = 'site-data';
635
+ if(! $zip->validate_folder($site_data_root_path, $target_site_data_root)) {
636
+ $this->logger->log_error(__METHOD__,'Site Data Validation:FAIL');
637
+ }else{
638
+ $this->logger->log_info(__METHOD__,'Site Data Validation:SUCCESS');
639
+ }
640
+
641
+ //Validate Other
642
+ $wpback_ignore = explode(',',WPBACKITUP__BACKUP_IGNORE_LIST);
643
+ $wpcontent_ignore=array(basename($uploads_root_path), basename($themes_root_path), basename($plugins_root_path));
644
+ $ignore = array_merge($wpback_ignore,$wpcontent_ignore);
645
+
646
+ $wpcontent_path = WPBACKITUP__CONTENT_PATH .'/';
647
+ $target_other_root = 'wp-content-other';
648
+
649
+ $this->logger->log_info(__METHOD__,'IGNORE:');
650
+ $this->logger->log($ignore);
651
+
652
+ //Validate the other folders
653
+ foreach(glob($wpcontent_path. '*',GLOB_ONLYDIR ) as $dir){
654
+ if( ! in_array(basename($dir), $ignore)){
655
+ $source_other_folder = $dir . '/';
656
+ $target_other_folder = $target_other_root . '/' . basename( $dir );
657
+
658
+ if(! $zip->validate_folder($source_other_folder, $target_other_folder)) {
659
+ $this->logger->log_error(__METHOD__,'Other Validation:FAIL - ' .basename( $dir ));
660
+ }else{
661
+ $this->logger->log_info(__METHOD__,'Other Validation:SUCCESS - '.basename( $dir ));
662
+ }
663
+ }
664
+ }
665
+
666
+ //Validate the other files
667
+ $files = array_filter(glob($wpcontent_path. '*'), 'is_file');
668
+ $file_validation=true;
669
+ foreach ($files as $file){
670
+ $target_other_file = $target_other_root . '/' . basename( $file );
671
+ if (false===$zip->validate_file($target_other_file)){
672
+ $this->logger->log_error(__METHOD__,'DIFF File:' .$target_other_file);
673
+ $file_validation=false;
674
+ };
675
+ }
676
+
677
+ // Write the other file validation results
678
+ if(! $file_validation) {
679
+ $this->logger->log_error(__METHOD__,'Other File Validation:FAIL');
680
+ }else{
681
+ $this->logger->log_info(__METHOD__,'Other File Validation:SUCCESS');
682
+ }
683
+
684
+ $this->logger->log_info(__METHOD__,'End - Validate backup');
685
+ return true;
686
  }
687
+
688
+ public function finalize_zip_file() {
689
+ $this->logger->log_info(__METHOD__,'Begin - Finalize the zip.');
690
+
691
+ $zip_file_path = $this->backup_folder_root . $this->backup_filename;
692
+ $new_zip_name = str_replace('.tmp','.zip',$zip_file_path);
693
+
694
+ $file_system = new WPBackItUp_FileSystem($this->logger);
695
+ if (! $file_system->rename_file($zip_file_path,$new_zip_name)){
696
+ $this->logger->log_error(__METHOD__,'Zip could not be finalized.');
697
+ return false;
698
+ }
699
+
700
+ //Change the file name property moving forward
701
+ $this->set_zip_extension();
702
+
703
+ $this->logger->log_info(__METHOD__,'End - Zip Finalized successfully.');
704
+ return true;
705
+ }
706
+
707
+ //Set zip extension to zip
708
+ public function set_zip_extension() {
709
+ $this->logger->log_info(__METHOD__,'Begin - change zip extension to zip');
710
+
711
+ $this->backup_filename = substr_replace($this->backup_filename, '.zip', -4);
712
+ //$this->backup_filename=str_replace('.tmp','.zip',$this->backup_filename);
713
+
714
+ $this->logger->log_info(__METHOD__,'End - Zip extension changed:' . $this->backup_filename);
715
+
716
+ }
717
+
718
+
719
  }
lib/includes/class-filesystem.php CHANGED
@@ -48,10 +48,10 @@ class WPBackItUp_FileSystem {
48
 
49
  if( is_dir($dir) ){
50
  //Make sure the folder is not in the ignore array
51
- if (!$this->ignore($dir,$ignore)){
52
  if($dh = opendir($dir)) {
53
  while( ($file = readdir($dh)) !== false ) {
54
- if (!$this->ignore($file,$ignore)) { //Check the file is not in the ignore array
55
  if(!is_dir($dir .'/'. $file)) {
56
  unlink($dir .'/'. $file); //delete the file
57
  $this->logger->log('(FileSytem.recursive_delete) File Deleted:' .$dir .'/'. $file);
@@ -197,6 +197,23 @@ class WPBackItUp_FileSystem {
197
  return false;
198
  }
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  //Check for backup folders
201
  private function is_backup_folder($dir){
202
  if (
@@ -323,7 +340,7 @@ class WPBackItUp_FileSystem {
323
  return true;
324
  }
325
 
326
- function get_file_handle($path,$newFile) {
327
  $this->logger->log('(FileSytem.get_file_handle) Path:' . $path);
328
 
329
  try {
@@ -353,5 +370,72 @@ class WPBackItUp_FileSystem {
353
  }
354
  }
355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
  }
48
 
49
  if( is_dir($dir) ){
50
  //Make sure the folder is not in the ignore array
51
+ if (!$this->delete_ignore($dir,$ignore)){
52
  if($dh = opendir($dir)) {
53
  while( ($file = readdir($dh)) !== false ) {
54
+ if (!$this->delete_ignore($file,$ignore)) { //Check the file is not in the ignore array
55
  if(!is_dir($dir .'/'. $file)) {
56
  unlink($dir .'/'. $file); //delete the file
57
  $this->logger->log('(FileSytem.recursive_delete) File Deleted:' .$dir .'/'. $file);
197
  return false;
198
  }
199
 
200
+ private function delete_ignore($file, $ignoreList){
201
+
202
+ //Exclude these files and folders from the delete
203
+ if (in_array(basename($file), $ignoreList) ||
204
+ //substr($file, 0, 1) == '.' ||
205
+ ($file == "." ) ||
206
+ ($file == ".." ))
207
+ //($file == "._" )
208
+ //($file == "cgi-bin" ))
209
+ {
210
+ //$this->logger->log('(FileSystem.ignore) IGNORE:'.$file);
211
+ return true;
212
+ }
213
+
214
+ return false;
215
+ }
216
+
217
  //Check for backup folders
218
  private function is_backup_folder($dir){
219
  if (
340
  return true;
341
  }
342
 
343
+ function get_file_handle($path,$newFile=false) {
344
  $this->logger->log('(FileSytem.get_file_handle) Path:' . $path);
345
 
346
  try {
370
  }
371
  }
372
 
373
+ /**
374
+ * Copy single file
375
+ * @param $from_file
376
+ * @param $to_file
377
+ *
378
+ * @return bool
379
+ */
380
+ function copy_file($from_file,$to_file) {
381
+ $this->logger->log('(FileSystem.copy_file) FROM Path:' . $from_file);
382
+ $this->logger->log('(FileSystem.copy_file) TO Path:' . $to_file);
383
+
384
+ try {
385
+ if (file_exists($from_file)){
386
+ if (copy($from_file,$to_file)){
387
+ $this->logger->log('(FileSystem.copy_file) File copied successfully.');
388
+ return true;
389
+ }
390
+ else{
391
+ $this->logger->log('(FileSystem.copy_file) File could not be copied:');
392
+ $this->logger->log(error_get_last());
393
+ return false;
394
+ }
395
+ }
396
+ else{
397
+ $this->logger->log('(FileSystem.copy_file) FROM File doesnt exist');
398
+ return false;
399
+ }
400
+
401
+ } catch(Exception $e) {
402
+ $this->logger->log('(FileSystem.copy_file) Exception:' . $e);
403
+ return false;
404
+ }
405
+ }
406
+
407
+ /**
408
+ * Rename single file
409
+ * @param $from_file
410
+ * @param $to_file_name
411
+ *
412
+ * @return bool
413
+ */
414
+ function rename_file($from_file,$to_file_name) {
415
+ $this->logger->log_info(__METHOD__,' FROM Path:' . $from_file);
416
+ $this->logger->log_info(__METHOD__,' TO Path:' . $to_file_name);
417
+
418
+ try {
419
+ if (file_exists($from_file)){
420
+ if (rename($from_file,$to_file_name)){
421
+ $this->logger->log_info(__METHOD__,'File renamed successfully.');
422
+ return true;
423
+ }
424
+ else{
425
+ $this->logger->log_error(__METHOD__,'File could not be copied:');
426
+ $this->logger->log(error_get_last());
427
+ return false;
428
+ }
429
+ }
430
+ else{
431
+ $this->logger->log_error(__METHOD__,'FROM File doesnt exist');
432
+ return false;
433
+ }
434
+
435
+ } catch(Exception $e) {
436
+ $this->logger->log_error(__METHOD__,' Exception:' . $e);
437
+ return false;
438
+ }
439
+ }
440
 
441
  }
lib/includes/class-job.php ADDED
@@ -0,0 +1,660 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!defined ('ABSPATH')) die('No direct access allowed');
2
+
3
+
4
+
5
+ class WPBackItUp_Job {
6
+
7
+ const JOB_TITLE='wpbackitup_job';
8
+
9
+ private $logger;
10
+ private $job_id;
11
+ private $allocated_task;
12
+
13
+ public $job_status;
14
+ public $backup_id;
15
+
16
+ private $job_start_time;
17
+ private $job_end_time;
18
+
19
+ static private $backup_tasks = array(
20
+ 1=>'cleanup_prev',
21
+ 2=>'backup_db' ,
22
+ 3=>'backup_siteinfo',
23
+ 4=>'backup_themes',
24
+ 5=>'backup_plugins',
25
+ 6=>'backup_uploads',
26
+ 7=>'backup_other',
27
+ 8=>'finalize_backup',
28
+ 9=>'validate_backup',
29
+ 10=>'cleanup_current'
30
+ );
31
+
32
+ static private $cleanup_tasks = array(
33
+ 1=>'scheduled_cleanup'
34
+ );
35
+
36
+ function __construct($job) {
37
+ try {
38
+ $this->logger = new WPBackItUp_Logger(false,null,'debug_job');
39
+
40
+ //Load of the class properties from the post object(see wp_post)
41
+ $this->job_id=$job->ID;
42
+ $this->job_status=$job->post_status;
43
+ $this->backup_id=$job->post_name;
44
+
45
+ //Deserialize content
46
+ $content = $job->post_content;
47
+ if (!empty($content)){
48
+ $job_info =maybe_unserialize($content);
49
+ if (is_array($job_info)){
50
+ $this->job_start_time=$job_info['start_time'];
51
+ }
52
+ }
53
+
54
+ } catch(Exception $e) {
55
+ error_log($e); //Log to debug
56
+ }
57
+ }
58
+
59
+ function __destruct() {
60
+
61
+ }
62
+
63
+ public function is_job_complete() {
64
+ $this->logger->log_info( __METHOD__, 'Begin' );
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
+
71
+ //Get Task Properties
72
+ $task_id = $task[0]['task_id'];
73
+ $task_status = $task[0]['task_status'];
74
+ $task_allocated_id = $task[0]['task_allocated_id'];
75
+ $task_last_updated = $task[0]['task_last_updated'];
76
+
77
+ if ('queued'==$task_status || 'active'==$task_status){
78
+ $this->logger->log_info( __METHOD__, 'Active or Queued Task found:' . $key );
79
+ return false;
80
+ }
81
+ }
82
+
83
+ //No active or queued tasks were found
84
+ $this->logger->log_info( __METHOD__, 'End - No Active or Queued Tasks found' );
85
+ return true;
86
+
87
+ }
88
+ //What is the next task in the stack
89
+ public function get_next_task(){
90
+ $this->logger->log_info(__METHOD__,'Begin');
91
+
92
+ $this->allocated_task=null; //Set the current task to null;
93
+
94
+ //Get the tasks -- DO I NEED TO SORT?
95
+ $tasks = get_post_meta($this->job_id);
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
102
+ $task_id = $task[0]['task_id'];
103
+ $task_status = $task[0]['task_status'];
104
+ $task_allocated_id = $task[0]['task_allocated_id'];
105
+ $task_last_updated = $task[0]['task_last_updated'];
106
+
107
+ //if next job in stack is queued then its time to get to work
108
+ switch ($task_status) {
109
+ case "queued":
110
+ //Try allocate task
111
+ $queued_task = $this->allocate_task($this->job_id, $key,$task_id);
112
+ return $queued_task[0]['task_id'];
113
+
114
+ case "active":
115
+ //Error if >= 3 minutes since the last update
116
+ if (time()>=$task_last_updated+WPBACKITUP__TASK_TIMEOUT_SECONDS){
117
+ $this->update_task_status($this->job_id, $key,$task_id,'error');
118
+
119
+ //Update job to error also
120
+ $this->set_job_status_error();
121
+ return 'error_' . $task_id ;
122
+
123
+ }else {
124
+
125
+ $this->logger->log_info( __METHOD__, 'Job:' . $key . ' is still active' );
126
+ //if its been less than 3 minutes then wait
127
+ return false;
128
+ }
129
+
130
+ case "complete":
131
+ //Do nothing - get the next task
132
+ break;
133
+
134
+ case "error":
135
+ //Job should already be error but update if not
136
+ //Update job to error also
137
+ $this->set_job_status_error();
138
+ return 'error_' . $task_id ;
139
+ }
140
+ }
141
+
142
+ //If no more tasks then job must be done
143
+ $this->set_job_status_complete();
144
+
145
+ $this->logger->log_info(__METHOD__,'End - no tasks to allocate');
146
+ return false; //no tasks to allocate
147
+ }
148
+
149
+ /**
150
+ * Allocate the task to this job - will set task status to active
151
+ *
152
+ * @param $job_id
153
+ * @param $key
154
+ * @param $task_id
155
+ *
156
+ * @return bool
157
+ */
158
+ private function allocate_task($job_id, $key,$task_id){
159
+ $this->logger->log_info(__METHOD__,'Begin');
160
+
161
+ //Allocate the task to this process
162
+ $process_uid = uniqid();
163
+ $this->update_task_status($job_id, $key,$task_id,'active',$process_uid);
164
+
165
+ //Get updated task and make sure uid is good
166
+ $updated_task = get_post_meta( $this->job_id, $key);
167
+ $updated_task_allocated_id = $updated_task[0]['task_allocated_id'];
168
+ if ($process_uid==$updated_task_allocated_id) {
169
+ $this->allocated_task=$updated_task; // set the jobs allocated task
170
+
171
+ $this->logger->log_info(__METHOD__,'End - Task allocated');
172
+ return $updated_task;
173
+ }else{
174
+ $this->allocated_task=null;
175
+ $this->logger->log_info(__METHOD__,'End - Task was not allocated');
176
+ return false;
177
+ }
178
+ }
179
+
180
+
181
+ /**
182
+ * Set the allocated task status to queued
183
+ */
184
+ public function set_task_queued(){
185
+ $this->logger->log_info(__METHOD__,'Begin');
186
+
187
+ $this->logger->log_info(__METHOD__, 'Task Info:');
188
+ $this->logger->log($this->allocated_task);
189
+
190
+ //Get allocated task Properties
191
+ $task_id = $this->allocated_task[0]['task_id'];
192
+ $this->update_task_status($this->job_id, $task_id,$task_id,'queued');
193
+
194
+ $this->logger->log_info(__METHOD__,'End');
195
+ }
196
+
197
+ /**
198
+ * Set the allocated task status to complete
199
+ */
200
+ public function set_task_complete(){
201
+ $this->logger->log_info(__METHOD__,'Begin');
202
+
203
+ $this->logger->log_info(__METHOD__, 'Task Info:');
204
+ $this->logger->log($this->allocated_task);
205
+
206
+ //Get allocated task Properties
207
+ $task_id = $this->allocated_task[0]['task_id'];
208
+ $this->update_task_status($this->job_id, $task_id,$task_id,'complete');
209
+
210
+
211
+ //Check if this was the last task
212
+ if ($this->is_job_complete()){
213
+ $this->set_job_status_complete();
214
+ }
215
+
216
+ $this->logger->log_info(__METHOD__,'End');
217
+ }
218
+
219
+ /**
220
+ * Set the allocated task status to error
221
+ */
222
+ public function set_task_error($error_code){
223
+ $this->logger->log_info(__METHOD__,'Begin');
224
+
225
+ $this->logger->log_info(__METHOD__, 'Task Info:');
226
+ $this->logger->log($this->allocated_task);
227
+
228
+ //Get allocated task Properties
229
+ $task_id = $this->allocated_task[0]['task_id'];
230
+ $this->update_task_status($this->job_id, $task_id,$task_id,'error','',$error_code);
231
+
232
+ $this->set_job_status_error();
233
+
234
+ $this->logger->log_info(__METHOD__,'End');
235
+ }
236
+
237
+
238
+ private function update_task_status($job_id,$task_name,$task_id, $task_status, $task_allocated_id='', $task_error_code=''){
239
+ $this->logger->log_info(__METHOD__,'Begin');
240
+
241
+ $meta_value = array(
242
+ 'task_id' => $task_id,
243
+ 'task_status' => $task_status,
244
+ 'task_allocated_id' => $task_allocated_id,
245
+ 'task_error_code' => $task_error_code,
246
+ 'task_last_updated' => time()
247
+ );
248
+
249
+ $this->logger->log_info(__METHOD__,'End - Task Updated:' .$job_id .'-'. $task_name .'-'. $task_status);
250
+ return update_post_meta( $job_id, $task_name, $meta_value );
251
+ }
252
+
253
+
254
+ /**
255
+ * Set job status to active
256
+ */
257
+ public function set_job_status_active( ) {
258
+ $status='active';
259
+ if ($this->update_job_status($status)){
260
+ $this->job_status = $status;
261
+ }
262
+
263
+ //Set job end Time
264
+ $this->set_job_start_time();
265
+ }
266
+
267
+ /**
268
+ * Set job status to error
269
+ */
270
+ public function set_job_status_error( ) {
271
+ $status='error';
272
+ if ($this->update_job_status($status)){
273
+ $this->job_status = $status;
274
+ }
275
+
276
+ //Set job end Time
277
+ $this->set_job_end_time();
278
+ }
279
+
280
+ /**
281
+ * Set job status to complete
282
+ */
283
+ public function set_job_status_complete( ) {
284
+ $status='complete';
285
+
286
+ if ($this->update_job_status($status)){
287
+ $this->job_status = $status;
288
+ }
289
+
290
+ //Set job end Time
291
+ $this->set_job_end_time();
292
+ }
293
+
294
+ /**
295
+ * Set job status to cancelled
296
+ */
297
+ public function set_job_status_cancelled( ) {
298
+ $status='cancelled';
299
+
300
+ if ($this->update_job_status($status)){
301
+ $this->job_status = $status;
302
+ }
303
+
304
+ //Set job end Time
305
+ $this->set_job_end_time();
306
+ }
307
+
308
+
309
+ /**
310
+ * Update job status
311
+ *
312
+ * @param $status
313
+ *
314
+ * @return bool
315
+ */
316
+ private function update_job_status($status) {
317
+ $this->logger->log_info(__METHOD__,'Begin');
318
+
319
+ $job = array(
320
+ 'ID' => $this->job_id,
321
+ 'post_status' => $status
322
+ );
323
+
324
+ // update the job
325
+ $job_id = wp_update_post($job );
326
+
327
+ if (0!=$job_id) {
328
+ $this->logger->log_info(__METHOD__,'End - Backup Job status set to:' .$job_id .'-' . $status );
329
+ return true;
330
+ } else{
331
+ $this->logger->log_error(__METHOD__,'End - Backup Job status NOT set.');
332
+ return false;
333
+ }
334
+
335
+ }
336
+
337
+ /**
338
+ * Set job start time
339
+ *
340
+ * @return bool
341
+ */
342
+ private function set_job_start_time() {
343
+ $this->logger->log_info(__METHOD__,'Begin');
344
+
345
+ $this->job_start_time= time();
346
+ $job_info = array(
347
+ 'start_time' => $this->job_start_time,
348
+ );
349
+
350
+ $job = array(
351
+ 'ID' => $this->job_id,
352
+ 'post_content' => serialize($job_info)
353
+ );
354
+
355
+ // update the job info
356
+ $job_id = wp_update_post($job );
357
+
358
+ if (0!=$job_id) {
359
+ $this->logger->log_info(__METHOD__,'End - Backup Job start time set');
360
+ return true;
361
+ } else{
362
+ $this->logger->log_error(__METHOD__,'End - Backup Job start time NOT set.');
363
+ return false;
364
+ }
365
+
366
+ }
367
+
368
+ /**
369
+ * Set job end time
370
+ *
371
+ * @return bool
372
+ */
373
+ private function set_job_end_time() {
374
+ $this->logger->log_info(__METHOD__,'Begin');
375
+
376
+ $this->job_end_time=time();
377
+ $job_info = array(
378
+ 'start_time' => $this->job_start_time,
379
+ 'end_time' => $this->job_end_time,
380
+ );
381
+
382
+ $job = array(
383
+ 'ID' => $this->job_id,
384
+ 'post_content' => serialize($job_info)
385
+ );
386
+
387
+ // update the job info
388
+ $job_id = wp_update_post($job );
389
+
390
+ if (0!=$job_id) {
391
+ $this->logger->log_info(__METHOD__,'End - Backup Job end time set');
392
+ return true;
393
+ } else{
394
+ $this->logger->log_error(__METHOD__,'End - Backup Job end time NOT set.');
395
+ return false;
396
+ }
397
+
398
+ }
399
+
400
+ /**---------STATICS---------***/
401
+
402
+ /**
403
+ * Is there at least 1 job queued or active?
404
+ *
405
+ * @param $job_name
406
+ *
407
+ * @return bool
408
+ */
409
+ public static function is_job_queued($job_name) {
410
+ $logger = new WPBackItUp_Logger(false,null,'debug_job');
411
+ $logger->log_info(__METHOD__,'Begin - Check Job Queue:' . $job_name);
412
+
413
+ //Get top 1
414
+ $args = array(
415
+ 'posts_per_page' => 1,
416
+ 'post_type' => $job_name,
417
+ 'post_status' => array('queued','active'),
418
+ 'orderby' => 'post_date',
419
+ 'order' => 'ASC',
420
+ 'suppress_filters' => true
421
+ );
422
+ $jobs = get_posts( $args );
423
+ $logger->log($jobs);
424
+
425
+ if (is_array($jobs) && count($jobs)>0) {
426
+ $logger->log_info(__METHOD__,'Jobs found:' . count($jobs) );
427
+ return true;
428
+ }
429
+
430
+ $logger->log_info(__METHOD__,'No jobs found:' . $job_name);
431
+ $logger->log_info(__METHOD__,'End');
432
+ return false;
433
+ }
434
+
435
+ /**
436
+ * Cancel all queued or active jobs
437
+ *
438
+ * @return bool
439
+ */
440
+ public static function cancel_all_jobs() {
441
+ $logger = new WPBackItUp_Logger(false,null,'debug_job');
442
+ $logger->log_info(__METHOD__,'Begin - Cancel all jobs.');
443
+
444
+
445
+ while (self::is_job_queued('backup')){
446
+ $backup_job = self::get_job('backup');
447
+ if (false!== $backup_job) {
448
+ $backup_job->set_job_status_cancelled();
449
+ $logger->log_info(__METHOD__,'Backup job Cancelled:' . $backup_job->job_id);
450
+ }
451
+ }
452
+
453
+ while (self::is_job_queued('cleanup')){
454
+ $cleanup_job = self::get_job('cleanup');
455
+ if (false!== $cleanup_job) {
456
+ $cleanup_job->set_job_status_cancelled();
457
+ $logger->log_info(__METHOD__,'Cleanup job Cancelled:' . $cleanup_job->job_id);
458
+ }
459
+ }
460
+
461
+ $logger->log_info(__METHOD__,'End - All jobs cancelled');
462
+ }
463
+
464
+ /**
465
+ * Gets the queued or active job on top of the stack
466
+ *
467
+ * @param $job_name
468
+ *
469
+ * @return bool|WPBackItUp_Job
470
+ */
471
+ public static function get_job($job_name) {
472
+ $logger = new WPBackItUp_Logger(false,null,'debug_job');
473
+ $logger->log_info(__METHOD__,'Begin - Job Name: ' .$job_name);
474
+
475
+ //Get backup on top
476
+ $args = array(
477
+ 'posts_per_page' => 1,
478
+ 'post_type' => $job_name,
479
+ 'post_status' => array('queued','active'),
480
+ 'orderby' => 'post_date',
481
+ 'order' => 'ASC',
482
+ );
483
+ $jobs = get_posts( $args );
484
+ $logger->log($jobs);
485
+
486
+ if (is_array($jobs) && count($jobs)>0) {
487
+ $logger->log_info(__METHOD__,'Job found:' . count($jobs));
488
+
489
+ $backup_job = new WPBackItUp_Job($jobs[0]);
490
+ if ('queued'==$backup_job->job_status){
491
+ $backup_job->set_job_status_active();
492
+ }
493
+ return $backup_job;
494
+ }
495
+
496
+ $logger->log_info(__METHOD__,'No jobs found.');
497
+ $logger->log_info(__METHOD__,'End');
498
+ return false;
499
+ }
500
+
501
+ /**
502
+ * Gets a job by id
503
+ *
504
+ * @param $id
505
+ *
506
+ * @return bool|WPBackItUp_Job
507
+ */
508
+ public static function get_job_by_id($id) {
509
+ $logger = new WPBackItUp_Logger(false,null,'debug_job');
510
+ $logger->log_info(__METHOD__,'Begin');
511
+
512
+ $job = get_post( $id, 'OBJECT');
513
+ $logger->log($job);
514
+
515
+ if (null!=$job) {
516
+ $logger->log_info(__METHOD__,'Job found:' .$id);
517
+ return new WPBackItUp_Job($job);
518
+ }
519
+
520
+ $logger->log_info(__METHOD__,'No job found with id.' . $id);
521
+ $logger->log_info(__METHOD__,'End');
522
+ return false;
523
+ }
524
+
525
+ /**
526
+ * Queue a job
527
+ *
528
+ * @param $job_name
529
+ *
530
+ * @return bool|WPBackItUp_Job
531
+ */
532
+ public static function queue_job($job_name){
533
+ $logger = new WPBackItUp_Logger(false,null,'debug_job');
534
+ $logger->log_info(__METHOD__,'Begin - Job:'. $job_name);
535
+
536
+ $new_job = array(
537
+ 'post_title' => self::JOB_TITLE,
538
+ 'post_name' => time(),
539
+ 'post_status' => 'queued',
540
+ 'post_type' => $job_name
541
+ );
542
+
543
+ // Insert the post into the database
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::create_backup_tasks( $job_id ) ) {
552
+ $logger->log_info( __METHOD__, 'Backup tasks not Created - deleting job:' . $job_id );
553
+ wp_delete_post( $job_id, true );
554
+ return false;
555
+ }
556
+
557
+ break;
558
+
559
+ case "cleanup":
560
+ //add the tasks
561
+ if ( false === self::create_cleanup_tasks( $job_id ) ) {
562
+ $logger->log_info( __METHOD__, 'Cleanup tasks not Created - deleting job:' . $job_id );
563
+ wp_delete_post( $job_id, true );
564
+ return false;
565
+ }
566
+ break;
567
+
568
+ default://Job type not defined
569
+ $logger->log_info( __METHOD__, 'Job type not defined - deleting job:' . $job_name );
570
+ wp_delete_post( $job_id, true );
571
+ return false;
572
+ }
573
+
574
+ $logger->log_info(__METHOD__,'End');
575
+ return self::get_job_by_id($job_id);
576
+ }
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 create_cleanup_tasks($job_id){
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 (self::$cleanup_tasks as $key => $value){
625
+ $task_name = $value;
626
+ $task_data = array(
627
+ 'task_id' => $task_name,
628
+ 'task_status' => 'queued',
629
+ 'task_allocated_id'=>'',
630
+ 'task_last_updated'=>$last_updated_time
631
+ );
632
+ $task_created = update_post_meta( $job_id, $task_name, $task_data );
633
+
634
+ if (false===$task_created){
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');
642
+ return true;
643
+
644
+ }
645
+
646
+ /**
647
+ * @return mixed
648
+ */
649
+ public function get_job_start_time() {
650
+ return $this->job_start_time;
651
+ }
652
+
653
+ /**
654
+ * @return mixed
655
+ */
656
+ public function get_job_end_time() {
657
+ return $this->job_end_time;
658
+ }
659
+ }
660
+
lib/includes/class-logger.php CHANGED
@@ -78,7 +78,7 @@ class WPBackItUp_Logger {
78
  try{
79
  if (true===$this->logging){
80
  if (!is_null($this->dfh) && is_resource($this->dfh)){
81
- $date = date_i18n('Y-m-d Hi:i:s',current_time( 'timestamp' ));
82
  if( is_array( $message ) || is_object( $message ) ){
83
  fwrite($this->dfh, $date ." " .print_r( $message, true ) . PHP_EOL);
84
  } else {
@@ -114,21 +114,83 @@ class WPBackItUp_Logger {
114
  }
115
  }
116
 
117
- function logConstants() {
118
- global $WPBackitup;
119
  try{
120
- if (true===$this->logging){
121
- $this->log("**SYSTEM CONSTANTS**");
122
-
 
 
 
 
 
 
 
123
  $this->log("Wordpress Version:" . get_bloginfo( 'version'));
124
- $this->log("PHP Version:" . phpversion());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  $this->log("Operating System:" . php_uname());
126
- $this->log("Safe Mode:" . (ini_get('safe_mode') ? 'true' : 'false'));
127
- $this->log("Script Max Execution Time:" . ini_get('max_execution_time'));
128
- $this->log("WPBackItUp License Active: " . ($WPBackitup->license_active() ? 'true' : 'false'));
129
 
130
- $this->log("**WPBACKITUP CONSTANTS**");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
 
 
132
  $prefix='WPBACKITUP';
133
  foreach (get_defined_constants() as $key=>$value)
134
  {
@@ -136,7 +198,7 @@ class WPBackItUp_Logger {
136
  $this->log($key . ':' . $value);
137
  }
138
  }
139
- $this->log("**END CONSTANTS**");
140
  }
141
  } catch(Exception $e) {
142
  //Dont do anything
78
  try{
79
  if (true===$this->logging){
80
  if (!is_null($this->dfh) && is_resource($this->dfh)){
81
+ $date = date_i18n('Y-m-d H:i:s',current_time( 'timestamp' ));
82
  if( is_array( $message ) || is_object( $message ) ){
83
  fwrite($this->dfh, $date ." " .print_r( $message, true ) . PHP_EOL);
84
  } else {
114
  }
115
  }
116
 
117
+ function log_sysinfo() {
118
+ global $wpdb,$WPBackitup;
119
  try{
120
+ if (true===$this->logging){
121
+
122
+ $this->log("**SYSTEM INFO**");
123
+
124
+ $this->log("\n--Site Info--");
125
+ $this->log('Site URL:' . site_url());
126
+ $this->log('Home URL:' . home_url());
127
+ $this->log('Multisite:' . ( is_multisite() ? 'Yes' : 'No' )) ;
128
+
129
+ $this->log("\n--Wordpress Info--");
130
  $this->log("Wordpress Version:" . get_bloginfo( 'version'));
131
+ $this->log('Language:' . ( defined( 'WPLANG' ) && WPLANG ? WPLANG : 'en_US' ));
132
+ $this->log('Table Prefix:' . 'Length: ' . strlen( $wpdb->prefix ) . ' Status: ' . ( strlen( $wpdb->prefix ) > 16 ? 'ERROR: Too long' : 'Acceptable' ));
133
+ $this->log('WP_DEBUG:' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ));
134
+ $this->log('Memory Limit:' . WP_MEMORY_LIMIT );
135
+
136
+
137
+ $this->log("\n--WordPress Active Plugins--");
138
+ // Check if get_plugins() function exists. This is required on the front end of the
139
+ // site, since it is in a file that is normally only loaded in the admin.
140
+ if ( ! function_exists( 'get_plugins' ) ) {
141
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
142
+ }
143
+
144
+ $plugins = get_plugins();
145
+ $active_plugins = get_option( 'active_plugins', array() );
146
+ foreach( $plugins as $plugin_path => $plugin ) {
147
+ if( !in_array( $plugin_path, $active_plugins ) ) continue;
148
+
149
+ $this->log( $plugin['Name'] . ': ' . $plugin['Version']);
150
+ }
151
+
152
+ // WordPress inactive plugins
153
+ $this->log("\n" . '--WordPress Inactive Plugins--');
154
+
155
+ foreach( $plugins as $plugin_path => $plugin ) {
156
+ if( in_array( $plugin_path, $active_plugins ) )
157
+ continue;
158
+
159
+ $this->log($plugin['Name'] . ': ' . $plugin['Version']);
160
+ }
161
+
162
+ $this->log("\n--Server Info--");
163
+ $this->log('PHP Version:' . PHP_VERSION);
164
+ $this->log('Webserver Info:' . $_SERVER['SERVER_SOFTWARE']);
165
+ $this->log('MySQL Version:' . $wpdb->db_version());
166
+
167
+
168
+ $this->log("\n--PHP Info--");
169
+ $this->log("PHP Info:" . phpversion());
170
  $this->log("Operating System:" . php_uname());
 
 
 
171
 
172
+ if ( @ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on' ){
173
+ $this->log("PHP Safe Mode: On");
174
+ } else{
175
+ $this->log("PHP Safe Mode: Off");
176
+ }
177
+
178
+ if ( @ini_get('sql.safe_mode') || strtolower(@ini_get('sql.safe_mode')) == 'on' ){
179
+ $this->log("SQL Safe Mode: On");
180
+ } else{
181
+ $this->log("SQL Safe Mode: Off");
182
+ }
183
+ $this->log("Script Max Execution Time:" . ini_get('max_execution_time'));
184
+ $this->log('Memory Limit:' . ini_get( 'memory_limit' ));
185
+ $this->log('Upload Max Size:' . ini_get( 'upload_max_filesize' ));
186
+ $this->log('Post Max Size:' . ini_get( 'post_max_size' ));
187
+ $this->log('Upload Max Filesize:' . ini_get( 'upload_max_filesize' ));
188
+ $this->log('Max Input Vars:' . ini_get( 'max_input_vars' ));
189
+ $this->log('Display Errors:' . ( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' ));
190
+
191
 
192
+ $this->log("\n--WP BackItUp Info--");
193
+ $this->log("WPBACKITUP License Active: " . ($WPBackitup->license_active() ? 'true' : 'false'));
194
  $prefix='WPBACKITUP';
195
  foreach (get_defined_constants() as $key=>$value)
196
  {
198
  $this->log($key . ':' . $value);
199
  }
200
  }
201
+ $this->log("**END SYSTEM INFO**");
202
  }
203
  } catch(Exception $e) {
204
  //Dont do anything
lib/includes/class-scheduler.php CHANGED
@@ -18,7 +18,7 @@ class WPBackItUp_Scheduler {
18
  */
19
  function __construct() {
20
 
21
- $this->logger = new WPBackItUp_Logger(false,null,'task_scheduler');
22
 
23
  }
24
 
@@ -86,7 +86,7 @@ class WPBackItUp_Scheduler {
86
 
87
  $lastrun_date = date("Ymd",$lastrun_datetime);
88
  $lastrun_dow =0;//0=none
89
- if ($lastrun_datetime!=2147483648){// 1901-12-13:never run
90
  $lastrun_dow = date("N",$lastrun_datetime);
91
  }
92
 
@@ -138,14 +138,19 @@ class WPBackItUp_Scheduler {
138
  $lastrun_date = date("Ymd",$lastrun_datetime);
139
  $this->logger->log('Last Run Date Time:' . date( 'Y-m-d H:i:s',$lastrun_datetime));
140
 
141
- //Did cleanup already run today
142
- if ($current_date==$lastrun_date){
143
- $this->logger->log('Cleanup already ran today');
144
- return false;
 
 
 
 
 
145
  }
146
 
147
- $this->logger->log('Cleanup should be run now.');
148
- return true;
149
 
150
  }catch(Exception $e) {
151
  $this->logger->log_error(__METHOD__,'Exception: ' .$e);
18
  */
19
  function __construct() {
20
 
21
+ $this->logger = new WPBackItUp_Logger(false,null,'debug_scheduler');
22
 
23
  }
24
 
86
 
87
  $lastrun_date = date("Ymd",$lastrun_datetime);
88
  $lastrun_dow =0;//0=none
89
+ if ($lastrun_datetime!=-2147483648){// 1901-12-13:never run
90
  $lastrun_dow = date("N",$lastrun_datetime);
91
  }
92
 
138
  $lastrun_date = date("Ymd",$lastrun_datetime);
139
  $this->logger->log('Last Run Date Time:' . date( 'Y-m-d H:i:s',$lastrun_datetime));
140
 
141
+ //Has it been at least an hour since the last cleanup?
142
+
143
+ $next_run_datetime=$lastrun_datetime+3600; //1 hour
144
+ $this->logger->log('Next Run Date Time:' . date( 'Y-m-d H:i:s',$next_run_datetime));
145
+
146
+ $this->logger->log('TimeToRun:' . $current_datetime . ':'.$next_run_datetime );
147
+ if ($current_datetime>=$next_run_datetime){
148
+ $this->logger->log('Cleanup should be run now.');
149
+ return true;
150
  }
151
 
152
+ $this->logger->log('Not yet time to run Cleanup.');
153
+ return false;
154
 
155
  }catch(Exception $e) {
156
  $this->logger->log_error(__METHOD__,'Exception: ' .$e);
lib/includes/class-utility.php CHANGED
@@ -67,5 +67,12 @@ class WPBackItUp_Utility {
67
 
68
  return $date_diff_seconds;
69
  }
70
- }
 
 
 
 
 
 
 
71
 
67
 
68
  return $date_diff_seconds;
69
  }
70
+
71
+ function timestamp_diff_seconds($timestamp1,$timestamp2 ){
72
+ // get a difference represented as an int, number of seconds
73
+ $timestamp_diff_seconds = abs($timestamp1 - $timestamp2);
74
+
75
+ return $timestamp_diff_seconds;
76
+ }
77
+ }
78
 
lib/includes/class-wpbackitup-admin.php CHANGED
@@ -34,7 +34,7 @@ class WPBackitup_Admin {
34
  private $backup_count; //getter will load
35
  private $successful_backup_count;
36
 
37
- public $backup_type;
38
 
39
 
40
  // Default plugin options
@@ -52,12 +52,14 @@ class WPBackitup_Admin {
52
  'backup_retained_number' => "3",
53
  'lite_backup_retained_number' => "1",
54
  'lite_registration_email' => "",
 
55
  'backup_count'=>0,
56
  'successful_backup_count'=>0,
57
  'stats_last_check_date'=> "1970-01-01 00:00:00",
58
  'backup_schedule'=>"",
59
- 'backup_lastrun_date'=>"2147483648",
60
- 'cleanup_lastrun_date'=>"2147483648",
 
61
  );
62
 
63
 
@@ -66,7 +68,6 @@ class WPBackitup_Admin {
66
  */
67
  public static function get_instance() {
68
  if ( ! self::$instance ) {
69
- // echo('new instance');
70
  self::$instance = new self();
71
  }
72
 
@@ -105,10 +106,10 @@ class WPBackitup_Admin {
105
  add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
106
 
107
  //Load all the resources
108
- add_action( 'admin_enqueue_scripts', array( &$this, 'load_resources' ) );
109
 
110
  //Load the backup action
111
- add_action('wp_ajax_wp-backitup_backup', array( &$this, 'ajax_backup' ));
112
 
113
  //Load the restore action
114
  add_action('wp_ajax_wp-backitup_restore', array( &$this, 'ajax_restore' ));
@@ -117,9 +118,11 @@ class WPBackitup_Admin {
117
  add_action('wp_ajax_wp-backitup_upload', array( &$this, 'ajax_upload' ));
118
 
119
  //Status reader for UI
120
- add_action('wp_ajax_wp-backitup_status_reader', array( &$this,'ajax_status_reader'));
121
 
122
- add_action('wp_ajax_wp-backitup_response_reader', array( &$this,'ajax_response_reader'));
 
 
123
 
124
  //Delete File Action
125
  add_action('wp_ajax_wp-backitup_delete_file', array( &$this,'ajax_delete_file'));
@@ -131,9 +134,12 @@ class WPBackitup_Admin {
131
  add_action('admin_post_nopriv_listlogs', array( &$this,'admin_listlogs'));
132
 
133
  //Create Daily backup action
134
- add_action( 'wpbackitup_check_scheduled_tasks', array( &$this,'wpbackitup_check_scheduled_tasks'));
 
 
 
 
135
 
136
- add_action( 'wpbackitup_resume_backup', array( &$this,'wpbackitup_resume_backup'));
137
  }
138
 
139
  /**
@@ -163,44 +169,28 @@ class WPBackitup_Admin {
163
  // remove duplicate submenu page. wp limitations //
164
  // http://wordpress.stackexchange.com/questions/16401/remove-duplicate-main-submenu-in-admin
165
  remove_submenu_page($this->namespace,$this->namespace);
166
-
167
- // Add print scripts and styles action based off the option page hook
168
- add_action( 'admin_print_scripts', array( &$this, 'admin_print_scripts' ) );
169
- add_action( 'admin_print_styles', array( &$this, 'admin_print_styles' ) );
170
- }
171
-
172
- /**
173
- * Load JavaScript for the admin options page
174
- *
175
- * @uses wp_enqueue_script()
176
- */
177
- public function admin_print_scripts() {
178
- wp_enqueue_script( "{$this->namespace}-admin" );
179
- wp_enqueue_script( "{$this->namespace}-admin-viewlog" );
180
 
181
  }
182
 
183
  public function load_resources() {
184
- // Admin JavaScript
185
- wp_register_script( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "js/wpbackitup_admin.js", array( 'jquery' ), $this->version, true );
186
- //wp_register_script( "{$this->namespace}-admin-viewlog", WPBACKITUP__PLUGIN_URL . "/js/admin_test.js", array( 'jquery' ), $this->version, true );
187
 
188
- // Admin Stylesheet
189
- wp_register_style( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "css/wpbackitup_admin.css", array(), $this->version, 'screen' );
190
 
191
- wp_register_style( 'google-fonts', '//netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.css');
192
- wp_enqueue_style( 'google-fonts' );
193
- }
194
 
195
- /**
196
- * Load Stylesheet for the admin options page
197
- *
198
- * @uses wp_enqueue_style()
199
- */
200
- public function admin_print_styles() {
201
- wp_enqueue_style( "{$this->namespace}-admin" );
 
202
  }
203
-
204
  /**
205
  * The admin section backup page rendering method
206
  *
@@ -312,41 +302,168 @@ class WPBackitup_Admin {
312
  $this->check_license();
313
  }
314
 
315
- public function wpbackitup_check_scheduled_tasks(){
316
 
317
- if( !class_exists( 'WPBackItUp_Scheduler' ) ) {
318
- include_once 'class-scheduler.php';
319
- }
 
320
 
321
- $scheduler = new WPBackItUp_Scheduler();
322
- if ($scheduler->isTaskScheduled('backup')){
323
- $this->backup_type='scheduled';
324
- include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/backup.php' );
325
- exit(0); //success - don't run anything else after a backup
326
- }
327
 
328
- if ($scheduler->isTaskScheduled('cleanup')){
329
- $this->backup_type='cleanup';
330
- include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/backup.php' );
331
- }
332
- }
333
 
334
- //Next Release
335
- function wpbackitup_resume_backup(){
 
 
 
336
 
337
- exit(0);
 
338
 
339
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
 
341
- //load backup
342
- public function ajax_backup() {
343
- $this->backup_type='manual';
344
- include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/backup.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  }
346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  //load restore
348
  public function ajax_restore() {
349
- include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/restore.php' );
350
  }
351
 
352
  //load upload
@@ -354,16 +471,10 @@ class WPBackitup_Admin {
354
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/upload.php' );
355
  }
356
 
357
- public function ajax_status_reader() {
358
- $log = WPBACKITUP__PLUGIN_PATH .'/logs/status.log';
359
- if(file_exists($log) ) {
360
- readfile($log);
361
- }
362
- exit;
363
- }
364
 
365
- public function ajax_response_reader() {
366
- $log = WPBACKITUP__PLUGIN_PATH .'/logs/response.log';
 
367
  if(file_exists($log) ) {
368
  readfile($log);
369
  }else{
@@ -436,16 +547,20 @@ class WPBackitup_Admin {
436
  //Could have just been a license update
437
  if(!empty($data)) {
438
 
 
 
439
  //Set back to original settings if value not changed
440
  if(!empty($data['backup_retained_number']) && !is_numeric($data['backup_retained_number']))
441
  {
442
  $data['backup_retained_number'] = $this->defaults['backup_retained_number'];
443
  set_transient('settings-error-number', __('Please enter a number', $this->namespace), 60);
 
444
  }
445
  else{ //Empty OR not NUMERIC
446
 
447
  //Empty
448
  if ( empty($data['backup_retained_number']) ){
 
449
  set_transient('settings-error-number', __('Please enter a number', $this->namespace), 60);
450
  }
451
 
@@ -463,12 +578,22 @@ class WPBackitup_Admin {
463
 
464
  }
465
 
 
466
  if(!empty($data['notification_email']) && !is_email($data['notification_email']))
467
  {
468
  $data['notification_email'] = $this->defaults['notification_email'];
469
  set_transient('settings-error-email', __('Please enter a a valid email', $this->namespace), 60);
470
  }
471
 
 
 
 
 
 
 
 
 
 
472
  // Update the options value with the data submitted
473
  foreach( $data as $key => $val ) {
474
  $this->set_option($key, $val);
@@ -503,8 +628,8 @@ class WPBackitup_Admin {
503
  $this->set_backup_schedule($days_selected);
504
 
505
  //Add backup scheduled if doesnt exist
506
- if(!wp_next_scheduled( 'wpbackitup_check_scheduled_tasks' ) ){
507
- wp_schedule_event( time()+3600, 'hourly', 'wpbackitup_check_scheduled_tasks');
508
  }
509
 
510
  return true;
@@ -527,7 +652,7 @@ class WPBackitup_Admin {
527
  * dealt with directly.
528
  */
529
 
530
- $logger = new WPBackItUp_Logger(false);
531
  $logger->log("Register WP BackItUp Lite");
532
  $logger->log($_POST);
533
 
@@ -536,53 +661,35 @@ class WPBackitup_Admin {
536
  if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)){
537
  $urlparts = parse_url(site_url());
538
  $domain = $urlparts['host'];
539
- $logger->log('Lite Registration Values: ' .$domain .':' .$email);
540
 
541
- //Not capturing these yet
542
- $first_name='';
543
- $last_name='';
544
 
545
- //save option to DB
546
  $this->set_option('lite_registration_email', $email);
547
-
548
- //register with mail chimp
549
- //$mailchimp_form_id = '5e70c18c53'; //DEV
550
- $mailchimp_form_id = '8e8e45c83b'; //PRD
551
-
552
- $url = WPBACKITUP__SECURESITE_URL; //PRD
553
- //$url="http://localhost/dev.wpbackitup.com"; //DEV
554
-
555
 
556
  $form_data = array(
557
- // '_wpnonce'=>'d0c887e966',
558
- // '_wp_http_referer'=>'/' .$url .'/test-newsletter-signup',
559
- 'yks-mailchimp-list-ct'=>'0',
560
- 'yks-mailchimp-list-id'=>$mailchimp_form_id,
561
- $mailchimp_form_id .'EMAIL' => $email,
562
- $mailchimp_form_id .'WEBSITE' => $domain,
563
- $mailchimp_form_id .'FNAME' => $first_name,
564
- $mailchimp_form_id .'LNAME' => $last_name
565
  );
566
 
567
- //URL Encode the Form Data
568
- $form_data=http_build_query($form_data);
569
- $post_url=$url . '/wp-admin/admin-ajax.php';
570
 
571
  $logger->log('Lite User Registration Post URL: ' .$post_url);
572
- $logger->log('Lite User Registration Post Form Data: ' .$form_data);
 
573
 
574
  $response = wp_remote_post( $post_url, array(
575
  'method' => 'POST',
576
  'timeout' => 45,
577
- 'redirection' => 5,
578
- 'httpversion' => '1.0',
579
  'blocking' => true,
580
  'headers' => array(),
581
- 'body' => array(
582
- 'action' => 'yks_mailchimp_form'
583
- , 'form_action' => 'frontend_submit_form'
584
- , 'form_data' => $form_data
585
- ),
586
  'cookies' => array()
587
  )
588
  );
@@ -694,6 +801,11 @@ class WPBackitup_Admin {
694
  return $this->get('cleanup_lastrun_date');
695
  }
696
 
 
 
 
 
 
697
 
698
  /**
699
  * Getter - license active - derived property
@@ -812,6 +924,10 @@ class WPBackitup_Admin {
812
  return $this->get('lite_registration_email');
813
  }
814
 
 
 
 
 
815
  function is_lite_registered(){
816
  $lite_email_registration= $this->lite_registration_email();
817
  if (!empty($lite_email_registration)) {
@@ -860,6 +976,10 @@ class WPBackitup_Admin {
860
  public function set_cleanup_lastrun_date($value){
861
  $this->set('cleanup_lastrun_date', $value);
862
  }
 
 
 
 
863
  /**---------- END SETTERS --------------- **/
864
 
865
 
@@ -926,10 +1046,20 @@ class WPBackitup_Admin {
926
  $api_params = array(
927
  'edd_action'=> 'activate_license',
928
  'license' => $license,
929
- 'item_name' => urlencode( WPBACKITUP__ITEM_NAME ) // the name of our product in EDD
 
 
 
 
 
 
 
 
 
 
 
 
930
  );
931
-
932
- $response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP__SECURESITE_URL ), array( 'timeout' => 15, 'sslverify' => true ) );
933
  $logger->log('Validation Response:');
934
  $logger->log($response);
935
 
@@ -1114,9 +1244,12 @@ class WPBackitup_Admin {
1114
  */
1115
  public static function activate() {
1116
  try{
 
 
 
1117
  //add cron task for once per hour starting in 1 hour
1118
- if(!wp_next_scheduled( 'wpbackitup_check_scheduled_tasks' ) ){
1119
- wp_schedule_event( time()+3600, 'hourly', 'wpbackitup_check_scheduled_tasks');
1120
  }
1121
 
1122
  //Check backup folder folders
@@ -1125,11 +1258,27 @@ class WPBackitup_Admin {
1125
  @mkdir($backup_dir, 0755);
1126
  }
1127
 
1128
- //Check restore folder folders
1129
- $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
1130
- if( !is_dir($restore_dir) ) {
1131
- @mkdir($restore_dir, 0755);
1132
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1133
 
1134
  //Check permissions on logs
1135
  $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs';
@@ -1137,6 +1286,14 @@ class WPBackitup_Admin {
1137
  chmod($logs_dir, 0755);
1138
  }
1139
 
 
 
 
 
 
 
 
 
1140
  //Make sure they exist now
1141
  if( !is_dir($backup_dir) || !is_dir($restore_dir)) {
1142
  exit ('WP BackItUp was not able to create the required backup and restore folders.');
@@ -1153,7 +1310,7 @@ class WPBackitup_Admin {
1153
  public static function deactivate() {
1154
  // Do deactivation actions
1155
 
1156
- wp_clear_scheduled_hook( 'wpbackitup_check_scheduled_tasks');
1157
  }
1158
 
1159
  /* --------------------- PRIVATES -----------------------------------------*/
34
  private $backup_count; //getter will load
35
  private $successful_backup_count;
36
 
37
+ public $backup_type;
38
 
39
 
40
  // Default plugin options
52
  'backup_retained_number' => "3",
53
  'lite_backup_retained_number' => "1",
54
  'lite_registration_email' => "",
55
+ 'lite_registration_first_name' => "",
56
  'backup_count'=>0,
57
  'successful_backup_count'=>0,
58
  'stats_last_check_date'=> "1970-01-01 00:00:00",
59
  'backup_schedule'=>"",
60
+ 'backup_lastrun_date'=>"-2147483648",
61
+ 'cleanup_lastrun_date'=>"-2147483648",
62
+ 'backup_batch_size'=>"10",
63
  );
64
 
65
 
68
  */
69
  public static function get_instance() {
70
  if ( ! self::$instance ) {
 
71
  self::$instance = new self();
72
  }
73
 
106
  add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
107
 
108
  //Load all the resources
109
+ add_action( 'admin_enqueue_scripts', array( &$this, 'load_resources' ) );
110
 
111
  //Load the backup action
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, 'ajax_restore' ));
118
  add_action('wp_ajax_wp-backitup_upload', array( &$this, 'ajax_upload' ));
119
 
120
  //Status reader for UI
121
+ add_action('wp_ajax_wp-backitup_restore_status_reader', array( &$this,'ajax_get_restore_status'));
122
 
123
+ add_action('wp_ajax_wp-backitup_backup_status_reader', array( &$this,'ajax_get_backup_status'));
124
+
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,'ajax_delete_file'));
134
  add_action('admin_post_nopriv_listlogs', array( &$this,'admin_listlogs'));
135
 
136
  //Create Daily backup action
137
+ add_action( 'wpbackitup_queue_scheduled_jobs', array( &$this,'wpbackitup_queue_scheduled_jobs'));
138
+
139
+ add_action( 'wpbackitup_run_backup_tasks', array( &$this,'wpbackitup_run_backup_tasks'));
140
+
141
+ add_action( 'wpbackitup_run_cleanup_tasks', array( &$this,'wpbackitup_run_cleanup_tasks'));
142
 
 
143
  }
144
 
145
  /**
169
  // remove duplicate submenu page. wp limitations //
170
  // http://wordpress.stackexchange.com/questions/16401/remove-duplicate-main-submenu-in-admin
171
  remove_submenu_page($this->namespace,$this->namespace);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  }
174
 
175
  public function load_resources() {
 
 
 
176
 
177
+ //Only load the JS and CSS when plugin is active
178
+ if( !empty($_REQUEST['page']) && substr($_REQUEST['page'], 0, 11) === 'wp-backitup') {
179
 
180
+ // Admin JavaScript
181
+ wp_register_script( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "js/wpbackitup_admin.js", array( 'jquery' ), $this->version, true );
182
+ wp_enqueue_script( "{$this->namespace}-admin" );
183
 
184
+ // Admin Stylesheet
185
+ wp_register_style( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "css/wpbackitup_admin.css", array(), $this->version, 'screen' );
186
+ wp_enqueue_style( "{$this->namespace}-admin" );
187
+
188
+ //Admin fonts
189
+ wp_register_style( 'google-fonts', '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' );
190
+ wp_enqueue_style( 'google-fonts' );
191
+ }
192
  }
193
+
194
  /**
195
  * The admin section backup page rendering method
196
  *
302
  $this->check_license();
303
  }
304
 
305
+ public function wpbackitup_queue_scheduled_jobs(){
306
 
307
+ //Include Scheduler Class
308
+ if( !class_exists( 'WPBackItUp_Scheduler' ) ) {
309
+ include_once 'class-scheduler.php';
310
+ }
311
 
312
+ //Include Job class
313
+ if( !class_exists( 'WPBackItUp_Job' ) ) {
314
+ include_once 'class-job.php';
315
+ }
 
 
316
 
317
+ //If no backup or cleanup queued already then queue one
318
+ if (!WPBackItUp_Job::is_job_queued('backup')) {
 
 
 
319
 
320
+ //Is it time for a backup?
321
+ //Check scheduler and queue tasks that need to be run
322
+ $scheduler = new WPBackItUp_Scheduler();
323
+ if ( $scheduler->isTaskScheduled( 'backup' ) && !WPBackItUp_Job::is_job_queued('cleanup')) {
324
+ $backup_job = WPBackItUp_Job::queue_job( 'backup' );
325
 
326
+ //Setup the job run event
327
+ wp_schedule_single_event( time(), 'wpbackitup_run_backup_tasks' );
328
 
329
+ exit( 0 ); //success - don't schedule anything else
330
+ }
331
+ } else {
332
+ //backup is queued are tasks scheduled
333
+ if (false===wp_next_scheduled('wpbackitup_run_backup_tasks')){
334
+ wp_schedule_single_event( time(), 'wpbackitup_run_backup_tasks' );
335
+ }
336
+ }
337
+
338
+ //If no backup or cleanup queued already then queue one
339
+ if (!WPBackItUp_Job::is_job_queued('cleanup')) {
340
+ //Is it time for a cleanup
341
+ //Check scheduler and queue tasks that need to be run
342
+ $scheduler = new WPBackItUp_Scheduler();
343
+ if ( $scheduler->isTaskScheduled( 'cleanup' ) && !WPBackItUp_Job::is_job_queued('backup') ) {
344
+ $cleanup_job = WPBackItUp_Job::queue_job( 'cleanup' );
345
 
346
+ //Setup the job run event
347
+ wp_schedule_single_event( time(), 'wpbackitup_run_cleanup_tasks' );
348
+
349
+ exit( 0 ); //success - don't schedule anything else
350
+ }
351
+ } else{
352
+ //cleanup is queued are tasks scheduled
353
+ if (false===wp_next_scheduled('wpbackitup_run_cleanup_tasks')){
354
+ wp_schedule_single_event( time(), 'wpbackitup_run_cleanup_tasks' );
355
+ }
356
+
357
+ }
358
+
359
+ exit(0); //success nothing to schedule
360
+ }
361
+
362
+ //Run queue manual backup
363
+ public function ajax_queue_backup() {
364
+ $logger = new WPBackItUp_Logger(false,null,'debug_events');
365
+ $logger->log_info(__METHOD__,'Begin');
366
+
367
+ //Include Job class
368
+ if( !class_exists( 'WPBackItUp_Job' ) ) {
369
+ include_once 'class-job.php';
370
+ }
371
+
372
+ $rtnData = new stdClass();
373
+ //If no backup queued already then queue one
374
+ if (!WPBackItUp_Job::is_job_queued('backup')){
375
+ if (WPBackItUp_Job::queue_job('backup')){
376
+ $rtnData->message = 'Backup Queued';
377
+ }else {
378
+ $rtnData->message = 'Backup could not be queued';
379
+ }
380
+ }else{
381
+ $rtnData->message = 'Backup already in queue';
382
+ }
383
+
384
+ $logger->log_info(__METHOD__,$rtnData->message);
385
+ $logger->log_info(__METHOD__,'End');
386
+ echo json_encode($rtnData);
387
+ exit;
388
+ }
389
+
390
+ //Run scheduled backup tasks
391
+ function wpbackitup_run_backup_tasks(){
392
+ $process_id = uniqid();
393
+
394
+ $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
395
+ $event_logger->log_info(__METHOD__ .'(' .$process_id .')', 'Begin');
396
+
397
+ //Try Run Next Backup Tasks
398
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','Try Run Backup Task');
399
+
400
+ $this->backup_type='scheduled';
401
+ include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_backup.php' );
402
+
403
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','End Try Run Backup Task');
404
+
405
+ exit(0);
406
  }
407
 
408
+ //Run scheduled backup tasks
409
+ function wpbackitup_run_cleanup_tasks(){
410
+ $process_id = uniqid();
411
+
412
+ $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
413
+ $event_logger->log_info(__METHOD__ .'(' .$process_id .')', 'Begin');
414
+
415
+ //Try Run Next Backup Tasks
416
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','Try Run cleanup Task');
417
+
418
+ $this->backup_type='scheduled';
419
+ include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_cleanup.php' );
420
+
421
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','End Try Run cleanup Task');
422
+
423
+ exit;
424
+ }
425
+
426
+
427
+ public function ajax_get_restore_status() {
428
+ $log = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
429
+ if(file_exists($log) ) {
430
+ readfile($log);
431
+ }
432
+ exit;
433
+ }
434
+
435
+
436
+ /**
437
+ * Return the backup status and try run tasks
438
+ */
439
+ public function ajax_get_backup_status() {
440
+ $process_id = uniqid();
441
+
442
+ $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
443
+ $event_logger->log_info(__METHOD__ .'(' .$process_id .')', 'Begin');
444
+
445
+ //Try Run Next Backup Tasks
446
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','Try Run Backup Task');
447
+
448
+ $this->backup_type='manual';
449
+ include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_backup.php' );
450
+
451
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','End Try Run Backup Task');
452
+
453
+ //return status
454
+ $log = WPBACKITUP__PLUGIN_PATH .'/logs/backup_status.log';
455
+ if(file_exists($log) ) {
456
+ //Probably should use the database instead now.
457
+ readfile($log);
458
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','Status sent to browser.');
459
+ }
460
+
461
+ exit;
462
+ }
463
+
464
  //load restore
465
  public function ajax_restore() {
466
+ include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_restore.php' );
467
  }
468
 
469
  //load upload
471
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/upload.php' );
472
  }
473
 
 
 
 
 
 
 
 
474
 
475
+
476
+ public function ajax_backup_response_reader() {
477
+ $log = WPBACKITUP__PLUGIN_PATH .'/logs/backup_response.log';
478
  if(file_exists($log) ) {
479
  readfile($log);
480
  }else{
547
  //Could have just been a license update
548
  if(!empty($data)) {
549
 
550
+
551
+ //** VALIDATE backup_retained_number **//
552
  //Set back to original settings if value not changed
553
  if(!empty($data['backup_retained_number']) && !is_numeric($data['backup_retained_number']))
554
  {
555
  $data['backup_retained_number'] = $this->defaults['backup_retained_number'];
556
  set_transient('settings-error-number', __('Please enter a number', $this->namespace), 60);
557
+
558
  }
559
  else{ //Empty OR not NUMERIC
560
 
561
  //Empty
562
  if ( empty($data['backup_retained_number']) ){
563
+ $data['backup_retained_number'] = $this->defaults['backup_retained_number'];
564
  set_transient('settings-error-number', __('Please enter a number', $this->namespace), 60);
565
  }
566
 
578
 
579
  }
580
 
581
+ //** VALIDATE notification_email **//
582
  if(!empty($data['notification_email']) && !is_email($data['notification_email']))
583
  {
584
  $data['notification_email'] = $this->defaults['notification_email'];
585
  set_transient('settings-error-email', __('Please enter a a valid email', $this->namespace), 60);
586
  }
587
 
588
+
589
+ //** VALIDATE backup_batch_size **//
590
+ if(empty($data['backup_batch_size']) || !is_numeric($data['backup_batch_size']))
591
+ {
592
+ $data['backup_batch_size'] = $this->defaults['backup_batch_size'];
593
+ set_transient('batch_size_settings-error-number', __('Please enter a number', $this->namespace), 60);
594
+ }
595
+
596
+
597
  // Update the options value with the data submitted
598
  foreach( $data as $key => $val ) {
599
  $this->set_option($key, $val);
628
  $this->set_backup_schedule($days_selected);
629
 
630
  //Add backup scheduled if doesnt exist
631
+ if(!wp_next_scheduled( 'wpbackitup_queue_scheduled_jobs' ) ){
632
+ wp_schedule_event( time()+3600, 'hourly', 'wpbackitup_queue_scheduled_jobs');
633
  }
634
 
635
  return true;
652
  * dealt with directly.
653
  */
654
 
655
+ $logger = new WPBackItUp_Logger(false,null,'debug_lite_registration');
656
  $logger->log("Register WP BackItUp Lite");
657
  $logger->log($_POST);
658
 
661
  if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)){
662
  $urlparts = parse_url(site_url());
663
  $domain = $urlparts['host'];
 
664
 
665
+ $first_name=$_POST['first_name'];
 
 
666
 
667
+ //save options to DB
668
  $this->set_option('lite_registration_email', $email);
669
+ if(!empty($first_name)){
670
+ $this->set_option('lite_registration_first_name', $first_name);
671
+ }
 
 
 
 
 
672
 
673
  $form_data = array(
674
+ 'email' => $email,
675
+ 'site' => $domain,
676
+ 'first_name' => $first_name,
677
+ 'time_zone'=> get_option('timezone_string'),
 
 
 
 
678
  );
679
 
680
+ $url = WPBACKITUP__SECURESITE_URL; //PRD
681
+ $post_url=$url . '/api/wpbackitup/register_lite';
 
682
 
683
  $logger->log('Lite User Registration Post URL: ' .$post_url);
684
+ $logger->log('Lite User Registration Post Form Data: ' );
685
+ $logger->log($form_data);
686
 
687
  $response = wp_remote_post( $post_url, array(
688
  'method' => 'POST',
689
  'timeout' => 45,
 
 
690
  'blocking' => true,
691
  'headers' => array(),
692
+ 'body' => $form_data,
 
 
 
 
693
  'cookies' => array()
694
  )
695
  );
801
  return $this->get('cleanup_lastrun_date');
802
  }
803
 
804
+ public function backup_batch_size(){
805
+ return $this->get('backup_batch_size');
806
+ }
807
+
808
+
809
 
810
  /**
811
  * Getter - license active - derived property
924
  return $this->get('lite_registration_email');
925
  }
926
 
927
+ function lite_registration_first_name(){
928
+ return $this->get('lite_registration_first_name');
929
+ }
930
+
931
  function is_lite_registered(){
932
  $lite_email_registration= $this->lite_registration_email();
933
  if (!empty($lite_email_registration)) {
976
  public function set_cleanup_lastrun_date($value){
977
  $this->set('cleanup_lastrun_date', $value);
978
  }
979
+
980
+ public function set_backup_batch_size($value){
981
+ $this->set('backup_batch_size', $value);
982
+ }
983
  /**---------- END SETTERS --------------- **/
984
 
985
 
1046
  $api_params = array(
1047
  'edd_action'=> 'activate_license',
1048
  'license' => $license,
1049
+ 'item_name' => urlencode( WPBACKITUP__ITEM_NAME ), // the name of product in EDD
1050
+ //'url' => home_url()
1051
+ );
1052
+
1053
+ $logger->log('Activate License Request Info:');
1054
+ $logger->log($api_params);
1055
+
1056
+ $response = wp_remote_get(
1057
+ add_query_arg( $api_params, WPBACKITUP__SECURESITE_URL ),
1058
+ array(
1059
+ 'timeout' => 15,
1060
+ 'sslverify' => false
1061
+ )
1062
  );
 
 
1063
  $logger->log('Validation Response:');
1064
  $logger->log($response);
1065
 
1244
  */
1245
  public static function activate() {
1246
  try{
1247
+ //Get rid of old job
1248
+ wp_clear_scheduled_hook('wpbackitup_check_scheduled_tasks');
1249
+
1250
  //add cron task for once per hour starting in 1 hour
1251
+ if(!wp_next_scheduled( 'wpbackitup_queue_scheduled_jobs' ) ){
1252
+ wp_schedule_event( time()+3600, 'hourly', 'wpbackitup_queue_scheduled_jobs');
1253
  }
1254
 
1255
  //Check backup folder folders
1258
  @mkdir($backup_dir, 0755);
1259
  }
1260
 
1261
+ //Check index in backup
1262
+ $backup_index = $backup_dir .'/index.html';
1263
+ if( !is_file($backup_index) ) {
1264
+ //create index.html
1265
+ $dfh = fopen( $backup_index, 'a' );
1266
+ fclose( $dfh );
1267
+ }
1268
+
1269
+ //Check restore folder folders
1270
+ $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
1271
+ if( !is_dir($restore_dir) ) {
1272
+ @mkdir($restore_dir, 0755);
1273
+ }
1274
+
1275
+ //check index in restore
1276
+ $restore_index = $restore_dir .'/index.html';
1277
+ if( !is_file($restore_index) ) {
1278
+ //create index.html
1279
+ $dfh = fopen( $restore_index, 'a' );
1280
+ fclose( $dfh );
1281
+ }
1282
 
1283
  //Check permissions on logs
1284
  $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs';
1286
  chmod($logs_dir, 0755);
1287
  }
1288
 
1289
+ //check index in logs
1290
+ $logs_index = $logs_dir .'/index.html';
1291
+ if( !is_file($logs_index) ) {
1292
+ //create index.html
1293
+ $dfh = fopen( $logs_index, 'a' );
1294
+ fclose( $dfh );
1295
+ }
1296
+
1297
  //Make sure they exist now
1298
  if( !is_dir($backup_dir) || !is_dir($restore_dir)) {
1299
  exit ('WP BackItUp was not able to create the required backup and restore folders.');
1310
  public static function deactivate() {
1311
  // Do deactivation actions
1312
 
1313
+ wp_clear_scheduled_hook( 'wpbackitup_queue_scheduled_jobs');
1314
  }
1315
 
1316
  /* --------------------- PRIVATES -----------------------------------------*/
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=1000;
11
  $this->zip_file_count=0;
12
  }
13
  function __destruct() {
14
 
15
  }
16
  }
17
  if (!$zip->addFile($src,substr($src,$path))){
18
  return false;
19
  }
20
  }
21
  if(!is_dir($src)){
22
  $zip->close();
23
  @unlink($dst);
24
  $this->logger->log('(Zip.compress) File not found:' . $dst);
25
  return false;
26
  }
27
  $rtnVal = $this->recurse_zip($src,$dst,$zip,$path);}
28
  //Reopen the zip when you get to max file count
29
  if($this->zip_file_count>=$this->max_file_count){
30
  $zip->close();
31
  $this->zip_file_count=0;
32
  $zip = new ZipArchive;
33
  $res = $zip->open($dst,ZIPARCHIVE::CREATE);
34
  //Check for error
35
  if($res !== TRUE){
36
  $this->logger->log('(Zip.recurse_zip) Zip open cant be opened:' .$res);
37
  return false;
38
  }
39
  }
40
  $zipFilePath = substr($src . '/' . $file,$path);
41
  if (!$zip->addEmptyDir($zipFilePath)){
42
  $this->logger->log('(Zip.recurse_zip) Cant add empty directory' .$zipFilePath);
43
  return false;
44
  }
45
  $this->zip_file_count++;
46
  if (!$this->recurse_zip($src . '/' . $file,$dst,$zip,$path)){
47
  $this->logger->log('(Zip.recurse_zip)Recursive zip error');
48
  return false;
49
  }
50
  $this->logger->log('(Zip.recurse_zip)Cant add file to zip');
51
  return false;
52
  }
53
  $this->zip_file_count++;
54
  return true;
 
55
  * WP Backitup Zip Function
56
  *
57
  * @package WP Backitup
58
  *
59
  * @author cssimmon
60
  *
61
  */
62
  private $zip_file_count;
63
  private $max_file_count=1000;
64
  $this->zip_file_count=0;
65
  }
66
  function __destruct() {
 
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=1000;
10
  $this->zip_file_count=0;
11
  }
12
  function __destruct() {
13
 
14
  }
15
  }
16
  if (!$zip->addFile($src,substr($src,$path))){
17
  return false;
18
  }
19
  }
20
  if(!is_dir($src)){
21
  $zip->close();
22
  @unlink($dst);
23
  $this->logger->log('(Zip.compress) File not found:' . $dst);
24
  return false;
25
  }
26
  $rtnVal = $this->recurse_zip($src,$dst,$zip,$path);}
27
  //Reopen the zip when you get to max file count
28
  if($this->zip_file_count>=$this->max_file_count){
29
  $zip->close();
30
  $this->zip_file_count=0;
31
  $zip = new ZipArchive;
32
  $res = $zip->open($dst,ZIPARCHIVE::CREATE);
33
  //Check for error
34
  if($res !== TRUE){
35
  $this->logger->log('(Zip.recurse_zip) Zip open cant be opened:' .$res);
36
  return false;
37
  }
38
  }
39
  $zipFilePath = substr($src . '/' . $file,$path);
40
  if (!$zip->addEmptyDir($zipFilePath)){
41
  $this->logger->log('(Zip.recurse_zip) Cant add empty directory' .$zipFilePath);
42
  return false;
43
  }
44
  $this->zip_file_count++;
45
  if (!$this->recurse_zip($src . '/' . $file,$dst,$zip,$path)){
46
  $this->logger->log('(Zip.recurse_zip)Recursive zip error');
47
  return false;
48
  }
49
  $this->logger->log('(Zip.recurse_zip)Cant add file to zip');
50
  return false;
51
  }
52
  $this->zip_file_count++;
53
  return true;
54
+ <?php if (!defined ('ABSPATH')) die('No direct access allowed');
55
  * WP Backitup Zip Function
56
  *
57
  * @package WP Backitup
58
  *
59
  * @author cssimmon
60
  *
61
  */
62
  private $zip_file_count;
63
  private $max_file_count=1000;
64
  $this->zip_file_count=0;
65
  }
66
  function __destruct() {
lib/includes/index.html ADDED
File without changes
lib/includes/job_backup.php ADDED
@@ -0,0 +1,915 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!defined ('ABSPATH')) die('No direct access allowed');
2
+ @set_time_limit(WPBACKITUP__SCRIPT_TIMEOUT_SECONDS);
3
+
4
+ /**
5
+ * WP Backitup Backup
6
+ *
7
+ * @package WP Backitup
8
+ *
9
+ * @author cssimmon
10
+ *
11
+ */
12
+
13
+ /*** Includes ***/
14
+
15
+ if( !class_exists( 'WPBackItUp_Logger' ) ) {
16
+ include_once 'class-logger.php';
17
+ }
18
+
19
+ if( !class_exists( 'WPBackItUp_Utility' ) ) {
20
+ include_once 'class-utility.php';
21
+ }
22
+
23
+
24
+ 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
+ // include file system class
39
+ if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
40
+ include_once 'class-filesystem.php';
41
+ }
42
+
43
+ // include job class
44
+ if( !class_exists( 'WPBackItUp_Job' ) ) {
45
+ include_once 'class-job.php';
46
+ }
47
+
48
+ /*** Globals ***/
49
+ global $WPBackitup;
50
+
51
+ global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
52
+ $inactive=0;
53
+ $active=1;
54
+ $complete=2;
55
+ $failure=-1;
56
+ $warning=-2;
57
+ $success=99;
58
+
59
+ //setup the status array
60
+ global $status_array;
61
+ $status_array = array(
62
+ 'preparing' =>$inactive,
63
+ 'backupdb' =>$inactive ,
64
+ 'infofile'=>$inactive,
65
+ 'backup_themes'=>$inactive,
66
+ 'backup_plugins'=>$inactive,
67
+ 'backup_uploads'=>$inactive,
68
+ 'backup_other'=>$inactive,
69
+ 'finalize_backup'=>$inactive,
70
+ 'validate_backup'=>$inactive,
71
+ 'cleanup'=>$inactive
72
+ );
73
+
74
+
75
+ //**************************//
76
+ // SINGLE THREAD BACKUPS //
77
+ //**************************//
78
+
79
+ $logger_tasks = new WPBackItUp_Logger(false,null,'debug_tasks');
80
+ $backup_process_id = uniqid();
81
+
82
+ //Make sure backup is NOT already running before you run the current task
83
+
84
+ //Scheduled the next check
85
+ if ('scheduled'==$this->backup_type){
86
+ wp_schedule_single_event( time()+30, 'wpbackitup_run_backup_tasks');
87
+ }
88
+
89
+ if (!WPBackItUp_Backup::start()) {
90
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Backup job cant acquire job lock.');
91
+ return; //nothing to do
92
+ }else{
93
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Backup job lock acquired.');
94
+ }
95
+ //**************************//
96
+
97
+
98
+ //**************************//
99
+ // Task Handling //
100
+ //**************************//
101
+ global $backup_job;
102
+ $backup_job=null;
103
+ $current_task= null;
104
+
105
+ $backup_error=false;
106
+ $backup_job = WPBackItUp_Job::get_job('backup');
107
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Check for available backup job');
108
+ if ($backup_job){
109
+
110
+ //Get the next task in the stack
111
+ $next_task = $backup_job->get_next_task();
112
+ if (false!==$next_task){
113
+ $backup_id=$backup_job->backup_id;
114
+ $current_task=$next_task;
115
+
116
+ //If task contains error then timeout has occurred
117
+ if (strpos($current_task,'error') !== false){
118
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Backup Error Found:' .$current_task);
119
+ $backup_error=true;
120
+ }
121
+
122
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Available Task Found:' . $current_task);
123
+
124
+ }else{
125
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','No available tasks found.');
126
+ WPBackItUp_Backup::end(); //release lock
127
+ return;
128
+ }
129
+ }else {
130
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','No backup job available.');
131
+
132
+ wp_clear_scheduled_hook( 'wpbackitup_run_backup_tasks');
133
+ WPBackItUp_Backup::end(); //release lock
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
+
141
+ //*************************//
142
+ //*** MAIN BACKUP CODE ***//
143
+ //*************************//
144
+
145
+ //Get the backup ID
146
+ $backup_name = get_backup_name($backup_job->backup_id);
147
+
148
+ global $logger;
149
+ $logger = new WPBackItUp_Logger(false,null,$backup_name);
150
+
151
+ global $wp_backup;
152
+ $wp_backup = new WPBackItUp_Backup($logger,$backup_name,$WPBackitup->backup_type);
153
+
154
+
155
+ //*************************//
156
+ //*** BACKUP TASKS ***//
157
+ //*************************//
158
+
159
+ //An error has occurred on the previous tasks
160
+ if ($backup_error) {
161
+ $error_task = substr($current_task,6);
162
+ $logger->log('Fatal error on previous task:'. $error_task);
163
+
164
+ //Check for error type
165
+ switch ($error_task) {
166
+ case "cleanup_prev":
167
+ set_status('preparing',$active,true);
168
+ write_fatal_error_status('2101');
169
+ end_backup(2101, false);
170
+ break;
171
+
172
+ case "backup_db":
173
+ set_status( 'backupdb', $active, true );
174
+ write_fatal_error_status( '2104' );
175
+ end_backup( 2104, false );
176
+ break;
177
+
178
+ case "backup_siteinfo":
179
+ set_status( 'infofile', $active, true );
180
+ write_fatal_error_status( '2105' );
181
+ end_backup( 2105, false );
182
+ break;
183
+
184
+ case "backup_themes":
185
+ set_status( 'backup_themes', $active, true );
186
+ write_fatal_error_status( '2120' );
187
+ end_backup( 2120, false );
188
+ break;
189
+
190
+ case "backup_plugins":
191
+ set_status( 'backup_plugins', $active, true );
192
+ write_fatal_error_status( '2121' );
193
+ end_backup( 2121, false );
194
+ break;
195
+
196
+ case "backup_uploads":
197
+ set_status( 'backup_uploads', $active, true );
198
+ write_fatal_error_status( '2122' );
199
+ end_backup( 2122, false );
200
+ break;
201
+
202
+ case "backup_other":
203
+ set_status( 'backup_other', $active, true );
204
+ write_fatal_error_status( '2123' );
205
+ end_backup( 2123, false );
206
+ break;
207
+
208
+ case "finalize_backup":
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 "cleanup_current": //Dont end backup on this error
221
+ set_status( 'cleanup', $active, true );
222
+ write_warning_status( '2106' );
223
+ break;
224
+
225
+ default:
226
+ write_warning_status( '2999' );
227
+ end_backup( 2999, false );
228
+ break;
229
+ }
230
+
231
+ }
232
+
233
+ //Cleanup Task
234
+ if ('cleanup_prev'==$current_task) {
235
+
236
+ //Init
237
+ $logger->log('***BEGIN BACKUP***');
238
+ $logger->log_sysinfo();
239
+ $logger->log('BACKUP TYPE:' .$wp_backup->backup_type);
240
+ $logger->log('BACKUP BATCH SIZE:' .$wp_backup->backup_batch_size);
241
+ $logger->log('BACKUP ID:' .$backup_job->backup_id);
242
+
243
+ $WPBackitup->increment_backup_count();
244
+ //End Init
245
+
246
+ $logger->log('**BEGIN CLEANUP**');
247
+
248
+ //Cleanup & Validate the backup folded is ready
249
+ write_response_processing("preparing for backup");
250
+ set_status('preparing',$active,true);
251
+
252
+ write_response_processing("Cleanup before backup");
253
+
254
+ //*** Check Dependencies ***
255
+ if (!WPBackItUp_Zip::zip_utility_exists()) {
256
+ $logger->log_error(__METHOD__, 'Zip Util does not exist.' );
257
+ $backup_job->set_task_error('125');
258
+ write_fatal_error_status( '125' );
259
+ end_backup( 125, false );
260
+ }
261
+
262
+ //*** END Check Dependencies ***
263
+
264
+
265
+ //Cleanup any backups that didnt finish normally
266
+ $wp_backup->cleanup_unfinished_backups();
267
+
268
+ //Make sure wpbackitup_backups exists
269
+ if (! $wp_backup->backup_root_folder_exists() ){
270
+ $backup_job->set_task_error('101');
271
+
272
+ write_fatal_error_status('101');
273
+ end_backup(101, false);
274
+ }
275
+
276
+ //Create the root folder for the current backup
277
+ if (! $wp_backup->create_current_backup_folder()){
278
+ $backup_job->set_task_error('101');
279
+
280
+ write_fatal_error_status('101');
281
+ end_backup(101, false);
282
+ }
283
+
284
+ //Check to see if the directory exists and is writeable
285
+ if (! $wp_backup->backup_folder_exists()){
286
+ $backup_job->set_task_error('102');
287
+
288
+ write_fatal_error_status('102');
289
+ end_backup(102,false);
290
+ }
291
+
292
+ set_status('preparing',$complete,false);
293
+ $backup_job->set_task_complete();
294
+
295
+ $logger->log('**END CLEANUP**');
296
+ return;
297
+ }
298
+
299
+
300
+ //Backup the database
301
+ if ('backup_db'==$current_task) {
302
+ $logger->log( '**BEGIN SQL EXPORT**' );
303
+ write_response_processing( "Create database export" );
304
+ set_status( 'backupdb', $active, true );
305
+
306
+ if ( ! $wp_backup->export_database() ) {
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
+
314
+ set_status('backupdb',$complete,false);
315
+ $backup_job->set_task_complete();
316
+
317
+ $logger->log('**END SQL EXPORT**');
318
+ return;
319
+
320
+ }
321
+
322
+ //Extract the site info
323
+ if ('backup_siteinfo'==$current_task) {
324
+ $logger->log( '**SITE INFO**' );
325
+ write_response_processing( "Retrieve Site Info" );
326
+ set_status( 'infofile', $active, true );
327
+
328
+ if ( ! $wp_backup->create_siteinfo_file() ) {
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
+
339
+ $logger->log( '**END SITE INFO**' );
340
+ return;
341
+
342
+ }
343
+
344
+ //Backup the themes
345
+ if ('backup_themes'==$current_task) {
346
+ $logger->log( '**BACKUP THEMES TASK**' );
347
+ write_response_processing( "Backup themes " );
348
+ set_status( 'backup_themes', $active, true );
349
+
350
+ switch ($wp_backup->backup_themes()) {
351
+ case "complete":
352
+ $logger->log('All themes backed up.');
353
+
354
+ set_status( 'backup_themes', $complete, false );
355
+ $backup_job->set_task_complete();
356
+ $logger->log('**END BACKUP THEMES TASK**');
357
+ break;
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 ('backup_plugins'==$current_task) {
380
+ $logger->log( '**BACKUP PLUGINS TASK**' );
381
+ write_response_processing( "Backup plugins " );
382
+ set_status( 'backup_plugins', $active, true );
383
+
384
+
385
+ switch ($wp_backup->backup_plugins()) {
386
+ case "complete":
387
+ $logger->log('All plugins backed up.');
388
+
389
+ set_status( 'backup_plugins', $complete, false );
390
+ $backup_job->set_task_complete();
391
+ $logger->log('**END BACKUP PLUGINS TASK**');
392
+ break;
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 ('backup_uploads'==$current_task) {
415
+ $logger->log( '**BACKUP UPLOADS TASK**' );
416
+ write_response_processing( "Backup uploads " );
417
+ set_status( 'backup_uploads', $active, true );
418
+
419
+ switch ($wp_backup->backup_uploads()) {
420
+ case "complete":
421
+ $logger->log('All uploads backed up.');
422
+
423
+ set_status( 'backup_uploads', $complete, false );
424
+ $backup_job->set_task_complete();
425
+ $logger->log('**END BACKUP UPLOADS TASK**');
426
+ break;
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 ('backup_other'==$current_task) {
449
+ $logger->log( '**BACKUP OTHER TASK**' );
450
+ write_response_processing( "Backup other files " );
451
+ set_status( 'backup_other', $active, true );
452
+
453
+ switch ($wp_backup->backup_other()) {
454
+ case "complete":
455
+ $logger->log('All others backed up.');
456
+
457
+ set_status('backup_other',$complete,false);
458
+ $backup_job->set_task_complete();
459
+ $logger->log('**END BACKUP OTHER TASK**');
460
+ break;
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 ('validate_backup'==$current_task) {
523
+ //Validate the content if logging is on
524
+ $logger->log('**VALIDATE CONTENT**');
525
+
526
+ write_response_processing( "Validating Backup " );
527
+ set_status( 'validate_backup', $active, true );
528
+
529
+ if ($WPBackitup->logging()){
530
+ $wp_backup->validate_backup();
531
+
532
+ }
533
+
534
+ set_status( 'validate_backup', $complete, false );
535
+ $backup_job->set_task_complete();
536
+ $logger->log('**END VALIDATE CONTENT**');
537
+
538
+ return;
539
+ }
540
+
541
+
542
+ //Cleanup work folders
543
+ if ('cleanup_current'==$current_task) {
544
+ $logger->log( '**CLEANUP**' );
545
+ write_response_processing( "Cleanup after Backup " );
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
+ //Check retention limits and cleanup
554
+ $wp_backup->purge_old_files();
555
+
556
+ set_status( 'cleanup', $complete, false );
557
+ $backup_job->set_task_complete();
558
+
559
+ $logger->log( '**END CLEANUP**' );
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
+ /******************/
571
+ function get_backup_name($timestamp){
572
+
573
+ $url = home_url();
574
+ $url = str_replace('http://','',$url);
575
+ $url = str_replace('https://','',$url);
576
+ $url = str_replace('/','-',$url);
577
+ $fileUTCDateTime=$timestamp;//current_time( 'timestamp' );
578
+ $localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
579
+ $backup_name = 'Backup_' . $url .'_' .$localDateTime;
580
+
581
+ return $backup_name;
582
+
583
+ }
584
+ function end_backup($err=null, $success=null){
585
+ global $WPBackitup,$wp_backup, $logger, $backup_job;
586
+ $logger->log_info(__METHOD__,"Begin");
587
+
588
+ WPBackItUp_Backup::end(); //Release the lock
589
+ $current_datetime = current_time( 'timestamp' );
590
+ $WPBackitup->set_backup_lastrun_date($current_datetime);
591
+
592
+ $util = new WPBackItUp_Utility($logger);
593
+ $seconds = $util->timestamp_diff_seconds($backup_job->get_job_start_time(),$backup_job->get_job_end_time());
594
+
595
+ $processing_minutes = round($seconds / 60);
596
+ $processing_seconds = $seconds % 60;
597
+
598
+ $logger->log('Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
599
+
600
+ //Send Notification email
601
+ send_backup_notification_email($err, $success);
602
+
603
+
604
+ if (true===$success) $logger->log("Backup completed: SUCCESS");
605
+ if (false===$success) $logger->log("Backup completed: ERROR");
606
+ $logger->log("*** END BACKUP ***");
607
+
608
+ $logFileName = $logger->logFileName;
609
+ $logFilePath = $logger->logFilePath;
610
+ $logger->close_file();
611
+
612
+ //Move the log if it exists
613
+ $newlogFilePath = $wp_backup->backup_folder_root .$logFileName;
614
+ if (null!=$success && file_exists($logFilePath)){
615
+ copy ($logFilePath,$newlogFilePath);
616
+ unlink($logFilePath);
617
+ }
618
+
619
+ echo('Backup has completed');
620
+ exit(0);
621
+ }
622
+
623
+ function send_backup_notification_email($err, $success) {
624
+ global $WPBackitup, $wp_backup, $logger,$status_array,$backup_job;
625
+ $logger->log_info(__METHOD__,"Begin");
626
+
627
+ $start_timestamp = $backup_job->get_job_start_time();
628
+ $end_timestamp = $backup_job->get_job_end_time();
629
+ $utility = new WPBackItUp_Utility($logger);
630
+ $seconds = $utility->timestamp_diff_seconds($start_timestamp,$end_timestamp);
631
+
632
+ $processing_minutes = round($seconds / 60);
633
+ $processing_seconds = $seconds % 60;
634
+
635
+ $status_description = array(
636
+ 'preparing'=>'Preparing for backup...Done',
637
+ 'backupdb'=>'Backing up database...Done',
638
+ 'infofile'=>'Creating backup information file...Done',
639
+ 'backup_themes'=>'Backing up themes...Done',
640
+ 'backup_plugins'=>'Backing up plugins...Done',
641
+ 'backup_uploads'=>'Backing up uploads...Done',
642
+ 'backup_other'=>'Backing up miscellaneous files...Done',
643
+ 'finalize_backup'=>'Finalizing backup...Done',
644
+ 'validate_backup'=>'Validating backup...Done',
645
+ 'cleanup'=>'Cleaning up...Done'
646
+ );
647
+
648
+ if($success)
649
+ {
650
+ $subject = get_bloginfo() . ' - Backup completed successfully.';
651
+ $message = '<b>Your backup completed successfully.</b><br/><br/>';
652
+
653
+ } else {
654
+ $subject = get_bloginfo() .' - Backup did not complete successfully.';
655
+ $message = '<b>Your backup did not complete successfully.</b><br/><br/>';
656
+ }
657
+
658
+ $local_start_datetime = get_date_from_gmt(date( 'Y-m-d H:i:s',$start_timestamp));
659
+ $local_end_datetime = get_date_from_gmt(date( 'Y-m-d H:i:s',$end_timestamp));
660
+ $message .= 'WordPress Site: <a href="' . home_url() . '" target="_blank">' . home_url() .'</a><br/>';
661
+ $message .= 'Backup date: ' . $local_start_datetime . '<br/>';
662
+ $message .= 'Number of backups completed with WP BackItUp: ' . $WPBackitup->backup_count() . '<br/>';
663
+
664
+ $message .= 'Completion Code: ' . $backup_job->backup_id .'-'. $processing_minutes .'-' .$processing_seconds .'<br/>';
665
+ $message .= 'WP BackItUp Version: ' . WPBACKITUP__VERSION . '<br/>';
666
+
667
+
668
+ $message .= '<br/>';
669
+
670
+
671
+ //Add the completed steps on success
672
+ if($success) {
673
+ $message .='<b>Steps Completed</b><br/>';
674
+
675
+ //Add the completed statuses
676
+ foreach ($status_array as $status_key => $status_value) {
677
+ if ($status_value==2) {
678
+ foreach ($status_description as $msg_key => $msg_value) {
679
+ if ($status_key==$msg_key) {
680
+ $message .= $msg_value . '<br/>';
681
+ break;
682
+ }
683
+ }
684
+ }
685
+ }
686
+ } else {
687
+ //Error occurred
688
+ $message .= '<br/>';
689
+ $message .= 'Errors:<br/>' . get_error_message($err);
690
+ }
691
+
692
+ $term='success';
693
+ if(!$success)$term='error';
694
+ $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/>';
695
+
696
+ $notification_email = $WPBackitup->get_option('notification_email');
697
+ if($notification_email)
698
+ $utility->send_email($notification_email,$subject,$message);
699
+
700
+ $logger->log_info(__function__,"End");
701
+ }
702
+
703
+ function cleanup_on_failure($path){
704
+ global $logger;
705
+ global $wp_backup;
706
+
707
+ if (WPBACKITUP__DEBUG===true){
708
+ $logger->log('Cleanup On Fail suspended: debug on.');
709
+ }
710
+ else{
711
+ $wp_backup->cleanup_unfinished_backups();
712
+ }
713
+ }
714
+
715
+ function write_fatal_error_status($status_code) {
716
+ global $status_array,$active,$failure;
717
+
718
+ //Find the active status and set to failure
719
+ foreach ($status_array as $key => $value) {
720
+ if ($value==$active){
721
+ $status_array[$key]=$failure;
722
+ }
723
+ }
724
+
725
+ write_status();
726
+ write_response_file_error($status_code);
727
+ }
728
+
729
+ function write_warning_status($status_code) {
730
+ global $status_array,$active,$warning;
731
+
732
+ //Find the active status and set to failure
733
+ foreach ($status_array as $key => $value) {
734
+ if ($value==$active){
735
+ $status_array[$key]=$warning;
736
+ }
737
+ }
738
+
739
+ write_status();
740
+ }
741
+
742
+ //function write_warning_status($status_code) {
743
+ // global $status_array,$warning;
744
+ //
745
+ // //Add warning to array
746
+ // $status_array[$status_code]=$warning;
747
+ // write_status();
748
+ //}
749
+
750
+ function write_status() {
751
+ global $status_array;
752
+ $fh=getStatusLog();
753
+
754
+ foreach ($status_array as $key => $value) {
755
+ fwrite($fh, '<div class="' . $key . '">' . $value .'</div>');
756
+ }
757
+
758
+ fclose($fh);
759
+ }
760
+
761
+ function set_status($process,$status,$flush){
762
+ global $status_array,$complete;
763
+
764
+ $status_array[$process]=$status;
765
+
766
+ //Mark all the others complete and flush
767
+ foreach ($status_array as $key => $value) {
768
+ if ($process==$key) {
769
+ break;
770
+ }else{
771
+ $status_array[$key]=$complete;
772
+ }
773
+ }
774
+
775
+ if ($flush) write_status();
776
+ }
777
+
778
+ function set_status_success(){
779
+ global $status_array,$complete,$success;
780
+
781
+ //Mark all the others complete and flush
782
+ foreach ($status_array as $key => $value) {
783
+ $status_array[$key]=$complete;
784
+ }
785
+
786
+ $status_array['finalinfo']=$success;
787
+ write_status();
788
+ }
789
+
790
+ //Get Status Log
791
+ function getStatusLog(){
792
+ global $logger;
793
+
794
+ $status_file_path = WPBACKITUP__PLUGIN_PATH .'/logs/backup_status.log';
795
+ $filesystem = new WPBackItUp_FileSystem($logger);
796
+ return $filesystem->get_file_handle($status_file_path);
797
+
798
+ }
799
+
800
+ //write Response Log
801
+ function write_response_processing($message) {
802
+
803
+ $jsonResponse = new stdClass();
804
+ $jsonResponse->backupStatus = 'processing';
805
+ $jsonResponse->backupMessage = $message;
806
+
807
+ write_response_file($jsonResponse);
808
+ }
809
+
810
+
811
+ //write Response Log
812
+ function write_response_file_error($error) {
813
+
814
+ $jsonResponse = new stdClass();
815
+ $jsonResponse->backupStatus = 'error';
816
+ $jsonResponse->backupMessage = get_error_message($error);
817
+
818
+ write_response_file($jsonResponse);
819
+ }
820
+
821
+ //write Response Log
822
+ function write_response_file_success() {
823
+ global $WPBackitup,$wp_backup,$logger;
824
+
825
+ $jsonResponse = new stdClass();
826
+ $jsonResponse->backupStatus = 'success';
827
+ $jsonResponse->backupMessage = 'success';
828
+ $jsonResponse->backupFile = $wp_backup->backup_filename;
829
+ $jsonResponse->backupZipLink = WPBACKITUP__BACKUP_URL . '/' . $wp_backup->backup_filename;
830
+ $jsonResponse->backupLicense = $WPBackitup->license_active();
831
+ $jsonResponse->backupRetained = $wp_backup->backup_retained_number;
832
+
833
+ if (file_exists($logger->logFilePath)) {
834
+ $jsonResponse->backupLogLink = basename($logger->logFileName,'.log');
835
+ }
836
+
837
+ write_response_file($jsonResponse);
838
+ }
839
+
840
+ //write Response Log
841
+ function write_response_file($JSON_Response) {
842
+ global $logger;
843
+
844
+ $json_response = json_encode($JSON_Response);
845
+ $logger->log('Write response file:' . $json_response);
846
+
847
+ $fh=get_response_file();
848
+ fwrite($fh, $json_response);
849
+ fclose($fh);
850
+ }
851
+
852
+ //Get Response Log
853
+ function get_response_file() {
854
+ global $logger;
855
+ $response_file_path = WPBACKITUP__PLUGIN_PATH .'logs/backup_response.log';
856
+ $filesytem = new WPBackItUp_FileSystem($logger);
857
+ return $filesytem->get_file_handle($response_file_path,false);
858
+ }
859
+
860
+
861
+ /**
862
+ * Get error message
863
+ *
864
+ * @param $error_code
865
+ *
866
+ * @return string
867
+ */
868
+ function get_error_message($error_code){
869
+
870
+ $error_message_array = array(
871
+ '101' =>'(101) Unable to create a new directory for backup. Please check your CHMOD settings of your wp-backitup backup directory',
872
+ '102'=> '(102) Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory',
873
+ '103'=> '(103) Unable to backup your files. Please try again',
874
+ '104'=> '(104) Unable to export your database. Please try again',
875
+ '105'=> '(105) Unable to export site information file. Please try again',
876
+ '106'=> '(106) Unable to cleanup your backup directory',
877
+ '107'=> '(107) Unable to compress(zip) your backup. Please try again',
878
+ '108'=> '(108) Unable to backup your site data files. Please try again',
879
+ '109'=> '(109) Unable to finalize backup. Please try again',
880
+ '114'=> '(114) Your database was accessible but an export could not be created. Please contact support by clicking the get support link on the right. Please let us know who your host is when you submit the request',
881
+ '120'=> '(120) Unable to backup your themes. Please try again',
882
+ '121'=> '(121) Unable to backup your plugins. Please try again',
883
+ '122'=> '(122) Unable to backup your uploads. Please try again',
884
+ '123'=> '(123) Unable to backup your miscellaneous files. Please try again',
885
+ '125'=> '(125) Unable to compress your backup because there is no zip utility available. Please contact support',
886
+ '126'=> '(126) Unable to validate your backup. Please try again',
887
+
888
+ '2101' =>'(2101) Unable to create a new directory for backup. Please check your CHMOD settings of your wp-backitup backup directory',
889
+ '2102'=> '(2102) Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory',
890
+ '2103'=> '(2103) Unable to backup your files. Please try again',
891
+ '2104'=> '(2104) Unable to export your database. Please try again',
892
+ '2105'=> '(2105) Unable to export site information file. Please try again',
893
+ '2106'=> '(2106) Unable to cleanup your backup directory',
894
+ '2107'=> '(2107) Unable to compress(zip) your backup. Please try again',
895
+ '2108'=> '(2108) Unable to backup your site data files. Please try again',
896
+ '2109'=> '(2109) Unable to finalize backup. Please try again',
897
+ '2114'=> '(2114) Your database was accessible but an export could not be created. Please contact support by clicking the get support link on the right. Please let us know who your host is when you submit the request',
898
+ '2120'=> '(2120) Unable to backup your themes. Please try again',
899
+ '2121'=> '(2121) Unable to backup your plugins. Please try again',
900
+ '2122'=> '(2122) Unable to backup your uploads. Please try again',
901
+ '2123'=> '(2123) Unable to backup your miscellaneous files. Please try again',
902
+ '2125'=> '(2125) Unable to compress your backup because there is no zip utility available. Please contact support',
903
+ '2126'=> '(2126) Unable to validate your backup. Please try again',
904
+ );
905
+
906
+ $error_message = '(999) Unexpected error';
907
+ if (array_key_exists($error_code,$error_message_array)) {
908
+ $error_message = $error_message_array[ $error_code ];
909
+ }
910
+
911
+ return $error_message;
912
+ }
913
+
914
+
915
+
lib/includes/job_cleanup.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!defined ('ABSPATH')) die('No direct access allowed');
2
+ @set_time_limit(WPBACKITUP__SCRIPT_TIMEOUT_SECONDS);
3
+
4
+ /**
5
+ * WP Backitup Backup
6
+ *
7
+ * @package WP Backitup
8
+ *
9
+ * @author cssimmon
10
+ *
11
+ */
12
+
13
+ /*** Includes ***/
14
+
15
+ if( !class_exists( 'WPBackItUp_Logger' ) ) {
16
+ include_once 'class-logger.php';
17
+ }
18
+
19
+ if( !class_exists( 'WPBackItUp_Utility' ) ) {
20
+ include_once 'class-utility.php';
21
+ }
22
+
23
+
24
+ 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
+ // include file system class
39
+ if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
40
+ include_once 'class-filesystem.php';
41
+ }
42
+
43
+ // include job class
44
+ if( !class_exists( 'WPBackItUp_Job' ) ) {
45
+ include_once 'class-job.php';
46
+ }
47
+
48
+ /*** Globals ***/
49
+ global $WPBackitup;
50
+
51
+ global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
52
+ $inactive=0;
53
+ $active=1;
54
+ $complete=2;
55
+ $failure=-1;
56
+ $warning=-2;
57
+ $success=99;
58
+
59
+
60
+ //**************************//
61
+ // SINGLE THREAD BACKUPS //
62
+ //**************************//
63
+ $logger_tasks = new WPBackItUp_Logger(false,null,'debug_tasks');
64
+ $backup_process_id = uniqid();
65
+
66
+
67
+ //If there is a queued or active job then add a resume check
68
+ if ('scheduled'==$this->backup_type){
69
+ wp_schedule_single_event( time()+30, 'wpbackitup_run_cleanup_tasks');
70
+ }
71
+
72
+ //Make sure backup is NOT already running before you run the current task
73
+ if (!WPBackItUp_Backup::start()) {
74
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Cleanup job cant acquire job lock.');
75
+ return; //nothing to do
76
+ }else{
77
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Cleanup job lock acquired.');
78
+ }
79
+ //**************************//
80
+
81
+
82
+ //**************************//
83
+ // Task Handling //
84
+ //**************************//
85
+ global $backup_job;
86
+ $backup_job=null;
87
+ $current_task= null;
88
+
89
+ $backup_error=false;
90
+
91
+
92
+ $backup_job = WPBackItUp_Job::get_job('cleanup');
93
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Check for available job');
94
+ if ($backup_job){
95
+
96
+ //Get the next task in the stack
97
+ $next_task = $backup_job->get_next_task();
98
+ if (false!==$next_task){
99
+ $backup_id=$backup_job->backup_id;
100
+ $current_task=$next_task;
101
+
102
+ //If task contains error then timeout has occurred
103
+ if (strpos($current_task,'error') !== false){
104
+ $backup_error=true;
105
+ }
106
+
107
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Available Task Found:' . $current_task);
108
+
109
+ }else{
110
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','No available tasks found.');
111
+ WPBackItUp_Backup::end(); //release lock
112
+ return;
113
+ }
114
+ }else {
115
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','No backup job available.');
116
+ wp_clear_scheduled_hook( 'wpbackitup_run_cleanup_tasks');
117
+ WPBackItUp_Backup::end(); //release lock
118
+ return;
119
+ }
120
+
121
+
122
+ //Should only get here when there is a task to run
123
+ $logger_tasks->log_info(__METHOD__.'(' .$backup_process_id .')','Run Backup task:' .$current_task);
124
+
125
+ //*************************//
126
+ //*** MAIN BACKUP CODE ***//
127
+ //*************************//
128
+
129
+ //Get the backup ID
130
+ $job_name = get_job_name($backup_job->backup_id);
131
+
132
+ global $logger;
133
+ $logger = new WPBackItUp_Logger(false,null,$job_name);
134
+
135
+ global $wp_backup;
136
+ $wp_backup = new WPBackItUp_Backup($logger,$job_name,$WPBackitup->backup_type);
137
+
138
+
139
+ //*** SCHEDULED TASKS ***//
140
+
141
+ //Run cleanup task
142
+ if ('scheduled_cleanup'==$current_task) {
143
+
144
+ //Init
145
+ $logger->log('***BEGIN JOB***');
146
+ $logger->log_sysinfo();
147
+
148
+ $logger->log('Scheduled Cleanup requested');
149
+
150
+ $logger->log( '**CLEAN UNFINISHED BACKUPS**' );
151
+ $wp_backup->cleanup_unfinished_backups();
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**' );
157
+
158
+ $backup_job->set_task_complete();
159
+
160
+ }
161
+
162
+ end_job(null,true);
163
+
164
+ //*** END SCHEDULED TASKS ***//
165
+
166
+ /******************/
167
+ /*** Functions ***/
168
+ /******************/
169
+ function get_job_name($timestamp){
170
+
171
+ $fileUTCDateTime=$timestamp;//current_time( 'timestamp' );
172
+ $localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
173
+ $job_name = 'cleanup_' .$localDateTime;
174
+
175
+ return $job_name;
176
+
177
+ }
178
+
179
+ function end_job($err=null, $success=null){
180
+ global $WPBackitup, $logger, $backup_job;
181
+ $logger->log_info(__METHOD__,"Begin");
182
+
183
+ WPBackItUp_Backup::end(); //Release the lock
184
+ $current_datetime = current_time( 'timestamp' );
185
+ $WPBackitup->set_cleanup_lastrun_date($current_datetime);
186
+
187
+ $util = new WPBackItUp_Utility($logger);
188
+ $seconds = $util->timestamp_diff_seconds($backup_job->get_job_start_time(),$backup_job->get_job_end_time());
189
+
190
+ $processing_minutes = round($seconds / 60);
191
+ $processing_seconds = $seconds % 60;
192
+
193
+ $logger->log('Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
194
+
195
+ if (true===$success) $logger->log("Cleanup completed: SUCCESS");
196
+ if (false===$success) $logger->log("Cleanup completed: ERROR");
197
+ $logger->log("*** END JOB ***");
198
+ $logger->close_file();
199
+
200
+ echo('cleanup has completed');
201
+ exit(0);
202
+ }
203
+
lib/includes/{restore.php → job_restore.php} RENAMED
@@ -11,6 +11,12 @@
11
  */
12
 
13
  /*** Includes ***/
 
 
 
 
 
 
14
  // include backup class
15
  if( !class_exists( 'WPBackItUp_Restore' ) ) {
16
  include_once 'class-restore.php';
@@ -26,6 +32,12 @@ if( !class_exists( 'WPBackItUp_SQL' ) ) {
26
  include_once 'class-sql.php';
27
  }
28
 
 
 
 
 
 
 
29
  /*** Globals ***/
30
  global $WPBackitup;
31
  global $table_prefix; //this is from wp-config
@@ -50,16 +62,18 @@ $status_array = array(
50
  'validation'=>$inactive,
51
  'restore_point'=>$inactive,
52
  'database'=>$inactive,
53
- 'wpcontent'=>$inactive,
 
 
 
54
  'cleanup'=>$inactive
55
  );
56
 
57
- $fileUTCDateTime=current_time( 'timestamp' );
58
- $localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
59
- $log_filename = 'restorelog_'.'_' .$localDateTime;
60
 
61
  global $logger;
62
- $logger = new WPBackItUp_Logger(false,null,$log_filename,true);
63
 
64
  global $wp_restore; //Eventually everything will be migrated to this class
65
  $wp_restore = new WPBackItUp_Restore($logger);
@@ -69,7 +83,16 @@ $wp_restore = new WPBackItUp_Restore($logger);
69
  //*** MAIN CODE ***//
70
  //*****************//
71
  $logger->log('***BEGIN RESTORE***');
72
- $logger->logConstants();
 
 
 
 
 
 
 
 
 
73
 
74
  if (!$this->license_active()){
75
  $logger->log('Restore is not available because license is not active.');
@@ -116,15 +139,21 @@ unzip_backup($backup_file_path,$wp_restore->restore_folder_path);
116
  set_status('unzipping',$complete,false);
117
  $logger->log('**END UNZIP BACKUP**');
118
 
119
-
120
  $logger->log('**VALIDATE BACKUP**');
121
  set_status('validation',$active,true);
122
  $restoration_dir_path=validate_restore_folder($wp_restore->restore_folder_path);
123
  $logger->log('**END VALIDATE BACKUP**');
124
 
125
 
 
 
 
 
 
 
 
126
  $logger->log('**VALIDATE SQL FILE EXISTS**');
127
- $backupSQLFile = $restoration_dir_path . WPBACKITUP__SQL_DBBACKUP_FILENAME;
128
  validate_SQL_exists($backupSQLFile);
129
  $logger->log('**END VALIDATE SQL FILE EXISTS**');
130
 
@@ -137,9 +166,10 @@ $user_pass = get_user_pass($user_id);
137
  $user_email = get_user_email($user_id);
138
  $logger->log('**END GET SITE VALUES FROM DB**');
139
 
 
140
  //Collect previous backup site url start
141
  $logger->log('**GET backupsiteinfo.txt VALUES**');
142
- $import_siteinfo_lines = file($restoration_dir_path .'backupsiteinfo.txt');
143
  $import_siteurl = str_replace("\n", '',trim($import_siteinfo_lines[0]));
144
  $current_siteurl = trim($siteurl ,'/');
145
  $import_table_prefix = str_replace("\n", '',$import_siteinfo_lines[1]);
@@ -154,6 +184,7 @@ if($table_prefix !=$import_table_prefix) {
154
 
155
  $logger->log('**END GET backupsiteinfo.txt VALUES**');
156
 
 
157
  $logger->log('**CREATE RESTORE POINT**');
158
  //Create restore point for DB
159
  set_status('validation',$complete,false);
@@ -169,9 +200,9 @@ set_status('database',$active,true);
169
  import_backedup_database($backupSQLFile,$RestorePoint_SQL);
170
  $logger->log('**END RESTORE DATABASE**');
171
 
172
-
173
  $logger->log('**UPDATE DATABASE VALUES**');
174
  //FAILURES AFTER THIS POINT SHOULD REQUIRE ROLLBACK OF DB
 
175
  update_user_credentials($import_table_prefix, $user_login, $user_pass, $user_email, $user_id);
176
  update_siteurl($import_table_prefix, $current_siteurl);
177
  update_homeurl($import_table_prefix, $homeurl);
@@ -181,37 +212,66 @@ $logger->log('**END UPDATE DATABASE VALUES**');
181
  set_status('database',$complete,false);
182
 
183
 
184
-
185
  //***DEAL WITH WPCONTENT NOW ***
186
- set_status('wpcontent',$active,true);
187
  $logger->log('**DELETE PLUGINS**');
188
- delete_plugins_content();
 
 
 
189
  $logger->log('**END DELETE PLUGINS**');
190
 
 
 
 
 
 
191
  $logger->log('**DELETE THEMES**');
192
- delete_themes_content();
 
 
193
  $logger->log('**END DELETE THEMES**');
194
 
195
- $logger->log('**DELETE WPCONTENT**');
196
- //delete whatever is left
197
- $wpcontent_folder=WPBACKITUP__CONTENT_PATH;
198
- delete_wpcontent_content($wpcontent_folder);
199
- $logger->log('**END DELETE WPCONTENT**');
200
-
201
- $logger->log('**RESTORE WPCONTENT**');
202
- restore_wpcontent($restoration_dir_path);
203
- set_status('wpcontent',$complete,false);
204
- $logger->log('**END DELETE WPCONTENT**');
205
-
206
- $logger->log('**VALIDATE WPCONTENT**');
207
- validate_wpcontent($restoration_dir_path,$wpcontent_folder);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  $logger->log('**END VALIDATE WPCONTENT**');
209
 
210
- $logger->log('**UPDATE PERMALINKS**');
211
- update_permalinks();
212
- $logger->log('**END UPDATE PERMALINKS**');
213
-
214
-
215
  $logger->log('**CLEANUP**');
216
  set_status('cleanup',$active,true);
217
  cleanup_restore_folder($restoration_dir_path);
@@ -221,20 +281,38 @@ $logger->log('**END CLEANUP**');
221
  set_status_success();
222
  $logger->log('Restore completed successfully');
223
  $logger->log('***END RESTORE***');
224
- die();
 
 
 
 
 
 
 
 
 
225
 
226
  /******************/
227
  /*** Functions ***/
228
  /******************/
 
 
 
 
 
 
 
 
 
229
 
230
  //Get Status Log
231
  function get_restore_Log() {
232
- $log = WPBACKITUP__PLUGIN_PATH .'/logs/status.log';
233
- if (file_exists($log)){
234
- unlink($log);
235
- }
236
- $fh = fopen($log, 'w+') or die( "Can't write to log file" );
237
- return $fh;
238
  }
239
 
240
  function write_fatal_error_status($status_code) {
@@ -291,11 +369,19 @@ function create_restore_folder($path) {
291
  $logger->log('Create restore folder:' .$path);
292
 
293
  $fileSystem = new WPBackItUp_FileSystem($logger);
294
- if(!$fileSystem->create_dir($path)) {
295
  $logger->log('Error: Cant create restore folder :'. $path);
296
  write_fatal_error_status('error222');
297
  die();
298
  }
 
 
 
 
 
 
 
 
299
  $logger->log('Restore folder created:' .$path);
300
  }
301
 
@@ -315,18 +401,50 @@ function unzip_backup($backup_file_path,$restore_folder_root){
315
  //unzip the upload
316
  $logger->log('Unzip the backup file source:' .$backup_file_path);
317
  $logger->log('Unzip the backup file target:' .$restore_folder_root);
318
- $zip = new ZipArchive;
319
- $res = $zip->open($backup_file_path);
320
- if ($res === TRUE) {
321
- $zip->extractTo($restore_folder_root);
322
- $zip->close();
323
- } else {
324
- $logger->log('Error: Cant unzip backup:'.$backup_file_path);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  write_fatal_error_status('error203');
326
  delete_restore_folder();
327
  die();
328
  }
329
- $logger->log('Backup file unzipped: ' .$restore_folder_root);
330
  }
331
 
332
  //Validate the restore folder
@@ -351,7 +469,7 @@ function validate_restore_folder($restore_folder_root){
351
 
352
  //Validate the restoration
353
  $logger->log('Validate restoration directory: ' . $restoration_dir_path .'backupsiteinfo.txt');
354
- if(!glob($restoration_dir_path .'backupsiteinfo.txt') ){
355
  $logger->log('Error: backupsiteinfo.txt missing from restore folder: ' .$restoration_dir_path);
356
  write_fatal_error_status('error204');
357
  delete_restore_folder(); //delete the restore folder if bad
@@ -633,6 +751,23 @@ function delete_themes_content(){
633
  $logger->log('Themes content deleted:' .$themes_folder);
634
  }
635
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636
  //Restore all wp content from zip
637
  function restore_wpcontent($restoration_dir_path){
638
  global $logger;
@@ -650,19 +785,142 @@ function restore_wpcontent($restoration_dir_path){
650
  $logger->log('Content folder copied successfully');
651
  }
652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
653
  //Restore all wp content from zip
654
  function validate_wpcontent($source_dir_path,$target_dir_path){
655
  global $logger;
656
- $logger->log('Validate content folder TO:' .$source_dir_path);
657
- $logger->log('Validate content folder FROM:' .$target_dir_path);
658
 
659
  $ignore = array(WPBACKITUP__PLUGIN_FOLDER,'debug.log','backupsiteinfo.txt','db-backup.sql');
660
  $filesystem = new WPBackItUp_FileSystem($logger);
661
  if(!$filesystem->recursive_validate($source_dir_path. '/', $target_dir_path . '/',$ignore)) {
662
- $logger->log('Error: Content folder is not the same as backup.');
 
 
663
  }
664
 
665
- $logger->log('Content folder validation complete.');
666
  }
667
 
668
  //Delete the restoration directory
@@ -679,13 +937,13 @@ function cleanup_restore_folder($restoration_dir_path){
679
  function update_permalinks(){
680
  global $wp_rewrite, $logger;
681
  try {
682
- $old_permalink_structure = $wp_rewrite->permalink_structure;
683
- $wp_rewrite->set_permalink_structure($old_permalink_structure);
684
- $wp_rewrite->flush_rules( true );//Update permalinks - hard flush
685
  }catch(Exception $e) {
686
- $logger->log('(restore.update_permalinks) Exception: ' .$e);
687
  return false;
688
  }
689
- $logger->log('(restore.update_permalinks) Permalinks updated.');
690
  return true;
691
  }
11
  */
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';
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
+ }
39
+
40
+
41
  /*** Globals ***/
42
  global $WPBackitup;
43
  global $table_prefix; //this is from wp-config
62
  'validation'=>$inactive,
63
  'restore_point'=>$inactive,
64
  'database'=>$inactive,
65
+ 'plugins'=>$inactive,
66
+ 'themes'=>$inactive,
67
+ 'uploads'=>$inactive,
68
+ 'other'=>$inactive,
69
  'cleanup'=>$inactive
70
  );
71
 
72
+ //Get the backup ID
73
+ $job_log_name = get_job_log_name();
 
74
 
75
  global $logger;
76
+ $logger = new WPBackItUp_Logger(false,null,$job_log_name,true);
77
 
78
  global $wp_restore; //Eventually everything will be migrated to this class
79
  $wp_restore = new WPBackItUp_Restore($logger);
83
  //*** MAIN CODE ***//
84
  //*****************//
85
  $logger->log('***BEGIN RESTORE***');
86
+ $logger->log_sysinfo();
87
+
88
+ //Is backup running
89
+ if ( ! WPBackItUp_Backup::start()) {
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
  if (!$this->license_active()){
98
  $logger->log('Restore is not available because license is not active.');
139
  set_status('unzipping',$complete,false);
140
  $logger->log('**END UNZIP BACKUP**');
141
 
 
142
  $logger->log('**VALIDATE BACKUP**');
143
  set_status('validation',$active,true);
144
  $restoration_dir_path=validate_restore_folder($wp_restore->restore_folder_path);
145
  $logger->log('**END VALIDATE BACKUP**');
146
 
147
 
148
+ //Set all the path information
149
+ $site_data_path=$restoration_dir_path . 'site-data/';
150
+ $plugins_path=$restoration_dir_path . 'wp-content-plugins/';
151
+ $themes_path=$restoration_dir_path . 'wp-content-themes/';
152
+ $other_path=$restoration_dir_path . 'wp-content-other/';
153
+ $uploads_path=$restoration_dir_path . 'wp-content-uploads/';
154
+
155
  $logger->log('**VALIDATE SQL FILE EXISTS**');
156
+ $backupSQLFile = $site_data_path. WPBACKITUP__SQL_DBBACKUP_FILENAME;
157
  validate_SQL_exists($backupSQLFile);
158
  $logger->log('**END VALIDATE SQL FILE EXISTS**');
159
 
166
  $user_email = get_user_email($user_id);
167
  $logger->log('**END GET SITE VALUES FROM DB**');
168
 
169
+
170
  //Collect previous backup site url start
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]);
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);
200
  import_backedup_database($backupSQLFile,$RestorePoint_SQL);
201
  $logger->log('**END RESTORE DATABASE**');
202
 
 
203
  $logger->log('**UPDATE DATABASE VALUES**');
204
  //FAILURES AFTER THIS POINT SHOULD REQUIRE ROLLBACK OF DB
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);
212
  set_status('database',$complete,false);
213
 
214
 
 
215
  //***DEAL WITH WPCONTENT NOW ***
216
+
217
  $logger->log('**DELETE PLUGINS**');
218
+ $target_plugins_path=WPBACKITUP__PLUGINS_ROOT_PATH;
219
+ set_status('plugins',$active,true);
220
+ $plugin_ignore = array(WPBACKITUP__PLUGIN_FOLDER);
221
+ delete_folder_content($target_plugins_path,$plugin_ignore);
222
  $logger->log('**END DELETE PLUGINS**');
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);
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
  /*** Functions ***/
297
  /******************/
298
+ function get_job_log_name(){
299
+
300
+ $fileUTCDateTime=current_time( 'timestamp' );
301
+ $localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
302
+ $job_log_name = 'job_restore_' .$localDateTime;
303
+
304
+ return $job_log_name;
305
+
306
+ }
307
 
308
  //Get Status Log
309
  function get_restore_Log() {
310
+ global $logger;
311
+
312
+ $status_file_path = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
313
+ $filesystem = new WPBackItUp_FileSystem($logger);
314
+ return $filesystem->get_file_handle($status_file_path);
315
+
316
  }
317
 
318
  function write_fatal_error_status($status_code) {
369
  $logger->log('Create restore folder:' .$path);
370
 
371
  $fileSystem = new WPBackItUp_FileSystem($logger);
372
+ if( ! $fileSystem->create_dir($path)) {
373
  $logger->log('Error: Cant create restore folder :'. $path);
374
  write_fatal_error_status('error222');
375
  die();
376
  }
377
+
378
+ //create index.html
379
+ $restore_index = $path .'/index.html';
380
+ if( !is_file($restore_index) ) {
381
+ $dfh = fopen( $restore_index, 'a' );
382
+ fclose( $dfh );
383
+ }
384
+
385
  $logger->log('Restore folder created:' .$path);
386
  }
387
 
401
  //unzip the upload
402
  $logger->log('Unzip the backup file source:' .$backup_file_path);
403
  $logger->log('Unzip the backup file target:' .$restore_folder_root);
404
+
405
+ if (!class_exists('ZipArchive')){
406
+ $logger->log('Zip Archive Class is not available.');
407
+ write_fatal_error_status('error235');
408
+ delete_restore_folder();
409
+ die();
410
+ }
411
+
412
+ $filesystem = new WPBackItUp_FileSystem($logger);
413
+ $zip_extract_root_path=$restore_folder_root .'/' .basename($backup_file_path,'.zip');
414
+ if (!$filesystem->create_dir($zip_extract_root_path)){
415
+ $logger->log('Unable to create extract root folder:'.$zip_extract_root_path);
416
+ write_fatal_error_status('error203');
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
  //Validate the restore folder
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
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
  //Restore all wp content from zip
772
  function restore_wpcontent($restoration_dir_path){
773
  global $logger;
785
  $logger->log('Content folder copied successfully');
786
  }
787
 
788
+
789
+ //Restore other content folders
790
+ function restore_other_folders($source_path,$target_other_root,$ignore) {
791
+ global $logger;
792
+ $logger->log_info(__METHOD__,'Begin');
793
+
794
+ $target_other_root =rtrim($target_other_root, '/') . '/';
795
+
796
+ $logger->log_info(__METHOD__,'Source Path:' .$source_path);
797
+ $logger->log_info(__METHOD__,'Target Path:' .$target_other_root);
798
+ $logger->log_info(__METHOD__,'Ignore:');
799
+ $logger->log($ignore);
800
+
801
+ foreach(glob($source_path. '*',GLOB_ONLYDIR ) as $dir){
802
+ $source_other_folder=$dir .'/';
803
+ $target_other_folder = $target_other_root .basename($dir);
804
+
805
+ if( ! in_array(basename($dir), $ignore) ) {
806
+ $logger->log_info(__METHOD__,'Restoring FROM:' .$source_other_folder );
807
+ $logger->log_info(__METHOD__,'Restoring TO:' .$target_other_folder);
808
+
809
+ restore_folder($source_other_folder,$target_other_folder);
810
+ }
811
+ }
812
+
813
+ //Restore the files in the root
814
+ $logger->log_info(__METHOD__,'Restore other files in wpcontent root');
815
+ $files = array_filter(glob($source_path. '*'), 'is_file');
816
+ $filesystem = new WPBackItUp_FileSystem($logger);
817
+ foreach ($files as $file){
818
+ $target_other_file = $target_other_root .basename($file);
819
+
820
+ if( ! in_array(basename($file), $ignore) ) {
821
+ $logger->log_info( __METHOD__, 'Restore file from:' . $file );
822
+ $logger->log_info( __METHOD__, 'Restore file to:' . $target_other_file );
823
+
824
+ if (! $filesystem->copy_file($file,$target_other_file) ){
825
+ $logger->log('Error: File was not copied successfully');
826
+ write_warning_status('error219');
827
+ restore_database();
828
+ delete_restore_folder();
829
+ die();
830
+ }
831
+ }
832
+ }
833
+
834
+ $logger->log_info(__METHOD__,'All Others restored successfully.');
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
+ // $logger->log_info(__METHOD__,'Source Path:' .$source_path);
845
+ // $logger->log_info(__METHOD__,'Target Path:' .$target_other_root);
846
+ // $logger->log_info(__METHOD__,'Ignore:');
847
+ // $logger->log($ignore);
848
+
849
+ foreach(glob($source_path. '*',GLOB_ONLYDIR ) as $dir){
850
+ $source_other_folder=$dir .'/';
851
+ $target_other_folder = $target_other_root .basename($dir);
852
+
853
+ if( ! in_array(basename($dir), $ignore) ) {
854
+ // $logger->log_info(__METHOD__,'Validate FROM:' .$source_other_folder );
855
+ // $logger->log_info(__METHOD__,'Validate TO:' .$target_other_folder);
856
+
857
+ validate_wpcontent($source_other_folder,$target_other_folder);
858
+ }
859
+ }
860
+
861
+ //$logger->log_info(__METHOD__,'Validate other files in wpcontent root');
862
+ $files = array_filter(glob($source_path. '*'), 'is_file');
863
+ foreach ($files as $file){
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
+ if (! file_exists($target_other_file) ){
871
+ $logger->log_info(__METHOD__,'DIFF file doesnt exist: ' .$target_other_file);
872
+ }
873
+ }
874
+ }
875
+
876
+ }
877
+
878
+ //Restore content folder
879
+ function restore_folder($source_path,$target_path){
880
+ global $logger;
881
+ $logger->log('Copy content folder from:' .$source_path);
882
+ $logger->log('Copy content folder to:' .$target_path);
883
+
884
+ //add the / if needed
885
+ $target_path =rtrim($target_path, '/') . '/';
886
+
887
+ $filesystem = new WPBackItUp_FileSystem($logger);
888
+ $ignore = array(WPBACKITUP__PLUGIN_FOLDER, WPBACKITUP__BACKUP_FOLDER,WPBACKITUP__RESTORE_FOLDER, 'status.log','debug.log', WPBACKITUP__SQL_DBBACKUP_FILENAME, 'backupsiteinfo.txt');
889
+
890
+ //Make sure the root exists
891
+ if(!$filesystem->create_dir($target_path)) {
892
+ $logger->log('Error: Cant create root folder');
893
+ write_warning_status('error219');
894
+ restore_database();
895
+ delete_restore_folder();
896
+ die();
897
+ }
898
+
899
+ if(!$filesystem->recursive_copy($source_path,$target_path,$ignore)) {
900
+ $logger->log('Error: Content folder was not copied successfully');
901
+ write_warning_status('error219');
902
+ restore_database();
903
+ delete_restore_folder();
904
+ die();
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
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
  }
lib/includes/upload.php CHANGED
@@ -13,7 +13,7 @@
13
 
14
  /*** Globals ***/
15
  global $logger;
16
- $logger = new WPBackItUp_Logger(true,null,'upload');
17
  $backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
18
 
19
  //*****************//
13
 
14
  /*** Globals ***/
15
  global $logger;
16
+ $logger = new WPBackItUp_Logger(true,null,'debug_upload');
17
  $backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
18
 
19
  //*****************//
lib/index.html ADDED
File without changes
logs/index.html ADDED
File without changes
logs/status.log DELETED
@@ -1 +0,0 @@
1
- INSTALL PLACEHOLDER
 
readme.txt CHANGED
@@ -151,6 +151,17 @@ Our online documentation and full list of FAQs can be found at [www.wpbackitup.c
151
 
152
 
153
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
154
  = 1.9 =
155
  * New Features: Scheduled backups are now available.
156
  * New Feature: Allow only a single backup to be run at a time.
151
 
152
 
153
  == Changelog ==
154
+ = 1.9.1 =
155
+ * New Features: Long running backups are now supported.
156
+ * Update: Extensive Performance improvements
157
+ * Update: User experience improvements to backup.
158
+ * Update: Extensive updates to error handling and messaging
159
+ * Update: Enhancements to backup email notification.
160
+ * Update: Logging enhancements.
161
+ * Update: Automated cleanup uses file retention limits for all logs.
162
+ * Update: Security enhancements to prevent unwanted access to backup, restore and log folders.
163
+ * Fix: IFrame css definition changed to use wp-backitup namespace.
164
+
165
  = 1.9 =
166
  * New Features: Scheduled backups are now available.
167
  * New Feature: Allow only a single backup to be run at a time.
views/backup.php CHANGED
@@ -27,6 +27,7 @@
27
  // get retention number set
28
  $retain_archives = $this->backup_retained_number();
29
 
 
30
  $lite_registration_email = $this->lite_registration_email();
31
  $is_lite_registered = $this->is_lite_registered();
32
 
@@ -164,7 +165,7 @@ if (!$backup_folder_exists) {
164
  //Local Date Time
165
  $file_datetime = get_date_from_gmt(date('Y-m-d H:i:s', filemtime($file)), 'Y-m-d g:i a');
166
 
167
- $success_logExists = false;
168
  if ('zip'==$file_type) {
169
  $zip_exists = true;
170
  $log_file = str_replace( '.zip', '.log', $file );
@@ -185,7 +186,6 @@ if (!$backup_folder_exists) {
185
 
186
  <tr <?php echo $class ?> id="row<?php echo $i; ?>">
187
  <td><?php echo $file_datetime ?></td>
188
- <td><?php echo $filename ?></td>
189
 
190
  <?php if ($zip_exists) :?>
191
  <td><a href="<?php echo WPBACKITUP__BACKUP_URL ?>/<?php echo $filename; ?>">Download</a></td>
@@ -231,35 +231,31 @@ if (!$backup_folder_exists) {
231
 
232
  <!--backup status messages-->
233
  <ul class="backup-status">
234
- <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></li>
235
- <li class='backupdb'><?php _e('Backing-up database', $namespace); ?>...<span class='status-icon'><img class="backupdb-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>
236
- <li class='infofile'><?php _e('Creating backup information file', $namespace); ?>...<span class='status-icon'><img class="infofile-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>
237
- <li class='backupfiles'><?php _e('Backing up plugins, themes, and uploads', $namespace); ?>...<span class='status-icon'><img class="backupfiles-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>
238
- <li class='zipfile'><?php _e('Zipping backup directory', $namespace); ?>...<span class='status-icon'><img class="zipfile-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>
239
- <li class='cleanup'><?php _e('Cleaning up', $namespace); ?>...<span class='status-icon'><img class="cleanup-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>
 
 
 
 
240
  </ul>
241
 
242
- <!--backup error messages-->
243
- <div class="backup-errors">
244
- <span class="error101"><div class='isa_error'><?php _e('Error 101: Unable to create a new directory for backup. Please check your CHMOD settings of your wp-backitup backup directory', $namespace); ?>.</div></span>
245
- <span class="error102"><div class='isa_error'><?php _e('Error 102: Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory', $namespace); ?>.</div></span>
246
- <span class="error103"><div class='isa_error'><?php _e('Error 103: Unable to backup your files. Please try again', $namespace); ?>.</div></span>
247
- <span class="error104"><div class='isa_error'><?php _e('Error 104: Unable to backup your database. Please try again', $namespace); ?>.</div></span>
248
- <span class="error105"><div class='isa_error'><?php _e('Error 105: Unable to create site information file. Please try again', $namespace); ?>.</div></span>
249
- <span class="error106"><div class='isa_warning'><?php _e('Warning 106: Unable to cleanup your backup directory', $namespace); ?>.</div></span>
250
- <span class="error107"><div class='isa_error'><?php _e('Error 107: Unable to compress(zip) your backup. Please try again', $namespace); ?>.</div></span>
251
- <span class="error114"><div class='isa_error'><?php _e('Error 114: Your database was accessible but an export could not be created. Please contact support by clicking the get support link on the right. Please let us know who your host is when you submit the request', $namespace); ?>.</div></span>
252
- </div>
253
-
254
  <!--Error status messages-->
255
- <ul class="backup-unexpected-error">
256
- <span class='error999'><div class='isa_error'><?php _e('An unexpected error has occurred. ', $namespace); ?></div></span>
257
  </ul>
258
 
259
  <!--success messages-->
260
- <div class="backup-success">
261
- <span class='finalinfo'><div class='isa_success'><?php _e('Backup completed successfully. ', $namespace); ?></div></span>
262
- </div>
 
 
 
 
263
 
264
  </div>
265
 
@@ -284,6 +280,7 @@ if (!$backup_folder_exists) {
284
  <div class="widget">
285
  <h3 class="promo"><?php _e('Register WP BackItUp', $namespace); ?></h3>
286
  <p><?php _e('Enter your email address to register your version of WP BackItUp. Registered users will receive <b>special offers</b> and access to our world class <b>support</b> team.', $namespace); ?></p>
 
287
  <input type="text" name="email" id="email" placeholder="email address" value="<?php echo($lite_registration_email) ?>" />
288
  <div class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e("Register", $namespace) ?>" /></div>
289
  </div>
27
  // get retention number set
28
  $retain_archives = $this->backup_retained_number();
29
 
30
+ $lite_registration_first_name = $this->lite_registration_first_name();
31
  $lite_registration_email = $this->lite_registration_email();
32
  $is_lite_registered = $this->is_lite_registered();
33
 
165
  //Local Date Time
166
  $file_datetime = get_date_from_gmt(date('Y-m-d H:i:s', filemtime($file)), 'Y-m-d g:i a');
167
 
168
+ $logExists = false;
169
  if ('zip'==$file_type) {
170
  $zip_exists = true;
171
  $log_file = str_replace( '.zip', '.log', $file );
186
 
187
  <tr <?php echo $class ?> id="row<?php echo $i; ?>">
188
  <td><?php echo $file_datetime ?></td>
 
189
 
190
  <?php if ($zip_exists) :?>
191
  <td><a href="<?php echo WPBACKITUP__BACKUP_URL ?>/<?php echo $filename; ?>">Download</a></td>
231
 
232
  <!--backup status messages-->
233
  <ul class="backup-status">
234
+ <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>
235
+ <li class='backupdb'><?php _e('Backing up database', $namespace); ?>...<span class='status-icon'><img class="backupdb-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>
236
+ <li class='infofile'><?php _e('Creating backup information file', $namespace); ?>...<span class='status-icon'><img class="infofile-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><span class='wpbackitup-warning'><?php _e('Warning', $namespace); ?></span></li>
237
+ <li class='backup_themes'><?php _e('Backing up themes', $namespace); ?>...<span class='status-icon'><img class="backup_themes-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>
238
+ <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>
239
+ <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>
240
+ <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>
241
+ <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>
242
+ <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>
243
+ <li class='cleanup'><?php _e('Cleaning up', $namespace); ?>...<span class='status-icon'><img class="cleanup-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>
244
  </ul>
245
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  <!--Error status messages-->
247
+ <ul class="backup-error">
248
+ <!--Warning PlaceHolder-->
249
  </ul>
250
 
251
  <!--success messages-->
252
+ <ul class="backup-success">
253
+ <li class='isa_success'><?php _e('Backup completed successfully. ', $namespace); ?></li>
254
+ </ul>
255
+
256
+ <ul class="backup-warning">
257
+ <!--Warning PlaceHolder-->
258
+ </ul>
259
 
260
  </div>
261
 
280
  <div class="widget">
281
  <h3 class="promo"><?php _e('Register WP BackItUp', $namespace); ?></h3>
282
  <p><?php _e('Enter your email address to register your version of WP BackItUp. Registered users will receive <b>special offers</b> and access to our world class <b>support</b> team.', $namespace); ?></p>
283
+ <input type="text" name="first_name" id="first_name" placeholder="first name" value="<?php echo($lite_registration_first_name) ?>" /><br/>
284
  <input type="text" name="email" id="email" placeholder="email address" value="<?php echo($lite_registration_email) ?>" />
285
  <div class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e("Register", $namespace) ?>" /></div>
286
  </div>
views/index.html ADDED
File without changes
views/restore.php CHANGED
@@ -119,7 +119,7 @@ if (!$restore_folder_exists) {
119
  ?>
120
  <div class="widget">
121
  <h3><i class="fa fa-upload"></i> <?php _e('Upload', $namespace); ?></h3>
122
- <iframe id="upload_target" name="upload_target" src="">
123
  </iframe>
124
  <p><b><?php _e('Upload a WP BackItUp zip file to add it to your list of available backups.', $namespace); ?></b></p>
125
  <?php
@@ -164,7 +164,10 @@ if (!$restore_folder_exists) {
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="restore_point"><?php _e('Creating checkpoint', $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>
166
  <li class="database"><?php _e('Restoring database', $namespace); ?>...<span class='status-icon'><img class="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>
167
- <li class="wpcontent"><?php _e('Restoring plugins, themes and uploads', $namespace); ?>...<span class='status-icon'><img class="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>
 
 
 
168
  <li class="cleanup"><?php _e('Cleaning up restore files', $namespace); ?>...<span class='status-icon'><img class="cleanup-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>
169
  </ul>
170
  <p>
@@ -197,6 +200,9 @@ if (!$restore_folder_exists) {
197
  <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>
198
  <span class='error225'><div class='isa_error'><?php _e('Error 225: Restore option is only available to licensed WP BackItUp users', $namespace); ?>.</div></span>
199
  <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>
 
 
 
200
  </div>
201
 
202
  <!--restore success messages-->
119
  ?>
120
  <div class="widget">
121
  <h3><i class="fa fa-upload"></i> <?php _e('Upload', $namespace); ?></h3>
122
+ <iframe class="wp-backitup-iframe" id="upload_target" name="upload_target" src="">
123
  </iframe>
124
  <p><b><?php _e('Upload a WP BackItUp zip file to add it to your list of available backups.', $namespace); ?></b></p>
125
  <?php
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="restore_point"><?php _e('Creating checkpoint', $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>
166
  <li class="database"><?php _e('Restoring database', $namespace); ?>...<span class='status-icon'><img class="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>
167
+ <li class="plugins"><?php _e('Restoring plugins', $namespace); ?>...<span class='status-icon'><img class="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>
168
+ <li class="themes"><?php _e('Restoring themes', $namespace); ?>...<span class='status-icon'><img class="themes-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>
169
+ <li class="uploads"><?php _e('Restoring uploads', $namespace); ?>...<span class='status-icon'><img class="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></li>
170
+ <li class="other"><?php _e('Restoring everything else', $namespace); ?>...<span class='status-icon'><img class="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></li>
171
  <li class="cleanup"><?php _e('Cleaning up restore files', $namespace); ?>...<span class='status-icon'><img class="cleanup-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>
172
  </ul>
173
  <p>
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 extract the backup because there is no zip utility available. Please contact support.', $namespace); ?>.</div></span>
204
+ <span class="error250"><div class='isa_error'><?php _e('Error 250: WP BackItUp is unable to start the restore because a backup is running. Please wait for the backup to complete and then try again.', $namespace); ?>.</div></span>
205
+
206
  </div>
207
 
208
  <!--restore success messages-->
views/settings.php CHANGED
@@ -6,6 +6,8 @@
6
  $license_active = $this->license_active();
7
  $is_lite_registered = $this->is_lite_registered();
8
 
 
 
9
  //Hold off on this for a bit
10
  $disabled='';
11
  // if (!$license_active && !$is_lite_registered){
@@ -73,6 +75,22 @@
73
  <p class="submit"><input type="submit" name="Save_Logging" class="button-primary" value="<?php _e("Save", $namespace) ?>" /></p>
74
  </div>
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  <!--Debug Widget-->
77
  <?php if (WP_DEBUG===true) :?>
78
  <div class="widget">
6
  $license_active = $this->license_active();
7
  $is_lite_registered = $this->is_lite_registered();
8
 
9
+ $backup_batch_size=$this->backup_batch_size();
10
+
11
  //Hold off on this for a bit
12
  $disabled='';
13
  // if (!$license_active && !$is_lite_registered){
75
  <p class="submit"><input type="submit" name="Save_Logging" class="button-primary" value="<?php _e("Save", $namespace) ?>" /></p>
76
  </div>
77
 
78
+ <div class="widget">
79
+ <h3 class="promo"><i class="fa fa-wrench"></i> Advanced Settings</h3>
80
+ <p><b>These options should only be changed when working with WP BackItUp support.</b></p>
81
+ <input name="data[backup_batch_size]" id="wpbackitup_batch_size" type="text" size="2" value="<?php echo $backup_batch_size; ?>"/>
82
+ <label> Backup batch size</label>
83
+ <p class="submit"><input type="submit" name="Save_AdvancedSettings" class="button-primary" value="<?php _e("Save", $namespace) ?>" />
84
+ <?php
85
+ if ( false !== ( $msg = get_transient('batch_size_settings-error-number') ) && $msg)
86
+ {
87
+ echo '<p class="error">'.$msg.'</p>';
88
+ delete_transient('batch_size_settings-error-number');
89
+ }
90
+ ?>
91
+ </p>
92
+ </div>
93
+
94
  <!--Debug Widget-->
95
  <?php if (WP_DEBUG===true) :?>
96
  <div class="widget">
views/test.php DELETED
@@ -1,22 +0,0 @@
1
- <?php
2
-
3
- global $WPBackitup;
4
-
5
- $logger = new WPBackItUp_Logger(false);
6
-
7
- $backupCount = $WPBackitup->backup_count();
8
- $logger->log('Count: ' .$backupCount);
9
- $WPBackitup->increment_backup_count();
10
-
11
-
12
- $logger->log('HERE');
13
-
14
- //do_action('wpbackitup_resume_backup',$WPBackitup->backup_count());
15
- $current_time = time();
16
- //Add backup scheduled if doesnt exist
17
- wp_schedule_single_event( time()+30, 'wpbackitup_resume_backup');
18
-
19
-
20
-
21
-
22
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.9
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.9');
38
  define( 'WPBACKITUP__DEBUG', false );
39
  define( 'WPBACKITUP__MINIMUM_WP_VERSION', '3.0' );
40
  define( 'WPBACKITUP__ITEM_NAME', 'WP Backitup' );
@@ -58,9 +58,16 @@ define( 'WPBACKITUP__RESTORE_PATH',WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__
58
 
59
  define( 'WPBACKITUP__PLUGINS_ROOT_PATH',WP_PLUGIN_DIR );
60
  define( 'WPBACKITUP__THEMES_ROOT_PATH',get_theme_root() );
 
61
 
62
  define( 'WPBACKITUP__SQL_DBBACKUP_FILENAME', 'db-backup.sql');
63
 
 
 
 
 
 
 
64
  register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
65
  register_deactivation_hook( __FILE__, array( 'WPBackitup_Admin', 'deactivate' ) );
66
 
@@ -75,6 +82,37 @@ function wpbackitup_modify_cron_schedules($schedules) {
75
 
76
  add_filter('cron_schedules', 'wpbackitup_modify_cron_schedules', 30);
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  // The checks here before loading are for performance only - unless one of those conditions is met, then none of the hooks will ever be used
80
  if (!is_admin() && (!defined('DOING_CRON') || !DOING_CRON) && (!defined('XMLRPC_REQUEST') || !XMLRPC_REQUEST) && empty($_SERVER['SHELL']) && empty($_SERVER['USER'])) return;
@@ -85,6 +123,3 @@ require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-logger.php' );
85
  global $WPBackitup;
86
  $WPBackitup = WPBackitup_Admin::get_instance();
87
  $WPBackitup->initialize();
88
-
89
-
90
-
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.9.1
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.9.1');
38
  define( 'WPBACKITUP__DEBUG', false );
39
  define( 'WPBACKITUP__MINIMUM_WP_VERSION', '3.0' );
40
  define( 'WPBACKITUP__ITEM_NAME', 'WP Backitup' );
58
 
59
  define( 'WPBACKITUP__PLUGINS_ROOT_PATH',WP_PLUGIN_DIR );
60
  define( 'WPBACKITUP__THEMES_ROOT_PATH',get_theme_root() );
61
+ 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,wp-clone,backwpup,backupwordpress,cache');
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
  register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
72
  register_deactivation_hook( __FILE__, array( 'WPBackitup_Admin', 'deactivate' ) );
73
 
82
 
83
  add_filter('cron_schedules', 'wpbackitup_modify_cron_schedules', 30);
84
 
85
+ function wpbackitup_custom_post_status(){
86
+ register_post_status( 'queued', array(
87
+ 'public' => false,
88
+ 'exclude_from_search' => false,
89
+ 'show_in_admin_all_list' => false,
90
+ 'show_in_admin_status_list' => true,
91
+ ));
92
+
93
+ register_post_status( 'active', array(
94
+ 'public' => false,
95
+ 'exclude_from_search' => false,
96
+ 'show_in_admin_all_list' => false,
97
+ 'show_in_admin_status_list' => true,
98
+ ));
99
+
100
+ register_post_status( 'error', array(
101
+ 'public' => false,
102
+ 'exclude_from_search' => false,
103
+ 'show_in_admin_all_list' => false,
104
+ 'show_in_admin_status_list' => true,
105
+ ));
106
+
107
+ register_post_status( 'complete', array(
108
+ 'public' => false,
109
+ 'exclude_from_search' => false,
110
+ 'show_in_admin_all_list' => false,
111
+ 'show_in_admin_status_list' => true,
112
+ ));
113
+
114
+ }
115
+ add_action( 'init', 'wpbackitup_custom_post_status' );
116
 
117
  // The checks here before loading are for performance only - unless one of those conditions is met, then none of the hooks will ever be used
118
  if (!is_admin() && (!defined('DOING_CRON') || !DOING_CRON) && (!defined('XMLRPC_REQUEST') || !XMLRPC_REQUEST) && empty($_SERVER['SHELL']) && empty($_SERVER['USER'])) return;
123
  global $WPBackitup;
124
  $WPBackitup = WPBackitup_Admin::get_instance();
125
  $WPBackitup->initialize();