Changeset 190810
- Timestamp:
- 01/07/2010 07:59:48 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
automatic-wordpress-backup/trunk/automatic-wordpress-backup.php
r190431 r190810 4 4 Plugin URI: http://www.wordpressbackup.org/ 5 5 Description: Automatically upload backups of important parts of your blog to Amazon S3 6 Version: 1.1.0-dev 26 Version: 1.1.0-dev3 7 7 Author: Dan Coulter 8 8 Author URI: http://dancoulter.com/ … … 40 40 41 41 class cmAWB { 42 static $version = '1.1.0-dev 2';42 static $version = '1.1.0-dev3'; 43 43 44 44 /** … … 151 151 } 152 152 $settings = self::get_settings(); 153 153 154 ?> 154 155 <script type="text/javascript"> … … 369 370 action: 'awb_restore', 370 371 backup: $('input[name=restore-backup]:checked').val() 371 }, function(){ 372 }, function(rsp){ 373 console.log(rsp); 372 374 //window.location.reload(); 373 } );375 }, 'text'); 374 376 } 375 377 }); … … 399 401 400 402 function backup($manual = false) { 401 global $wpdb ;403 global $wpdb, $wp_version; 402 404 require_once('S3.php'); 403 405 … … 455 457 $backups[$key] = str_replace(ABSPATH, '', $value); 456 458 } 457 $result = shell_exec('zip -r ' . $file . ' ' . implode(' ', $backups) . ' -x *uploads/awb*');459 $result = shell_exec('zip -r ' . $file . ' ' . implode(' ', apply_filters('awb_backup_folders', $backups)) . ' -x *uploads/awb*'); 458 460 459 461 chdir(WP_CONTENT_DIR . '/uploads/awb'); … … 492 494 } 493 495 494 file_put_contents('manifest.txt', "Backup generated by Automatic WordPress Backup v" . self::$version . " on " . date('Y-m-d H:i:s T') ." \n\nThe following sections were backed up:\n * " . implode("\n * ", $manifest) . "\n\nMachine Readable: " . serialize(array('time'=>time(),'version'=>self::$version, 'sections'=>$sections)));496 file_put_contents('manifest.txt', "Backup generated by Automatic WordPress Backup v" . self::$version . " on " . date('Y-m-d H:i:s T') ." with WordPress " . $wp_version . "\n\nThe following sections were backed up:\n * " . implode("\n * ", $manifest) . "\n\nMachine Readable: " . serialize(array('wordpress'=>$wp_version,'time'=>time(),'version'=>self::$version, 'sections'=>$sections))); 495 497 $result = shell_exec('zip -u ' . $file . ' manifest.txt'); 496 498 @unlink('manifest.txt'); … … 508 510 509 511 chdir($cwd); 510 511 512 } 512 513 … … 531 532 532 533 function restore() { 533 if ( !wp_verify_nonce($_GET['_wpnonce'], 'awb') ) die("invalid nonce"); 534 //self::backup(true); 534 if ( !wp_verify_nonce($_GET['_wpnonce'], 'awb') ) die("{success: false, error: 'Invalid nonce'}"); 535 536 global $wpdb, $wp_version; 535 537 536 538 require_once('S3.php'); … … 541 543 542 544 $awb_dir = WP_CONTENT_DIR . '/uploads/awb'; 543 mkdir($awb_dir . '/tmp'); 544 545 $restore_dir = $awb_dir . '/tmp'; 546 547 mkdir($restore_dir); 545 548 $cwd = getcwd(); 546 chdir($ awb_dir . '/tmp');549 chdir($restore_dir); 547 550 exec("wget --no-check-certificate -O backup.zip '" . $s3->getObjectURL(get_option('s3b-bucket'), $_POST['backup']) . "'"); 548 551 exec('unzip backup.zip'); 549 $contents = self::rscandir($awb_dir . '/tmp', true); 552 $contents = self::rscandir($restore_dir, true); 553 554 if ( !is_file('manifest.txt') ) { 555 chdir($cwd); 556 self::rrmdir($restore_dir); 557 die(json_encode(array('success' => false, 'error' => __("No manifest was found. It is possible that an old version of this plugin created a backup that is not able to be automatically restored.")))); 558 die("{success: false, error: ''}"); 559 } 560 561 $manifest = file_get_contents('manifest.txt'); 562 if ( !(preg_match('|Machine Readable: (.*)|', $manifest, $matches) && ($manifest = unserialize($matches[1]))) ) { 563 chdir($cwd); 564 self::rrmdir($restore_dir); 565 die(json_encode(array('success' => false, 'error' => __('The file manifest seems to be corrupted. There may be a problem with your backup.')))); 566 } 567 568 $manifest['test'] = (float) $wp_version; 569 if ( (float) $manifest['wordpress'] > (float) $wp_version ) { 570 chdir($cwd); 571 self::rrmdir($restore_dir); 572 die(json_encode(array('success' => false, 'error' => __('Cannot restore to an older version of WordPress'), 'manifest' => $manifest))); 573 } 574 575 // Run a manual backup... 576 //self::backup(true); 577 578 foreach ( $manifest['sections'] as $section ) { 579 switch ( $section ) { 580 case 'database': 581 $wpdb->show_errors(); 582 $sql = file_get_contents('awb-database-backup.sql'); 583 $sql = preg_replace('|^\#.*$|m', '', $sql); 584 $sql = explode(";\n", $sql); 585 foreach ( $sql as $statement ) { 586 if ( trim($statement) != '' ) { 587 $wpdb->query($statement); 588 } 589 } 590 break; 591 } 592 } 593 594 chdir($cwd); 595 self::rrmdir($awb_dir . '/tmp'); 596 die(json_encode(array('success' => true, 'manifest' => $manifest))); 597 598 //self::backup(true); 599 600 /* 601 550 602 551 603 if ( file_exists($awb_dir . '/tmp/wp-content/uploads/awb/awb-database-backup.sql') ) { … … 594 646 595 647 exit; 648 */ 596 649 } 597 650 … … 744 797 } 745 798 } 746 $output .= " \n" . $entries . implode(', ', $values) . ');';799 $output .= "\n" . $entries . implode(', ', $values) . ');'; 747 800 } 748 801 $row_start += $row_inc;
Note: See TracChangeset
for help on using the changeset viewer.