WP-DB-Backup - Version 2.0.6

Version Description

Download this release

Release Info

Developer filosofo
Plugin Icon 128x128 WP-DB-Backup
Version 2.0.6
Comparing to
See all releases

Code changes from version 2.0.5 to 2.0.6

Files changed (2) hide show
  1. readme.txt +1 -1
  2. wp-db-backup.php +87 -81
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.ilfilosofo.com/blog/wp-db-backup/
4
  Tags: mysql, database, backup, cron
5
  Requires at least: 2.0
6
  Tested up to: 2.2
7
- Stable tag: 2.0.5
8
 
9
  On-demand backup of your WordPress database.
10
 
4
  Tags: mysql, database, backup, cron
5
  Requires at least: 2.0
6
  Tested up to: 2.2
7
+ Stable tag: 2.0.6
8
 
9
  On-demand backup of your WordPress database.
10
 
wp-db-backup.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.ilfilosofo.com/blog/wp-db-backup
5
  Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup.php">Manage &rarr; Backup</a> to get started.
6
  Author: Austin Matzko
7
  Author URI: http://www.ilfilosofo.com/blog/
8
- Version: 2.0.5
9
 
10
  Development continued from that done by Skippy (http://www.skippy.net/)
11
 
@@ -32,15 +32,24 @@ Copyright 2007 Austin Matzko (email : if.website at gmail.com)
32
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33
  */
34
 
35
- // CHANGE THIS IF YOU WANT TO USE A
36
- // DIFFERENT BACKUP LOCATION
 
 
37
 
38
  $rand = substr( md5( md5( DB_PASSWORD ) ), -5 );
39
-
40
  define('WP_BACKUP_DIR', 'wp-content/backup-' . $rand);
41
 
42
  define('ROWS_PER_SEGMENT', 100);
43
 
 
 
 
 
 
 
 
 
44
  class wpdbBackup {
45
 
46
  var $backup_complete = false;
@@ -54,6 +63,15 @@ class wpdbBackup {
54
  return function_exists('gzopen');
55
  }
56
 
 
 
 
 
 
 
 
 
 
57
  function wpdbBackup() {
58
  global $table_prefix, $wpdb;
59
  load_plugin_textdomain('wp-db-backup');
@@ -233,12 +251,17 @@ class wpdbBackup {
233
  $rec_count = $wpdb->get_var("SELECT count(*) FROM {$table}");
234
  $rec_segments = ceil($rec_count / ROWS_PER_SEGMENT);
235
  $table_count = 0;
 
 
 
 
 
236
  do {
237
- echo "case {$step_count}: backup(\"{$table}\", {$table_count}); break;\n";
238
  $step_count++;
239
  $table_count++;
240
  } while($table_count < $rec_segments);
241
- echo "case {$step_count}: backup(\"{$table}\", -1); break;\n";
242
  $step_count++;
243
  }
244
  echo "case {$step_count}: finishBackup(); break;";
@@ -359,58 +382,50 @@ class wpdbBackup {
359
  add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', basename(__FILE__), array(&$this, 'build_backup_script'));
360
  }
361
 
 
 
 
 
362
  function sql_addslashes($a_string = '', $is_like = FALSE) {
363
- /*
364
- Better addslashes for SQL queries.
365
- Taken from phpMyAdmin.
366
- */
367
- if ($is_like) {
368
- $a_string = str_replace('\\', '\\\\\\\\', $a_string);
369
- } else {
370
- $a_string = str_replace('\\', '\\\\', $a_string);
371
- }
372
- $a_string = str_replace('\'', '\\\'', $a_string);
373
-
374
- return $a_string;
375
- } // function sql_addslashes($a_string = '', $is_like = FALSE)
376
 
 
 
 
 
377
  function backquote($a_name) {
378
- /*
379
- Add backqouotes to tables and db-names in
380
- SQL queries. Taken from phpMyAdmin.
381
- */
382
- if (!empty($a_name) && $a_name != '*') {
383
- if (is_array($a_name)) {
384
- $result = array();
385
- reset($a_name);
386
- while(list($key, $val) = each($a_name)) {
387
- $result[$key] = '`' . $val . '`';
388
- }
389
- return $result;
390
- } else {
391
- return '`' . $a_name . '`';
392
- }
393
- } else {
394
- return $a_name;
395
- }
396
- } // function backquote($a_name, $do_it = TRUE)
397
 
398
  function open($filename = '', $mode = 'w') {
399
  if ('' == $filename) return false;
400
- if ($this->gzip()) {
401
  $fp = @gzopen($filename, $mode);
402
- } else {
403
  $fp = @fopen($filename, $mode);
404
- }
405
  return $fp;
406
  }
407
 
408
  function close($fp) {
409
- if ($this->gzip()) {
410
  gzclose($fp);
411
- } else {
412
  fclose($fp);
413
- }
414
  }
415
 
416
  function stow($query_line) {
@@ -428,24 +443,22 @@ class wpdbBackup {
428
  }
429
 
430
  function backup_error($err) {
431
- if(count($this->backup_errors) < 20) {
432
  $this->backup_errors[] = $err;
433
- } elseif(count($this->backup_errors) == 20) {
434
  $this->backup_errors[] = __('Subsequent errors have been omitted from this log.','wp-db-backup');
435
- }
436
  }
437
 
 
 
 
 
 
 
 
 
438
  function backup_table($table, $segment = 'none') {
439
  global $wpdb;
440
-
441
- /*
442
- Taken partially from phpMyAdmin and partially from
443
- Alain Wolf, Zurich - Switzerland
444
- Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
445
-
446
- Modified by Scott Merril (http://www.skippy.net/)
447
- to use the WordPress $wpdb object
448
- */
449
 
450
  $table_structure = $wpdb->get_results("DESCRIBE $table");
451
  if (! $table_structure) {
@@ -545,7 +558,6 @@ class wpdbBackup {
545
  } while((count($table_data) > 0) and ($segment=='none'));
546
  }
547
 
548
-
549
  if(($segment == 'none') || ($segment < 0)) {
550
  // Create footer/closing comment in SQL-file
551
  $this->stow("\n");
@@ -554,23 +566,21 @@ class wpdbBackup {
554
  $this->stow("# --------------------------------------------------------\n");
555
  $this->stow("\n");
556
  }
557
-
558
  } // end backup_table()
559
 
560
  function return_bytes($val) {
561
- $val = trim($val);
562
- $last = strtolower($val{strlen($val)-1});
563
- switch($last) {
564
- // The 'G' modifier is available since PHP 5.1.0
565
- case 'g':
566
- $val *= 1024;
567
- case 'm':
568
- $val *= 1024;
569
- case 'k':
570
- $val *= 1024;
571
- }
572
-
573
- return $val;
574
  }
575
 
576
  function db_backup($core_tables, $other_tables) {
@@ -578,9 +588,8 @@ class wpdbBackup {
578
 
579
  $datum = date("Ymd_B");
580
  $wp_backup_filename = DB_NAME . "_$table_prefix$datum.sql";
581
- if ($this->gzip()) {
582
- $wp_backup_filename .= '.gz';
583
- }
584
 
585
  if (is_writable(ABSPATH . $this->backup_dir)) {
586
  $this->fp = $this->open(ABSPATH . $this->backup_dir . $wp_backup_filename);
@@ -774,9 +783,8 @@ class wpdbBackup {
774
  // Get list of non-WP tables
775
  $other_tables = array_diff($all_tables, $wp_backup_default_tables);
776
 
777
- if ('' != $feedback) {
778
  echo $feedback;
779
- }
780
 
781
  // Give the new dirs the same perms as wp-content.
782
  $stat = stat( ABSPATH . 'wp-content' );
@@ -786,18 +794,17 @@ class wpdbBackup {
786
  if ( @ mkdir( ABSPATH . $this->backup_dir) ) {
787
  @ chmod( ABSPATH . $this->backup_dir, $dir_perms);
788
  } else {
789
- echo '<div class="updated error"><p align="center">' . __('WARNING: Your wp-content directory is <strong>NOT</strong> writable! We can not create the backup directory.','wp-db-backup') . '<br />' . ABSPATH . $this->backup_dir . "</p></div>";
790
  $WHOOPS = TRUE;
791
  }
792
  }
793
 
794
  if ( !is_writable( ABSPATH . $this->backup_dir) ) {
795
- echo '<div class="updated error"><p align="center">' . __('WARNING: Your backup directory is <strong>NOT</strong> writable! We can not create the backup directory.','wp-db-backup') . '<br />' . ABSPATH . "</p></div>";
796
  }
797
 
798
- if ( !file_exists( ABSPATH . $this->backup_dir . 'index.php') ) {
799
  @ touch( ABSPATH . $this->backup_dir . "index.php");
800
- }
801
 
802
  ?><div class='wrap'>
803
  <h2><?php _e('Backup','wp-db-backup') ?></h2>
@@ -996,5 +1003,4 @@ function wpdbBackup_init() {
996
  }
997
 
998
  add_action('plugins_loaded', 'wpdbBackup_init');
999
-
1000
  ?>
5
  Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup.php">Manage &rarr; Backup</a> to get started.
6
  Author: Austin Matzko
7
  Author URI: http://www.ilfilosofo.com/blog/
8
+ Version: 2.0.6
9
 
10
  Development continued from that done by Skippy (http://www.skippy.net/)
11
 
32
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33
  */
34
 
35
+ /**
36
+ * Change WP_BACKUP_DIR if you want to
37
+ * use a different backup location
38
+ */
39
 
40
  $rand = substr( md5( md5( DB_PASSWORD ) ), -5 );
 
41
  define('WP_BACKUP_DIR', 'wp-content/backup-' . $rand);
42
 
43
  define('ROWS_PER_SEGMENT', 100);
44
 
45
+ /**
46
+ * Set MOD_EVASIVE_OVERRIDE to true
47
+ * and increase MOD_EVASIVE_DELAY
48
+ * if the backup stops prematurely.
49
+ */
50
+ define('MOD_EVASIVE_OVERRIDE', false);
51
+ define('MOD_EVASIVE_DELAY', '500');
52
+
53
  class wpdbBackup {
54
 
55
  var $backup_complete = false;
63
  return function_exists('gzopen');
64
  }
65
 
66
+ function module_check() {
67
+ $mod_evasive = false;
68
+ if ( true == MOD_EVASIVE_OVERRIDE ) return true;
69
+ if ( function_exists('apache_get_modules') )
70
+ foreach( (array) apache_get_modules() as $mod )
71
+ if ( false !== strpos($mod,'mod_evasive') || false !== strpos($mod,'mod_dosevasive') ) $mod_evasive = true;
72
+ return $mod_evasive;
73
+ }
74
+
75
  function wpdbBackup() {
76
  global $table_prefix, $wpdb;
77
  load_plugin_textdomain('wp-db-backup');
251
  $rec_count = $wpdb->get_var("SELECT count(*) FROM {$table}");
252
  $rec_segments = ceil($rec_count / ROWS_PER_SEGMENT);
253
  $table_count = 0;
254
+ if ( $this->module_check() ) {
255
+ $delay = "setTimeout('";
256
+ $delay_time = "', " . (int) MOD_EVASIVE_DELAY . ")";
257
+ }
258
+ else { $delay = $delay_time = ''; }
259
  do {
260
+ echo "case {$step_count}: {$delay}backup(\"{$table}\", {$table_count}){$delay_time}; break;\n";
261
  $step_count++;
262
  $table_count++;
263
  } while($table_count < $rec_segments);
264
+ echo "case {$step_count}: {$delay}backup(\"{$table}\", -1){$delay_time}; break;\n";
265
  $step_count++;
266
  }
267
  echo "case {$step_count}: finishBackup(); break;";
382
  add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', basename(__FILE__), array(&$this, 'build_backup_script'));
383
  }
384
 
385
+ /**
386
+ * Better addslashes for SQL queries.
387
+ * Taken from phpMyAdmin.
388
+ */
389
  function sql_addslashes($a_string = '', $is_like = FALSE) {
390
+ if ($is_like) $a_string = str_replace('\\', '\\\\\\\\', $a_string);
391
+ else $a_string = str_replace('\\', '\\\\', $a_string);
392
+ return str_replace('\'', '\\\'', $a_string);
393
+ }
 
 
 
 
 
 
 
 
 
394
 
395
+ /**
396
+ * Add backquotes to tables and db-names in
397
+ * SQL queries. Taken from phpMyAdmin.
398
+ */
399
  function backquote($a_name) {
400
+ if (!empty($a_name) && $a_name != '*') {
401
+ if (is_array($a_name)) {
402
+ $result = array();
403
+ reset($a_name);
404
+ while(list($key, $val) = each($a_name))
405
+ $result[$key] = '`' . $val . '`';
406
+ return $result;
407
+ } else {
408
+ return '`' . $a_name . '`';
409
+ }
410
+ } else {
411
+ return $a_name;
412
+ }
413
+ }
 
 
 
 
 
414
 
415
  function open($filename = '', $mode = 'w') {
416
  if ('' == $filename) return false;
417
+ if ($this->gzip())
418
  $fp = @gzopen($filename, $mode);
419
+ else
420
  $fp = @fopen($filename, $mode);
 
421
  return $fp;
422
  }
423
 
424
  function close($fp) {
425
+ if ($this->gzip())
426
  gzclose($fp);
427
+ else
428
  fclose($fp);
 
429
  }
430
 
431
  function stow($query_line) {
443
  }
444
 
445
  function backup_error($err) {
446
+ if(count($this->backup_errors) < 20)
447
  $this->backup_errors[] = $err;
448
+ elseif(count($this->backup_errors) == 20)
449
  $this->backup_errors[] = __('Subsequent errors have been omitted from this log.','wp-db-backup');
 
450
  }
451
 
452
+ /**
453
+ * Taken partially from phpMyAdmin and partially from
454
+ * Alain Wolf, Zurich - Switzerland
455
+ * Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
456
+
457
+ * Modified by Scott Merril (http://www.skippy.net/)
458
+ * to use the WordPress $wpdb object
459
+ */
460
  function backup_table($table, $segment = 'none') {
461
  global $wpdb;
 
 
 
 
 
 
 
 
 
462
 
463
  $table_structure = $wpdb->get_results("DESCRIBE $table");
464
  if (! $table_structure) {
558
  } while((count($table_data) > 0) and ($segment=='none'));
559
  }
560
 
 
561
  if(($segment == 'none') || ($segment < 0)) {
562
  // Create footer/closing comment in SQL-file
563
  $this->stow("\n");
566
  $this->stow("# --------------------------------------------------------\n");
567
  $this->stow("\n");
568
  }
 
569
  } // end backup_table()
570
 
571
  function return_bytes($val) {
572
+ $val = trim($val);
573
+ $last = strtolower($val{strlen($val)-1});
574
+ switch($last) {
575
+ // The 'G' modifier is available since PHP 5.1.0
576
+ case 'g':
577
+ $val *= 1024;
578
+ case 'm':
579
+ $val *= 1024;
580
+ case 'k':
581
+ $val *= 1024;
582
+ }
583
+ return $val;
 
584
  }
585
 
586
  function db_backup($core_tables, $other_tables) {
588
 
589
  $datum = date("Ymd_B");
590
  $wp_backup_filename = DB_NAME . "_$table_prefix$datum.sql";
591
+ if ($this->gzip())
592
+ $wp_backup_filename .= '.gz';
 
593
 
594
  if (is_writable(ABSPATH . $this->backup_dir)) {
595
  $this->fp = $this->open(ABSPATH . $this->backup_dir . $wp_backup_filename);
783
  // Get list of non-WP tables
784
  $other_tables = array_diff($all_tables, $wp_backup_default_tables);
785
 
786
+ if ('' != $feedback)
787
  echo $feedback;
 
788
 
789
  // Give the new dirs the same perms as wp-content.
790
  $stat = stat( ABSPATH . 'wp-content' );
794
  if ( @ mkdir( ABSPATH . $this->backup_dir) ) {
795
  @ chmod( ABSPATH . $this->backup_dir, $dir_perms);
796
  } else {
797
+ echo '<div class="updated error"><p style="text-align:center">' . __('WARNING: Your wp-content directory is <strong>NOT</strong> writable! We can not create the backup directory.','wp-db-backup') . '<br />' . ABSPATH . $this->backup_dir . "</p></div>";
798
  $WHOOPS = TRUE;
799
  }
800
  }
801
 
802
  if ( !is_writable( ABSPATH . $this->backup_dir) ) {
803
+ echo '<div class="updated error"><p style="text-align:center">' . __('WARNING: Your backup directory is <strong>NOT</strong> writable! We can not create the backup directory.','wp-db-backup') . '<br />' . ABSPATH . "</p></div>";
804
  }
805
 
806
+ if ( !file_exists( ABSPATH . $this->backup_dir . 'index.php') )
807
  @ touch( ABSPATH . $this->backup_dir . "index.php");
 
808
 
809
  ?><div class='wrap'>
810
  <h2><?php _e('Backup','wp-db-backup') ?></h2>
1003
  }
1004
 
1005
  add_action('plugins_loaded', 'wpdbBackup_init');
 
1006
  ?>