Version Description
- Improvement: Backup fail safe option now uses only php db dump and pclZip
- Improvement: Better feedback regarding completion of backups even in case of error
- Improvement: Restore using file system (better handling of file permissions)
- Fix: Notice issue with unserialise
Download this release
Release Info
Developer | infinitewp |
Plugin | InfiniteWP Client |
Version | 1.2.0 |
Comparing to | |
See all releases |
Code changes from version 1.1.10 to 1.2.0
- addons/backup_repository/backup_repository.class.php +6 -0
- backup.class.php +345 -127
- init.php +4 -6
- lib/amazon_s3/services/s3.class.php +5 -3
- readme.txt +7 -1
addons/backup_repository/backup_repository.class.php
CHANGED
@@ -58,23 +58,29 @@ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup
|
|
58 |
if ($backup_file && file_exists($backup_file)) {
|
59 |
//FTP, Amazon S3 or Dropbox
|
60 |
if (isset($account_info['iwp_ftp']) && !empty($account_info)) {
|
|
|
61 |
$account_info['iwp_ftp']['backup_file'] = $backup_file;
|
62 |
iwp_mmb_print_flush('FTP upload: Start');
|
63 |
$return = $this->ftp_backup($account_info['iwp_ftp']);
|
|
|
64 |
iwp_mmb_print_flush('FTP upload: End');
|
65 |
}
|
66 |
|
67 |
if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
|
|
|
68 |
$account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
|
69 |
iwp_mmb_print_flush('Amazon S3 upload: Start');
|
70 |
$return = $this->amazons3_backup($account_info['iwp_amazon_s3']);
|
|
|
71 |
iwp_mmb_print_flush('Amazon S3 upload: End');
|
72 |
}
|
73 |
|
74 |
if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
|
|
|
75 |
$account_info['iwp_dropbox']['backup_file'] = $backup_file;
|
76 |
iwp_mmb_print_flush('Dropbox upload: Start');
|
77 |
$return = $this->dropbox_backup($account_info['iwp_dropbox']);
|
|
|
78 |
iwp_mmb_print_flush('Dropbox upload: End');
|
79 |
}
|
80 |
|
58 |
if ($backup_file && file_exists($backup_file)) {
|
59 |
//FTP, Amazon S3 or Dropbox
|
60 |
if (isset($account_info['iwp_ftp']) && !empty($account_info)) {
|
61 |
+
$this->update_status($task_name, 'ftp');
|
62 |
$account_info['iwp_ftp']['backup_file'] = $backup_file;
|
63 |
iwp_mmb_print_flush('FTP upload: Start');
|
64 |
$return = $this->ftp_backup($account_info['iwp_ftp']);
|
65 |
+
$this->update_status($task_name, 'ftp', true);
|
66 |
iwp_mmb_print_flush('FTP upload: End');
|
67 |
}
|
68 |
|
69 |
if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
|
70 |
+
$this->update_status($task_name, 's3');
|
71 |
$account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
|
72 |
iwp_mmb_print_flush('Amazon S3 upload: Start');
|
73 |
$return = $this->amazons3_backup($account_info['iwp_amazon_s3']);
|
74 |
+
$this->update_status($task_name, 's3', true);
|
75 |
iwp_mmb_print_flush('Amazon S3 upload: End');
|
76 |
}
|
77 |
|
78 |
if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
|
79 |
+
$this->update_status($task_name, 'dropbox');
|
80 |
$account_info['iwp_dropbox']['backup_file'] = $backup_file;
|
81 |
iwp_mmb_print_flush('Dropbox upload: Start');
|
82 |
$return = $this->dropbox_backup($account_info['iwp_dropbox']);
|
83 |
+
$this->update_status($task_name, 'dropbox', true);
|
84 |
iwp_mmb_print_flush('Dropbox upload: End');
|
85 |
}
|
86 |
|
backup.class.php
CHANGED
@@ -172,12 +172,13 @@ if (is_array($params['account_info'])) { //only if sends from IWP Admin Panel fi
|
|
172 |
}
|
173 |
}
|
174 |
|
175 |
-
|
176 |
if (is_array($before[$task_name]['task_results'])) {
|
177 |
$before[$task_name]['task_results'] = array_values($before[$task_name]['task_results']);
|
178 |
}
|
179 |
-
$before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['time'] = $time;
|
180 |
-
}
|
|
|
181 |
|
182 |
$this->update_tasks($before);
|
183 |
//update_option('iwp_client_backup_tasks', $before);
|
@@ -321,7 +322,10 @@ function delete_task_now($task_name){
|
|
321 |
|
322 |
extract($args); //extract settings
|
323 |
|
324 |
-
|
|
|
|
|
|
|
325 |
$this->set_memory();
|
326 |
|
327 |
//Remove old backup(s)
|
@@ -356,7 +360,7 @@ function delete_task_now($task_name){
|
|
356 |
//What to backup - db or full?
|
357 |
if (trim($what) == 'db') {
|
358 |
//Take database backup
|
359 |
-
$this->update_status($task_name,
|
360 |
$GLOBALS['fail_safe_db'] = $this->tasks[$task_name]['task_args']['fail_safe_db'];
|
361 |
|
362 |
$db_result = $this->backup_db();
|
@@ -369,12 +373,17 @@ function delete_task_now($task_name){
|
|
369 |
'error' => $db_result['error']
|
370 |
);
|
371 |
} else {
|
372 |
-
$this->update_status($task_name,
|
373 |
-
$this->update_status($task_name,
|
374 |
|
375 |
/*zip_backup_db*/
|
376 |
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
|
377 |
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
|
|
|
|
|
|
|
|
|
|
|
378 |
$comp_level = $disable_comp ? '-0' : '-1';
|
379 |
chdir(IWP_BACKUP_DIR);
|
380 |
$zip = $this->get_zip();
|
@@ -395,33 +404,7 @@ function delete_task_now($task_name){
|
|
395 |
}
|
396 |
|
397 |
if (!$zip_archive_db_result) {
|
398 |
-
|
399 |
-
// fallback to pclzip
|
400 |
-
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
|
401 |
-
//require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
402 |
-
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
|
403 |
-
$archive = new IWPPclZip($backup_file);
|
404 |
-
|
405 |
-
if($fail_safe_files && $disable_comp){
|
406 |
-
$result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
|
407 |
-
}
|
408 |
-
elseif(!$fail_safe_files && $disable_comp){
|
409 |
-
$result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
|
410 |
-
}
|
411 |
-
elseif($fail_safe_files && !$disable_comp){
|
412 |
-
$result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
|
413 |
-
}
|
414 |
-
else{
|
415 |
-
$result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
|
416 |
-
}
|
417 |
-
iwp_mmb_print_flush('DB ZIP PCL: End');
|
418 |
-
@unlink($db_result);
|
419 |
-
@unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
|
420 |
-
@rmdir(IWP_DB_DIR);
|
421 |
-
if (!$result) {
|
422 |
-
return array(
|
423 |
-
'error' => 'Failed to zip database (pclZip - ' . $archive->error_code . '): .' . $archive->error_string
|
424 |
-
);
|
425 |
}
|
426 |
}
|
427 |
}
|
@@ -434,7 +417,7 @@ function delete_task_now($task_name){
|
|
434 |
'error' => 'Failed to zip database.'
|
435 |
);
|
436 |
}*///commented because of zipArchive
|
437 |
-
$this->update_status($task_name,
|
438 |
}
|
439 |
} elseif (trim($what) == 'full') {
|
440 |
$content_backup = $this->backup_full($task_name, $backup_file, $exclude, $include);
|
@@ -496,27 +479,27 @@ function delete_task_now($task_name){
|
|
496 |
$paths['time'] = time();
|
497 |
|
498 |
|
499 |
-
if ($task_name != 'Backup Now') {
|
500 |
-
|
|
|
501 |
$temp[count($temp) - 1] = $paths;
|
502 |
|
|
|
503 |
} else {
|
504 |
$temp[count($temp)] = $paths;
|
505 |
}
|
|
|
506 |
|
507 |
$backup_settings[$task_name]['task_results'] = $temp;
|
508 |
$this->update_tasks($backup_settings);
|
509 |
//update_option('iwp_client_backup_tasks', $backup_settings);
|
510 |
}
|
511 |
|
512 |
-
|
513 |
-
/*
|
514 |
-
//IWP Remove starts here //IWP Remove ends here
|
515 |
-
*/
|
516 |
if ($task_name != 'Backup Now') {
|
517 |
|
518 |
if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
|
519 |
-
$this->update_status($task_name,
|
520 |
$account_info['iwp_ftp']['backup_file'] = $backup_file;
|
521 |
iwp_mmb_print_flush('FTP upload: Start');
|
522 |
$ftp_result = $this->ftp_backup($account_info['iwp_ftp']);
|
@@ -529,11 +512,11 @@ function delete_task_now($task_name){
|
|
529 |
return $ftp_result;
|
530 |
}
|
531 |
$this->wpdb_reconnect();
|
532 |
-
$this->update_status($task_name,
|
533 |
}
|
534 |
|
535 |
if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
|
536 |
-
$this->update_status($task_name,
|
537 |
$account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
|
538 |
iwp_mmb_print_flush('Amazon S3 upload: Start');
|
539 |
$amazons3_result = $this->amazons3_backup($account_info['iwp_amazon_s3']);
|
@@ -545,11 +528,11 @@ function delete_task_now($task_name){
|
|
545 |
return $amazons3_result;
|
546 |
}
|
547 |
$this->wpdb_reconnect();
|
548 |
-
$this->update_status($task_name,
|
549 |
}
|
550 |
|
551 |
if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
|
552 |
-
$this->update_status($task_name,
|
553 |
$account_info['iwp_dropbox']['backup_file'] = $backup_file;
|
554 |
iwp_mmb_print_flush('Dropbox upload: Start');
|
555 |
$dropbox_result = $this->dropbox_backup($account_info['iwp_dropbox']);
|
@@ -562,7 +545,7 @@ function delete_task_now($task_name){
|
|
562 |
return $dropbox_result;
|
563 |
}
|
564 |
$this->wpdb_reconnect();
|
565 |
-
$this->update_status($task_name,
|
566 |
}
|
567 |
|
568 |
if ($del_host_file) {
|
@@ -571,7 +554,8 @@ function delete_task_now($task_name){
|
|
571 |
|
572 |
} //end additional
|
573 |
|
574 |
-
|
|
|
575 |
return $backup_url; //Return url to backup file
|
576 |
}
|
577 |
|
@@ -582,7 +566,7 @@ function delete_task_now($task_name){
|
|
582 |
global $zip_errors;
|
583 |
$sys = substr(PHP_OS, 0, 3);
|
584 |
|
585 |
-
$this->update_status($task_name,
|
586 |
$GLOBALS['fail_safe_db'] = $this->tasks[$task_name]['task_args']['fail_safe_db'];
|
587 |
$db_result = $this->backup_db();
|
588 |
|
@@ -596,12 +580,17 @@ function delete_task_now($task_name){
|
|
596 |
);
|
597 |
}
|
598 |
|
599 |
-
$this->update_status($task_name,
|
600 |
-
$this->update_status($task_name,
|
601 |
|
602 |
/*zip_backup_db*/
|
603 |
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
|
604 |
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
|
|
|
|
|
|
|
|
|
|
|
605 |
$comp_level = $disable_comp ? '-0' : '-1';
|
606 |
$zip = $this->get_zip();
|
607 |
iwp_mmb_print_flush('DB ZIP CMD: Start');
|
@@ -624,42 +613,15 @@ function delete_task_now($task_name){
|
|
624 |
}
|
625 |
|
626 |
if (!$zip_archive_db_result) {
|
627 |
-
|
628 |
-
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
|
629 |
-
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
|
630 |
-
$archive = new IWPPclZip($backup_file);
|
631 |
-
|
632 |
-
if($fail_safe_files && $disable_comp){
|
633 |
-
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
|
634 |
}
|
635 |
-
elseif(!$fail_safe_files && $disable_comp){
|
636 |
-
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
|
637 |
}
|
638 |
-
elseif($fail_safe_files && !$disable_comp){
|
639 |
-
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
|
640 |
-
}
|
641 |
-
else{
|
642 |
-
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
|
643 |
}
|
644 |
-
iwp_mmb_print_flush('DB ZIP PCL: End');
|
645 |
-
|
646 |
@unlink($db_result);
|
647 |
@unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
|
648 |
@rmdir(IWP_DB_DIR);
|
649 |
|
650 |
-
|
651 |
-
return array(
|
652 |
-
'error' => 'Failed to zip database. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
653 |
-
);
|
654 |
-
}
|
655 |
-
}
|
656 |
-
}
|
657 |
-
|
658 |
-
@unlink($db_result);
|
659 |
-
@unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
|
660 |
-
@rmdir(IWP_DB_DIR);
|
661 |
-
|
662 |
-
$this->update_status($task_name, $this->statuses['db_zip'], true);
|
663 |
|
664 |
|
665 |
//Always remove backup folders
|
@@ -744,9 +706,13 @@ function delete_task_now($task_name){
|
|
744 |
}
|
745 |
}
|
746 |
|
747 |
-
$this->update_status($task_name,
|
748 |
chdir(ABSPATH);
|
749 |
|
|
|
|
|
|
|
|
|
750 |
$do_cmd_zip_alternative = false;
|
751 |
@copy($backup_file, $backup_file.'_2');
|
752 |
|
@@ -802,7 +768,22 @@ function delete_task_now($task_name){
|
|
802 |
}
|
803 |
|
804 |
|
805 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
806 |
iwp_mmb_print_flush('Files ZIP PCL: Start');
|
807 |
if (!isset($archive)) {
|
808 |
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
|
@@ -871,15 +852,41 @@ function delete_task_now($task_name){
|
|
871 |
'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
872 |
);
|
873 |
}
|
874 |
-
}
|
875 |
}
|
876 |
//Reconnect
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
881 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
882 |
|
|
|
|
|
|
|
|
|
|
|
|
|
883 |
/**
|
884 |
* Zipping database dump and index.php in folder iwp_db by ZipArchive class, requires php zip extension.
|
885 |
*
|
@@ -994,6 +1001,12 @@ function delete_task_now($task_name){
|
|
994 |
}
|
995 |
|
996 |
$file = $db_folder . DB_NAME . '.sql';
|
|
|
|
|
|
|
|
|
|
|
|
|
997 |
$result = $this->backup_db_dump($file); // try mysqldump always then fallback to php dump
|
998 |
return $result;
|
999 |
}
|
@@ -1174,11 +1187,112 @@ function delete_task_now($task_name){
|
|
1174 |
return $file;
|
1175 |
|
1176 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1177 |
|
1178 |
function restore($args)
|
1179 |
{
|
1180 |
|
1181 |
-
global $wpdb;
|
1182 |
if (empty($args)) {
|
1183 |
return false;
|
1184 |
}
|
@@ -1187,11 +1301,13 @@ function delete_task_now($task_name){
|
|
1187 |
$this->set_memory();
|
1188 |
|
1189 |
$unlink_file = true; //Delete file after restore
|
|
|
|
|
1190 |
|
1191 |
//Detect source
|
1192 |
if ($backup_url) {
|
1193 |
//This is for clone (overwrite)
|
1194 |
-
|
1195 |
$backup_file = download_url($backup_url);
|
1196 |
if (is_wp_error($backup_file)) {
|
1197 |
return array(
|
@@ -1248,13 +1364,69 @@ function delete_task_now($task_name){
|
|
1248 |
|
1249 |
$what = $tasks[$task_name]['task_args']['what'];
|
1250 |
}
|
|
|
|
|
1251 |
|
1252 |
$this->wpdb_reconnect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1253 |
|
1254 |
if ($backup_file && file_exists($backup_file)) {
|
1255 |
if ($overwrite) {
|
1256 |
//Keep old db credentials before overwrite
|
1257 |
-
if (
|
1258 |
@unlink($backup_file);
|
1259 |
return array(
|
1260 |
'error' => 'Error creating wp-config. Please check your write permissions.'
|
@@ -1288,11 +1460,15 @@ function delete_task_now($task_name){
|
|
1288 |
$restore_options['iwp_client_user_hit_count'] = serialize(get_option('iwp_client_user_hit_count'));
|
1289 |
$restore_options['iwp_client_backup_tasks'] = serialize(get_option('iwp_client_backup_tasks'));
|
1290 |
}
|
|
|
|
|
1291 |
|
1292 |
-
|
1293 |
-
|
|
|
|
|
1294 |
$unzip = $this->get_unzip();
|
1295 |
-
$command = "$unzip -o $backup_file";
|
1296 |
iwp_mmb_print_flush('ZIP Extract CMD: Start');
|
1297 |
ob_start();
|
1298 |
$result = $this->iwp_mmb_exec($command);
|
@@ -1305,14 +1481,14 @@ function delete_task_now($task_name){
|
|
1305 |
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
|
1306 |
iwp_mmb_print_flush('ZIP Extract PCL: Start');
|
1307 |
$archive = new IWPPclZip($backup_file);
|
1308 |
-
$result = $archive->extract(PCLZIP_OPT_PATH,
|
1309 |
iwp_mmb_print_flush('ZIP Extract PCL: End');
|
1310 |
}
|
1311 |
$this->wpdb_reconnect();
|
1312 |
|
1313 |
-
if ($unlink_file) {
|
1314 |
@unlink($backup_file);
|
1315 |
-
}
|
1316 |
|
1317 |
if (!$result) {
|
1318 |
return array(
|
@@ -1320,7 +1496,7 @@ function delete_task_now($task_name){
|
|
1320 |
);
|
1321 |
}
|
1322 |
|
1323 |
-
$db_result = $this->restore_db();
|
1324 |
|
1325 |
if (!$db_result) {
|
1326 |
return array(
|
@@ -1337,26 +1513,46 @@ function delete_task_now($task_name){
|
|
1337 |
'error' => 'Error while restoring. The WP root directory is not writable. Set write permission(755 or 777).'
|
1338 |
);
|
1339 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1340 |
|
1341 |
$this->wpdb_reconnect();
|
|
|
|
|
1342 |
|
1343 |
//Replace options and content urls
|
1344 |
if ($overwrite) {
|
1345 |
//Get New Table prefix
|
1346 |
$new_table_prefix = trim($this->get_table_prefix());
|
1347 |
//Retrieve old wp_config
|
1348 |
-
|
|
|
1349 |
//Replace table prefix
|
1350 |
-
|
|
|
1351 |
|
|
|
1352 |
foreach ($lines as $line) {
|
1353 |
if (strstr($line, '$table_prefix')) {
|
1354 |
$line = '$table_prefix = "' . $new_table_prefix . '";' . PHP_EOL;
|
1355 |
}
|
1356 |
-
|
|
|
1357 |
}
|
|
|
|
|
1358 |
|
1359 |
-
|
|
|
1360 |
|
1361 |
//Replace options
|
1362 |
$query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
|
@@ -1428,7 +1624,7 @@ function delete_task_now($task_name){
|
|
1428 |
$wpdb->query($query);
|
1429 |
|
1430 |
//Check for .htaccess permalinks update
|
1431 |
-
$this->replace_htaccess($home);
|
1432 |
} else {
|
1433 |
//restore client options
|
1434 |
if (is_array($restore_options) && !empty($restore_options)) {
|
@@ -1449,15 +1645,19 @@ function delete_task_now($task_name){
|
|
1449 |
}
|
1450 |
}
|
1451 |
}
|
|
|
|
|
|
|
|
|
1452 |
|
1453 |
return !empty($new_user) ? $new_user : true ;
|
1454 |
}
|
1455 |
|
1456 |
-
function restore_db()
|
1457 |
{
|
1458 |
global $wpdb;
|
1459 |
$paths = $this->check_mysql_paths();
|
1460 |
-
$file_path =
|
1461 |
@chmod($file_path,0755);
|
1462 |
$file_name = glob($file_path . '/*.sql');
|
1463 |
$file_name = $file_name[0];
|
@@ -1480,7 +1680,8 @@ function delete_task_now($task_name){
|
|
1480 |
|
1481 |
|
1482 |
@unlink($file_name);
|
1483 |
-
@unlink(dirname($file_name))
|
|
|
1484 |
return true;
|
1485 |
}
|
1486 |
|
@@ -1864,7 +2065,9 @@ function ftp_backup($args)
|
|
1864 |
@ftp_pasv($conn_id,true);
|
1865 |
}
|
1866 |
|
1867 |
-
|
|
|
|
|
1868 |
$get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
|
1869 |
if ($get === false) {
|
1870 |
return false;
|
@@ -1948,7 +2151,8 @@ function ftp_backup($args)
|
|
1948 |
if ($dropbox_site_folder == true)
|
1949 |
$dropbox_destination .= '/' . $this->site_name;
|
1950 |
|
1951 |
-
|
|
|
1952 |
|
1953 |
try {
|
1954 |
|
@@ -2045,7 +2249,8 @@ function ftp_backup($args)
|
|
2045 |
if ($as3_site_folder == true)
|
2046 |
$as3_directory .= '/' . $this->site_name;
|
2047 |
|
2048 |
-
|
|
|
2049 |
$s3->get_object($as3_bucket, $as3_directory . '/' . $backup_file, array("fileDownload" => $temp));
|
2050 |
} catch (Exception $e){
|
2051 |
return $temp;
|
@@ -2169,9 +2374,7 @@ function ftp_backup($args)
|
|
2169 |
return $stats;
|
2170 |
}
|
2171 |
|
2172 |
-
|
2173 |
-
//IWP Remove starts here//IWP Remove ends here
|
2174 |
-
*/
|
2175 |
function get_next_schedules()
|
2176 |
{
|
2177 |
$stats = array();
|
@@ -2409,22 +2612,27 @@ function get_next_schedules()
|
|
2409 |
7 - Email
|
2410 |
100 - Finished
|
2411 |
*/
|
2412 |
-
if ($task_name != 'Backup Now') {
|
2413 |
$tasks = $this->tasks;
|
2414 |
$index = count($tasks[$task_name]['task_results']) - 1;
|
2415 |
-
|
2416 |
-
|
|
|
|
|
2417 |
}
|
|
|
2418 |
if (!$completed) {
|
2419 |
-
|
|
|
2420 |
} else {
|
2421 |
$status_index = count($tasks[$task_name]['task_results'][$index]['status']) - 1;
|
2422 |
-
|
|
|
2423 |
}
|
2424 |
|
2425 |
$this->update_tasks($tasks);
|
2426 |
//update_option('iwp_client_backup_tasks',$tasks);
|
2427 |
-
}
|
2428 |
}
|
2429 |
|
2430 |
function update_tasks($tasks)
|
@@ -2445,17 +2653,20 @@ function get_next_schedules()
|
|
2445 |
}
|
2446 |
}
|
2447 |
|
2448 |
-
function replace_htaccess($url)
|
2449 |
{
|
2450 |
-
|
2451 |
-
|
2452 |
-
|
2453 |
-
|
2454 |
-
|
2455 |
-
|
2456 |
-
|
2457 |
-
|
2458 |
-
|
|
|
|
|
|
|
2459 |
}
|
2460 |
|
2461 |
function check_cron_remove(){
|
@@ -2513,6 +2724,13 @@ function get_next_schedules()
|
|
2513 |
unset($params['backups']);
|
2514 |
return $params;
|
2515 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2516 |
}
|
2517 |
|
2518 |
/*if( function_exists('add_filter') ){
|
172 |
}
|
173 |
}
|
174 |
|
175 |
+
// if (isset($time) && $time) { //set next result time before backup
|
176 |
if (is_array($before[$task_name]['task_results'])) {
|
177 |
$before[$task_name]['task_results'] = array_values($before[$task_name]['task_results']);
|
178 |
}
|
179 |
+
$before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['time'] = (isset($time) && $time) ? $time : time();
|
180 |
+
//}
|
181 |
+
|
182 |
|
183 |
$this->update_tasks($before);
|
184 |
//update_option('iwp_client_backup_tasks', $before);
|
322 |
|
323 |
extract($args); //extract settings
|
324 |
|
325 |
+
//$adminHistoryID - admin panel history ID for backup task.
|
326 |
+
|
327 |
+
|
328 |
+
//Try increase memory limit and execution time
|
329 |
$this->set_memory();
|
330 |
|
331 |
//Remove old backup(s)
|
360 |
//What to backup - db or full?
|
361 |
if (trim($what) == 'db') {
|
362 |
//Take database backup
|
363 |
+
$this->update_status($task_name, 'db_dump');
|
364 |
$GLOBALS['fail_safe_db'] = $this->tasks[$task_name]['task_args']['fail_safe_db'];
|
365 |
|
366 |
$db_result = $this->backup_db();
|
373 |
'error' => $db_result['error']
|
374 |
);
|
375 |
} else {
|
376 |
+
$this->update_status($task_name, 'db_dump', true);
|
377 |
+
$this->update_status($task_name, 'db_zip');
|
378 |
|
379 |
/*zip_backup_db*/
|
380 |
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
|
381 |
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
|
382 |
+
|
383 |
+
if($fail_safe_files){
|
384 |
+
$this->fail_safe_pcl_db($backup_file,$fail_safe_files,$disable_comp);
|
385 |
+
}
|
386 |
+
else{
|
387 |
$comp_level = $disable_comp ? '-0' : '-1';
|
388 |
chdir(IWP_BACKUP_DIR);
|
389 |
$zip = $this->get_zip();
|
404 |
}
|
405 |
|
406 |
if (!$zip_archive_db_result) {
|
407 |
+
$this->fail_safe_pcl_db($backup_file,$fail_safe_files,$disable_comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
}
|
409 |
}
|
410 |
}
|
417 |
'error' => 'Failed to zip database.'
|
418 |
);
|
419 |
}*///commented because of zipArchive
|
420 |
+
$this->update_status($task_name, 'db_zip', true);
|
421 |
}
|
422 |
} elseif (trim($what) == 'full') {
|
423 |
$content_backup = $this->backup_full($task_name, $backup_file, $exclude, $include);
|
479 |
$paths['time'] = time();
|
480 |
|
481 |
|
482 |
+
//if ($task_name != 'Backup Now') {
|
483 |
+
$paths['backhack_status'] = $temp[count($temp) - 1]['backhack_status'];
|
484 |
+
//$paths['status'] = $temp[count($temp) - 1]['status'];
|
485 |
$temp[count($temp) - 1] = $paths;
|
486 |
|
487 |
+
/*
|
488 |
} else {
|
489 |
$temp[count($temp)] = $paths;
|
490 |
}
|
491 |
+
*/
|
492 |
|
493 |
$backup_settings[$task_name]['task_results'] = $temp;
|
494 |
$this->update_tasks($backup_settings);
|
495 |
//update_option('iwp_client_backup_tasks', $backup_settings);
|
496 |
}
|
497 |
|
498 |
+
|
|
|
|
|
|
|
499 |
if ($task_name != 'Backup Now') {
|
500 |
|
501 |
if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
|
502 |
+
$this->update_status($task_name, 'ftp');
|
503 |
$account_info['iwp_ftp']['backup_file'] = $backup_file;
|
504 |
iwp_mmb_print_flush('FTP upload: Start');
|
505 |
$ftp_result = $this->ftp_backup($account_info['iwp_ftp']);
|
512 |
return $ftp_result;
|
513 |
}
|
514 |
$this->wpdb_reconnect();
|
515 |
+
$this->update_status($task_name, 'ftp', true);
|
516 |
}
|
517 |
|
518 |
if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
|
519 |
+
$this->update_status($task_name, 's3');
|
520 |
$account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
|
521 |
iwp_mmb_print_flush('Amazon S3 upload: Start');
|
522 |
$amazons3_result = $this->amazons3_backup($account_info['iwp_amazon_s3']);
|
528 |
return $amazons3_result;
|
529 |
}
|
530 |
$this->wpdb_reconnect();
|
531 |
+
$this->update_status($task_name, 's3', true);
|
532 |
}
|
533 |
|
534 |
if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
|
535 |
+
$this->update_status($task_name, 'dropbox');
|
536 |
$account_info['iwp_dropbox']['backup_file'] = $backup_file;
|
537 |
iwp_mmb_print_flush('Dropbox upload: Start');
|
538 |
$dropbox_result = $this->dropbox_backup($account_info['iwp_dropbox']);
|
545 |
return $dropbox_result;
|
546 |
}
|
547 |
$this->wpdb_reconnect();
|
548 |
+
$this->update_status($task_name, 'dropbox', true);
|
549 |
}
|
550 |
|
551 |
if ($del_host_file) {
|
554 |
|
555 |
} //end additional
|
556 |
|
557 |
+
$this->update_status($task_name,'finished',true);
|
558 |
+
|
559 |
return $backup_url; //Return url to backup file
|
560 |
}
|
561 |
|
566 |
global $zip_errors;
|
567 |
$sys = substr(PHP_OS, 0, 3);
|
568 |
|
569 |
+
$this->update_status($task_name, 'db_dump');
|
570 |
$GLOBALS['fail_safe_db'] = $this->tasks[$task_name]['task_args']['fail_safe_db'];
|
571 |
$db_result = $this->backup_db();
|
572 |
|
580 |
);
|
581 |
}
|
582 |
|
583 |
+
$this->update_status($task_name, 'db_dump', true);
|
584 |
+
$this->update_status($task_name, 'db_zip');
|
585 |
|
586 |
/*zip_backup_db*/
|
587 |
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
|
588 |
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
|
589 |
+
|
590 |
+
if($fail_safe_files){
|
591 |
+
$this->fail_safe_pcl_db($backup_file,$fail_safe_files,$disable_comp);
|
592 |
+
}
|
593 |
+
else{
|
594 |
$comp_level = $disable_comp ? '-0' : '-1';
|
595 |
$zip = $this->get_zip();
|
596 |
iwp_mmb_print_flush('DB ZIP CMD: Start');
|
613 |
}
|
614 |
|
615 |
if (!$zip_archive_db_result) {
|
616 |
+
$this->fail_safe_pcl_db($backup_file,$fail_safe_files,$disable_comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
}
|
|
|
|
|
618 |
}
|
|
|
|
|
|
|
|
|
|
|
619 |
}
|
|
|
|
|
620 |
@unlink($db_result);
|
621 |
@unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
|
622 |
@rmdir(IWP_DB_DIR);
|
623 |
|
624 |
+
$this->update_status($task_name, 'db_zip', true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
625 |
|
626 |
|
627 |
//Always remove backup folders
|
706 |
}
|
707 |
}
|
708 |
|
709 |
+
$this->update_status($task_name, 'files_zip');
|
710 |
chdir(ABSPATH);
|
711 |
|
712 |
+
if($fail_safe_files){
|
713 |
+
$this->fail_safe_pcl_files($task_name, $backup_file, $exclude, $include, $fail_safe_files, $disable_comp, $add, $remove);
|
714 |
+
}
|
715 |
+
else{
|
716 |
$do_cmd_zip_alternative = false;
|
717 |
@copy($backup_file, $backup_file.'_2');
|
718 |
|
768 |
}
|
769 |
|
770 |
|
771 |
+
if (!$zip_archive_result) {
|
772 |
+
$this->fail_safe_pcl_files($task_name, $backup_file, $exclude, $include, $fail_safe_files, $disable_comp, $add, $remove);
|
773 |
+
}
|
774 |
+
}
|
775 |
+
}
|
776 |
+
|
777 |
+
//Reconnect
|
778 |
+
$this->wpdb_reconnect();
|
779 |
+
|
780 |
+
$this->update_status($task_name, 'files_zip', true);
|
781 |
+
return true;
|
782 |
+
}
|
783 |
+
|
784 |
+
|
785 |
+
function fail_safe_pcl_files($task_name, $backup_file, $exclude, $include, $fail_safe_files, $disable_comp, $add, $remove){ //Try pclZip
|
786 |
+
//$this->back_hack($task_name, 'Files ZIP PCL: Start');
|
787 |
iwp_mmb_print_flush('Files ZIP PCL: Start');
|
788 |
if (!isset($archive)) {
|
789 |
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
|
852 |
'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
853 |
);
|
854 |
}
|
855 |
+
//}
|
856 |
}
|
857 |
//Reconnect
|
858 |
+
function fail_safe_pcl_db($backup_file,$fail_safe_files,$disable_comp){
|
859 |
+
//$this->back_hack($task_name, 'DB ZIP PCL: Start');
|
860 |
+
iwp_mmb_print_flush('DB ZIP PCL: Start');
|
861 |
+
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
|
862 |
+
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
|
863 |
+
$archive = new IWPPclZip($backup_file);
|
864 |
+
|
865 |
+
if($fail_safe_files && $disable_comp){
|
866 |
+
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
|
867 |
+
}
|
868 |
+
elseif(!$fail_safe_files && $disable_comp){
|
869 |
+
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
|
870 |
+
}
|
871 |
+
elseif($fail_safe_files && !$disable_comp){
|
872 |
+
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
|
873 |
+
}
|
874 |
+
else{
|
875 |
+
$result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
|
876 |
}
|
877 |
+
//$this->back_hack($task_name, 'DB ZIP PCL: End');
|
878 |
+
iwp_mmb_print_flush('DB ZIP PCL: End');
|
879 |
+
|
880 |
+
@unlink($db_result);
|
881 |
+
@unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
|
882 |
+
@rmdir(IWP_DB_DIR);
|
883 |
|
884 |
+
if (!$result_db) {
|
885 |
+
return array(
|
886 |
+
'error' => 'Failed to zip database. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
887 |
+
);
|
888 |
+
}
|
889 |
+
}
|
890 |
/**
|
891 |
* Zipping database dump and index.php in folder iwp_db by ZipArchive class, requires php zip extension.
|
892 |
*
|
1001 |
}
|
1002 |
|
1003 |
$file = $db_folder . DB_NAME . '.sql';
|
1004 |
+
|
1005 |
+
if($GLOBALS['fail_safe_db']){
|
1006 |
+
$result = $this->backup_db_php($file);
|
1007 |
+
return $result;
|
1008 |
+
}
|
1009 |
+
|
1010 |
$result = $this->backup_db_dump($file); // try mysqldump always then fallback to php dump
|
1011 |
return $result;
|
1012 |
}
|
1187 |
return $file;
|
1188 |
|
1189 |
}
|
1190 |
+
|
1191 |
+
/**
|
1192 |
+
* Copies a directory from one location to another via the WordPress Filesystem Abstraction.
|
1193 |
+
* Assumes that WP_Filesystem() has already been called and setup.
|
1194 |
+
*
|
1195 |
+
* @since 2.5.0
|
1196 |
+
*
|
1197 |
+
* @param string $from source directory
|
1198 |
+
* @param string $to destination directory
|
1199 |
+
* @param array $skip_list a list of files/folders to skip copying
|
1200 |
+
* @return mixed WP_Error on failure, True on success.
|
1201 |
+
*/
|
1202 |
+
function iwp_mmb_direct_to_any_copy_dir($from, $to, $skip_list = array() ) {//$from => direct file system, $to => automatic filesystem
|
1203 |
+
global $wp_filesystem;
|
1204 |
+
|
1205 |
+
$wp_temp_direct = new WP_Filesystem_Direct();
|
1206 |
+
|
1207 |
+
|
1208 |
+
$dirlist = $wp_temp_direct->dirlist($from);
|
1209 |
+
|
1210 |
+
$from = trailingslashit($from);
|
1211 |
+
$to = trailingslashit($to);
|
1212 |
+
|
1213 |
+
$skip_regex = '';
|
1214 |
+
foreach ( (array)$skip_list as $key => $skip_file )
|
1215 |
+
$skip_regex .= preg_quote($skip_file, '!') . '|';
|
1216 |
+
|
1217 |
+
if ( !empty($skip_regex) )
|
1218 |
+
$skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
|
1219 |
+
|
1220 |
+
foreach ( (array) $dirlist as $filename => $fileinfo ) {
|
1221 |
+
if ( !empty($skip_regex) )
|
1222 |
+
if ( preg_match($skip_regex, $from . $filename) )
|
1223 |
+
continue;
|
1224 |
+
|
1225 |
+
if ( 'f' == $fileinfo['type'] ) {
|
1226 |
+
if ( ! $this->iwp_mmb_direct_to_any_copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
|
1227 |
+
// If copy failed, chmod file to 0644 and try again.
|
1228 |
+
$wp_filesystem->chmod($to . $filename, 0644);
|
1229 |
+
if ( ! $this->iwp_mmb_direct_to_any_copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
|
1230 |
+
return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
|
1231 |
+
}
|
1232 |
+
} elseif ( 'd' == $fileinfo['type'] ) {
|
1233 |
+
if ( !$wp_filesystem->is_dir($to . $filename) ) {
|
1234 |
+
if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
|
1235 |
+
return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
|
1236 |
+
}
|
1237 |
+
$result = $this->iwp_mmb_direct_to_any_copy_dir($from . $filename, $to . $filename, $skip_list);
|
1238 |
+
if ( is_wp_error($result) )
|
1239 |
+
return $result;
|
1240 |
+
}
|
1241 |
+
}
|
1242 |
+
return true;
|
1243 |
+
}
|
1244 |
+
|
1245 |
+
function iwp_mmb_direct_to_any_copy($source, $destination, $overwrite = false, $mode = false){
|
1246 |
+
global $wp_filesystem;
|
1247 |
+
if($wp_filesystem->method == 'direct'){
|
1248 |
+
return $wp_filesystem->copy($source, $destination, $overwrite, $mode);
|
1249 |
+
}
|
1250 |
+
elseif($wp_filesystem->method == 'ftpext' || $wp_filesystem->method == 'ftpsockets'){
|
1251 |
+
if ( ! $overwrite && $wp_filesystem->exists($destination) )
|
1252 |
+
return false;
|
1253 |
+
//$content = $this->get_contents($source);
|
1254 |
+
// if ( false === $content)
|
1255 |
+
// return false;
|
1256 |
+
|
1257 |
+
//put content
|
1258 |
+
//$tempfile = wp_tempnam($file);
|
1259 |
+
$source_handle = fopen($source, 'r');
|
1260 |
+
if ( ! $source_handle )
|
1261 |
+
return false;
|
1262 |
+
|
1263 |
+
//fwrite($temp, $contents);
|
1264 |
+
//fseek($temp, 0); //Skip back to the start of the file being written to
|
1265 |
+
|
1266 |
+
$sample_content = fread($source_handle, (1024 * 1024 * 2));//1024 * 1024 * 2 => 2MB
|
1267 |
+
fseek($source_handle, 0); //Skip back to the start of the file being written to
|
1268 |
+
|
1269 |
+
$type = $wp_filesystem->is_binary($sample_content) ? FTP_BINARY : FTP_ASCII;
|
1270 |
+
unset($sample_content);
|
1271 |
+
if($wp_filesystem->method == 'ftpext'){
|
1272 |
+
$ret = @ftp_fput($wp_filesystem->link, $destination, $source_handle, $type);
|
1273 |
+
}
|
1274 |
+
elseif($wp_filesystem->method == 'ftpsockets'){
|
1275 |
+
$wp_filesystem->ftp->SetType($type);
|
1276 |
+
$ret = $wp_filesystem->ftp->fput($destination, $source_handle);
|
1277 |
+
}
|
1278 |
+
|
1279 |
+
fclose($source_handle);
|
1280 |
+
unlink($source);//to immediately save system space
|
1281 |
+
//unlink($tempfile);
|
1282 |
+
|
1283 |
+
$wp_filesystem->chmod($destination, $mode);
|
1284 |
+
|
1285 |
+
return $ret;
|
1286 |
+
|
1287 |
+
//return $this->put_contents($destination, $content, $mode);
|
1288 |
+
}
|
1289 |
+
}
|
1290 |
+
|
1291 |
|
1292 |
function restore($args)
|
1293 |
{
|
1294 |
|
1295 |
+
global $wpdb, $wp_filesystem;
|
1296 |
if (empty($args)) {
|
1297 |
return false;
|
1298 |
}
|
1301 |
$this->set_memory();
|
1302 |
|
1303 |
$unlink_file = true; //Delete file after restore
|
1304 |
+
|
1305 |
+
include_once ABSPATH . 'wp-admin/includes/file.php';
|
1306 |
|
1307 |
//Detect source
|
1308 |
if ($backup_url) {
|
1309 |
//This is for clone (overwrite)
|
1310 |
+
|
1311 |
$backup_file = download_url($backup_url);
|
1312 |
if (is_wp_error($backup_file)) {
|
1313 |
return array(
|
1364 |
|
1365 |
$what = $tasks[$task_name]['task_args']['what'];
|
1366 |
}
|
1367 |
+
|
1368 |
+
|
1369 |
|
1370 |
$this->wpdb_reconnect();
|
1371 |
+
|
1372 |
+
/////////////////// dev ////////////////////////
|
1373 |
+
|
1374 |
+
|
1375 |
+
if (!$this->is_server_writable()) {
|
1376 |
+
return array(
|
1377 |
+
'error' => 'Failed, please add FTP details'
|
1378 |
+
);
|
1379 |
+
}
|
1380 |
+
|
1381 |
+
$url = wp_nonce_url('index.php?page=iwp_no_page','iwp_fs_cred');
|
1382 |
+
ob_start();
|
1383 |
+
if (false === ($creds = request_filesystem_credentials($url, '', false, ABSPATH, null) ) ) {
|
1384 |
+
return array(
|
1385 |
+
'error' => 'Unable to get file system credentials'
|
1386 |
+
); // stop processing here
|
1387 |
+
}
|
1388 |
+
ob_end_clean();
|
1389 |
+
|
1390 |
+
if ( ! WP_Filesystem($creds, ABSPATH) ) {
|
1391 |
+
//request_filesystem_credentials($url, '', true, false, null);
|
1392 |
+
return array(
|
1393 |
+
'error' => 'Unable to initiate file system. Please check you have entered valid FTP credentials.'
|
1394 |
+
); // stop processing here
|
1395 |
+
//return;
|
1396 |
+
}
|
1397 |
+
|
1398 |
+
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');//will be used to copy from temp directory
|
1399 |
+
|
1400 |
+
// do process
|
1401 |
+
$temp_dir = get_temp_dir();
|
1402 |
+
$new_temp_folder = trailingslashit($temp_dir).'IWP_Restore_temp_dir_kjhdsjfkhsdkhfksjhdfkjh/';//should be random
|
1403 |
+
mkdir($new_temp_folder, 0755);// new folder should be empty
|
1404 |
+
|
1405 |
+
//echo '<pre>$new_temp_folder:'; var_dump($new_temp_folder); echo '</pre>';
|
1406 |
+
|
1407 |
+
|
1408 |
+
$remote_abspath = $wp_filesystem->abspath();
|
1409 |
+
if(!empty($remote_abspath)){
|
1410 |
+
$remote_abspath = trailingslashit($remote_abspath);
|
1411 |
+
}else{
|
1412 |
+
return array(
|
1413 |
+
'error' => 'Unable to locate WP root directory using file system.'
|
1414 |
+
);
|
1415 |
+
}
|
1416 |
+
|
1417 |
+
//global $wp_filesystem;
|
1418 |
+
// $wp_filesystem->put_contents(
|
1419 |
+
// '/tmp/example.txt',
|
1420 |
+
// 'Example contents of a file',
|
1421 |
+
// FS_CHMOD_FILE // predefined mode settings for WP files
|
1422 |
+
// );
|
1423 |
+
|
1424 |
+
/////////////////// dev ////////////////////////
|
1425 |
|
1426 |
if ($backup_file && file_exists($backup_file)) {
|
1427 |
if ($overwrite) {
|
1428 |
//Keep old db credentials before overwrite
|
1429 |
+
if (!$wp_filesystem->copy($remote_abspath . 'wp-config.php', $remote_abspath . 'iwp-temp-wp-config.php', true)) {
|
1430 |
@unlink($backup_file);
|
1431 |
return array(
|
1432 |
'error' => 'Error creating wp-config. Please check your write permissions.'
|
1460 |
$restore_options['iwp_client_user_hit_count'] = serialize(get_option('iwp_client_user_hit_count'));
|
1461 |
$restore_options['iwp_client_backup_tasks'] = serialize(get_option('iwp_client_backup_tasks'));
|
1462 |
}
|
1463 |
+
|
1464 |
+
|
1465 |
|
1466 |
+
|
1467 |
+
//Backup file will be extracted to a temporary path
|
1468 |
+
|
1469 |
+
//chdir(ABSPATH);
|
1470 |
$unzip = $this->get_unzip();
|
1471 |
+
$command = "$unzip -o $backup_file -d $new_temp_folder";
|
1472 |
iwp_mmb_print_flush('ZIP Extract CMD: Start');
|
1473 |
ob_start();
|
1474 |
$result = $this->iwp_mmb_exec($command);
|
1481 |
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
|
1482 |
iwp_mmb_print_flush('ZIP Extract PCL: Start');
|
1483 |
$archive = new IWPPclZip($backup_file);
|
1484 |
+
$result = $archive->extract(PCLZIP_OPT_PATH, $new_temp_folder, PCLZIP_OPT_REPLACE_NEWER);
|
1485 |
iwp_mmb_print_flush('ZIP Extract PCL: End');
|
1486 |
}
|
1487 |
$this->wpdb_reconnect();
|
1488 |
|
1489 |
+
/*if ($unlink_file) {
|
1490 |
@unlink($backup_file);
|
1491 |
+
}*/
|
1492 |
|
1493 |
if (!$result) {
|
1494 |
return array(
|
1496 |
);
|
1497 |
}
|
1498 |
|
1499 |
+
$db_result = $this->restore_db($new_temp_folder);
|
1500 |
|
1501 |
if (!$db_result) {
|
1502 |
return array(
|
1513 |
'error' => 'Error while restoring. The WP root directory is not writable. Set write permission(755 or 777).'
|
1514 |
);
|
1515 |
}
|
1516 |
+
|
1517 |
+
|
1518 |
+
//copy files from temp to ABSPATH
|
1519 |
+
$copy_result = $this->iwp_mmb_direct_to_any_copy_dir($new_temp_folder, $remote_abspath);
|
1520 |
+
|
1521 |
+
if ( is_wp_error($copy_result) ){
|
1522 |
+
$wp_temp_direct2 = WP_Filesystem_Direct();
|
1523 |
+
$wp_temp_direct2->delete($new_temp_folder, 2);
|
1524 |
+
return $copy_result;
|
1525 |
+
}
|
1526 |
+
|
1527 |
|
1528 |
$this->wpdb_reconnect();
|
1529 |
+
|
1530 |
+
|
1531 |
|
1532 |
//Replace options and content urls
|
1533 |
if ($overwrite) {
|
1534 |
//Get New Table prefix
|
1535 |
$new_table_prefix = trim($this->get_table_prefix());
|
1536 |
//Retrieve old wp_config
|
1537 |
+
//@unlink(ABSPATH . 'wp-config.php');
|
1538 |
+
$wp_filesystem->delete($remote_abspath . 'wp-config.php', false, 'f');
|
1539 |
//Replace table prefix
|
1540 |
+
//$lines = file(ABSPATH . 'iwp-temp-wp-config.php');
|
1541 |
+
$lines = $wp_filesystem->get_contents_array($remote_abspath . 'iwp-temp-wp-config.php');
|
1542 |
|
1543 |
+
$new_lines = '';
|
1544 |
foreach ($lines as $line) {
|
1545 |
if (strstr($line, '$table_prefix')) {
|
1546 |
$line = '$table_prefix = "' . $new_table_prefix . '";' . PHP_EOL;
|
1547 |
}
|
1548 |
+
$new_lines .= $line;
|
1549 |
+
//file_put_contents(ABSPATH . 'wp-config.php', $line, FILE_APPEND);
|
1550 |
}
|
1551 |
+
|
1552 |
+
$wp_filesystem->put_contents($remote_abspath . 'wp-config.php', $new_lines);
|
1553 |
|
1554 |
+
//@unlink(ABSPATH . 'iwp-temp-wp-config.php');
|
1555 |
+
$wp_filesystem->prefix($remote_abspath . 'iwp-temp-wp-config.php', false, 'f');
|
1556 |
|
1557 |
//Replace options
|
1558 |
$query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
|
1624 |
$wpdb->query($query);
|
1625 |
|
1626 |
//Check for .htaccess permalinks update
|
1627 |
+
$this->replace_htaccess($home, $remote_abspath);
|
1628 |
} else {
|
1629 |
//restore client options
|
1630 |
if (is_array($restore_options) && !empty($restore_options)) {
|
1645 |
}
|
1646 |
}
|
1647 |
}
|
1648 |
+
|
1649 |
+
//clear the temp directory
|
1650 |
+
$wp_temp_direct2 = new WP_Filesystem_Direct();
|
1651 |
+
$wp_temp_direct2->delete($new_temp_folder, 2);
|
1652 |
|
1653 |
return !empty($new_user) ? $new_user : true ;
|
1654 |
}
|
1655 |
|
1656 |
+
function restore_db($new_temp_folder)
|
1657 |
{
|
1658 |
global $wpdb;
|
1659 |
$paths = $this->check_mysql_paths();
|
1660 |
+
$file_path = $new_temp_folder . '/iwp_db';
|
1661 |
@chmod($file_path,0755);
|
1662 |
$file_name = glob($file_path . '/*.sql');
|
1663 |
$file_name = $file_name[0];
|
1680 |
|
1681 |
|
1682 |
@unlink($file_name);
|
1683 |
+
@unlink(dirname($file_name).'/index.php');
|
1684 |
+
@rmdir(dirname($file_name));//remove its folder
|
1685 |
return true;
|
1686 |
}
|
1687 |
|
2065 |
@ftp_pasv($conn_id,true);
|
2066 |
}
|
2067 |
|
2068 |
+
//$temp = ABSPATH . 'iwp_temp_backup.zip';
|
2069 |
+
$temp = wp_tempnam('iwp_temp_backup.zip');
|
2070 |
+
|
2071 |
$get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
|
2072 |
if ($get === false) {
|
2073 |
return false;
|
2151 |
if ($dropbox_site_folder == true)
|
2152 |
$dropbox_destination .= '/' . $this->site_name;
|
2153 |
|
2154 |
+
//$temp = ABSPATH . 'iwp_temp_backup.zip';
|
2155 |
+
$temp = wp_tempnam('iwp_temp_backup.zip');
|
2156 |
|
2157 |
try {
|
2158 |
|
2249 |
if ($as3_site_folder == true)
|
2250 |
$as3_directory .= '/' . $this->site_name;
|
2251 |
|
2252 |
+
//$temp = ABSPATH . 'iwp_temp_backup.zip';
|
2253 |
+
$temp = wp_tempnam('iwp_temp_backup.zip');
|
2254 |
$s3->get_object($as3_bucket, $as3_directory . '/' . $backup_file, array("fileDownload" => $temp));
|
2255 |
} catch (Exception $e){
|
2256 |
return $temp;
|
2374 |
return $stats;
|
2375 |
}
|
2376 |
|
2377 |
+
|
|
|
|
|
2378 |
function get_next_schedules()
|
2379 |
{
|
2380 |
$stats = array();
|
2612 |
7 - Email
|
2613 |
100 - Finished
|
2614 |
*/
|
2615 |
+
//if ($task_name != 'Backup Now') {
|
2616 |
$tasks = $this->tasks;
|
2617 |
$index = count($tasks[$task_name]['task_results']) - 1;
|
2618 |
+
//!is_array($tasks[$task_name]['task_results'][$index]['status']) &&
|
2619 |
+
if (!is_array($tasks[$task_name]['task_results'][$index]['backhack_status'])) {
|
2620 |
+
//$tasks[$task_name]['task_results'][$index]['status'] = array();
|
2621 |
+
$tasks[$task_name]['task_results'][$index]['backhack_status'] = array();
|
2622 |
}
|
2623 |
+
$tasks[$task_name]['task_results'][$index]['backhack_status']['adminHistoryID'] = $GLOBALS['IWP_CLIENT_HISTORY_ID'];
|
2624 |
if (!$completed) {
|
2625 |
+
//$tasks[$task_name]['task_results'][$index]['status'][] = (int) $status * (-1);
|
2626 |
+
$tasks[$task_name]['task_results'][$index]['backhack_status'][$status]['start'] = microtime(true);
|
2627 |
} else {
|
2628 |
$status_index = count($tasks[$task_name]['task_results'][$index]['status']) - 1;
|
2629 |
+
//$tasks[$task_name]['task_results'][$index]['status'][$status_index] = abs($tasks[$task_name]['task_results'][$index]['status'][$status_index]);
|
2630 |
+
$tasks[$task_name]['task_results'][$index]['backhack_status'][$status]['end'] = microtime(true);
|
2631 |
}
|
2632 |
|
2633 |
$this->update_tasks($tasks);
|
2634 |
//update_option('iwp_client_backup_tasks',$tasks);
|
2635 |
+
//}
|
2636 |
}
|
2637 |
|
2638 |
function update_tasks($tasks)
|
2653 |
}
|
2654 |
}
|
2655 |
|
2656 |
+
function replace_htaccess($url, $remote_abspath)
|
2657 |
{
|
2658 |
+
global $wp_filesystem;
|
2659 |
+
//$file = @file_get_contents(ABSPATH.'.htaccess');
|
2660 |
+
$file = $wp_filesystem->get_contents($remote_abspath.'.htaccess');
|
2661 |
+
if ($file && strlen($file)) {
|
2662 |
+
$args = parse_url($url);
|
2663 |
+
$string = rtrim($args['path'], "/");
|
2664 |
+
$regex = "/BEGIN WordPress(.*?)RewriteBase(.*?)\n(.*?)RewriteRule \.(.*?)index\.php(.*?)END WordPress/sm";
|
2665 |
+
$replace = "BEGIN WordPress$1RewriteBase " . $string . "/ \n$3RewriteRule . " . $string . "/index.php$5END WordPress";
|
2666 |
+
$file = preg_replace($regex, $replace, $file);
|
2667 |
+
//@file_put_contents(ABSPATH.'.htaccess', $file);
|
2668 |
+
$wp_filesystem->put_contents($remote_abspath.'.htaccess', $file);
|
2669 |
+
}
|
2670 |
}
|
2671 |
|
2672 |
function check_cron_remove(){
|
2724 |
unset($params['backups']);
|
2725 |
return $params;
|
2726 |
}
|
2727 |
+
|
2728 |
+
function is_server_writable(){
|
2729 |
+
if((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && (get_filesystem_method(array(), ABSPATH) != 'direct'))
|
2730 |
+
return false;
|
2731 |
+
else
|
2732 |
+
return true;
|
2733 |
+
}
|
2734 |
}
|
2735 |
|
2736 |
/*if( function_exists('add_filter') ){
|
init.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: InfiniteWP - Client
|
|
4 |
Plugin URI: http://infinitewp.com/
|
5 |
Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
|
6 |
Author: Revmakx
|
7 |
-
Version: 1.
|
8 |
Author URI: http://www.revmakx.com
|
9 |
*/
|
10 |
/************************************************************
|
@@ -26,7 +26,7 @@ Author URI: http://www.revmakx.com
|
|
26 |
**************************************************************/
|
27 |
|
28 |
if(!defined('IWP_MMB_CLIENT_VERSION'))
|
29 |
-
define('IWP_MMB_CLIENT_VERSION', '1.
|
30 |
|
31 |
|
32 |
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
|
@@ -83,9 +83,6 @@ if( !function_exists ( 'iwp_mmb_filter_params' )) {
|
|
83 |
}
|
84 |
}
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
if( !function_exists ('iwp_mmb_parse_request')) {
|
90 |
function iwp_mmb_parse_request()
|
91 |
{
|
@@ -99,7 +96,7 @@ if( !function_exists ('iwp_mmb_parse_request')) {
|
|
99 |
$data = base64_decode($HTTP_RAW_POST_DATA);
|
100 |
if ($data){
|
101 |
//$num = @extract(unserialize($data));
|
102 |
-
$unserialized_data = unserialize($data);
|
103 |
if(isset($unserialized_data['params'])){
|
104 |
$unserialized_data['params'] = iwp_mmb_filter_params($unserialized_data['params']);
|
105 |
}
|
@@ -133,6 +130,7 @@ if( !function_exists ('iwp_mmb_parse_request')) {
|
|
133 |
|
134 |
$auth = $iwp_mmb_core->authenticate_message($action . $id, $signature, $id);
|
135 |
if ($auth === true) {
|
|
|
136 |
|
137 |
if(isset($params['username']) && !is_user_logged_in()){
|
138 |
$user = function_exists('get_user_by') ? get_user_by('login', $params['username']) : get_userdatabylogin( $params['username'] );
|
4 |
Plugin URI: http://infinitewp.com/
|
5 |
Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
|
6 |
Author: Revmakx
|
7 |
+
Version: 1.2.0
|
8 |
Author URI: http://www.revmakx.com
|
9 |
*/
|
10 |
/************************************************************
|
26 |
**************************************************************/
|
27 |
|
28 |
if(!defined('IWP_MMB_CLIENT_VERSION'))
|
29 |
+
define('IWP_MMB_CLIENT_VERSION', '1.2.0');
|
30 |
|
31 |
|
32 |
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
|
83 |
}
|
84 |
}
|
85 |
|
|
|
|
|
|
|
86 |
if( !function_exists ('iwp_mmb_parse_request')) {
|
87 |
function iwp_mmb_parse_request()
|
88 |
{
|
96 |
$data = base64_decode($HTTP_RAW_POST_DATA);
|
97 |
if ($data){
|
98 |
//$num = @extract(unserialize($data));
|
99 |
+
$unserialized_data = @unserialize($data);
|
100 |
if(isset($unserialized_data['params'])){
|
101 |
$unserialized_data['params'] = iwp_mmb_filter_params($unserialized_data['params']);
|
102 |
}
|
130 |
|
131 |
$auth = $iwp_mmb_core->authenticate_message($action . $id, $signature, $id);
|
132 |
if ($auth === true) {
|
133 |
+
$GLOBALS['IWP_CLIENT_HISTORY_ID'] = $id;
|
134 |
|
135 |
if(isset($params['username']) && !is_user_logged_in()){
|
136 |
$user = function_exists('get_user_by') ? get_user_by('login', $params['username']) : get_userdatabylogin( $params['username'] );
|
lib/amazon_s3/services/s3.class.php
CHANGED
@@ -3686,10 +3686,10 @@ class AmazonS3 extends CFRuntime
|
|
3686 |
{
|
3687 |
$opt['partSize'] = 5242880; // 5 MB
|
3688 |
}
|
3689 |
-
// If more than
|
3690 |
-
elseif ((integer) $opt['partSize'] >
|
3691 |
{
|
3692 |
-
$opt['partSize'] =
|
3693 |
}
|
3694 |
}
|
3695 |
else
|
@@ -3737,6 +3737,7 @@ class AmazonS3 extends CFRuntime
|
|
3737 |
$batch = new CFBatchRequest(isset($opt['limit']) ? (integer) $opt['limit'] : null);
|
3738 |
foreach ($pieces as $i => $piece)
|
3739 |
{
|
|
|
3740 |
$this->batch($batch)->upload_part($bucket, $filename, $upload_id, array(
|
3741 |
'expect' => '100-continue',
|
3742 |
'fileUpload' => $opt['fileUpload'],
|
@@ -3745,6 +3746,7 @@ class AmazonS3 extends CFRuntime
|
|
3745 |
'length' => (integer) $piece['length'],
|
3746 |
));
|
3747 |
}
|
|
|
3748 |
|
3749 |
// Send batch requests
|
3750 |
$batch_responses = $this->batch($batch)->send();
|
3686 |
{
|
3687 |
$opt['partSize'] = 5242880; // 5 MB
|
3688 |
}
|
3689 |
+
// If more than 50 MB...
|
3690 |
+
elseif ((integer) $opt['partSize'] > 52428800)
|
3691 |
{
|
3692 |
+
$opt['partSize'] = 52428800; // 50 MB
|
3693 |
}
|
3694 |
}
|
3695 |
else
|
3737 |
$batch = new CFBatchRequest(isset($opt['limit']) ? (integer) $opt['limit'] : null);
|
3738 |
foreach ($pieces as $i => $piece)
|
3739 |
{
|
3740 |
+
iwp_mmb_auto_print('amazonS3_chucked_upload');
|
3741 |
$this->batch($batch)->upload_part($bucket, $filename, $upload_id, array(
|
3742 |
'expect' => '100-continue',
|
3743 |
'fileUpload' => $opt['fileUpload'],
|
3746 |
'length' => (integer) $piece['length'],
|
3747 |
));
|
3748 |
}
|
3749 |
+
iwp_mmb_auto_print('amazonS3_chucked_upload');
|
3750 |
|
3751 |
// Send batch requests
|
3752 |
$batch_responses = $this->batch($batch)->send();
|
readme.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
Contributors: infinitewp
|
3 |
Tags: admin, administration, amazon, api, authentication, automatic, dashboard, dropbox, events, integration, manage, multisite, multiple, notification, performance, s3, security, seo, stats, tracking, infinitewp, updates, backup, restore, iwp, infinite
|
4 |
Requires at least: 3.0
|
5 |
-
Tested up to: 3.
|
6 |
Stable tag: trunk
|
7 |
|
8 |
Install this plugin on unlimited sites and manage them all from a central dashboard.
|
@@ -48,6 +48,12 @@ Credits: [Vladimir Prelovac](http://prelovac.com/vladimir) for his worker plugin
|
|
48 |
|
49 |
== Changelog ==
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
= 1.1.10 =
|
52 |
* Charset issue fixed for restore / clone
|
53 |
* Dropbox improved
|
2 |
Contributors: infinitewp
|
3 |
Tags: admin, administration, amazon, api, authentication, automatic, dashboard, dropbox, events, integration, manage, multisite, multiple, notification, performance, s3, security, seo, stats, tracking, infinitewp, updates, backup, restore, iwp, infinite
|
4 |
Requires at least: 3.0
|
5 |
+
Tested up to: 3.6
|
6 |
Stable tag: trunk
|
7 |
|
8 |
Install this plugin on unlimited sites and manage them all from a central dashboard.
|
48 |
|
49 |
== Changelog ==
|
50 |
|
51 |
+
= 1.2.0 =
|
52 |
+
* Improvement: Backup fail safe option now uses only php db dump and pclZip
|
53 |
+
* Improvement: Better feedback regarding completion of backups even in case of error
|
54 |
+
* Improvement: Restore using file system (better handling of file permissions)
|
55 |
+
* Fix: Notice issue with unserialise
|
56 |
+
|
57 |
= 1.1.10 =
|
58 |
* Charset issue fixed for restore / clone
|
59 |
* Dropbox improved
|