BackUpWordPress - Version 1.2

Version Description

Download this release

Release Info

Developer willmot
Plugin Icon 128x128 BackUpWordPress
Version 1.2
Comparing to
See all releases

Code changes from version 1.1.4 to 1.2

admin.actions.php CHANGED
@@ -24,15 +24,18 @@ add_action( 'load-tools_page_' . HMBKP_PLUGIN_SLUG, 'hmbkp_request_delete_backup
24
  function hmbkp_request_do_backup() {
25
 
26
  // Are we sure
27
- if ( !isset( $_GET['action'] ) || $_GET['action'] !== 'hmbkp_backup_now' || hmbkp_is_in_progress() || !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) )
28
  return false;
29
-
30
  // Schedule a single backup
31
  wp_schedule_single_event( time(), 'hmbkp_schedule_single_backup_hook' );
32
 
33
- // Fire the cron now
34
- wp_cron();
35
 
 
 
 
36
  // Redirect back
37
  wp_redirect( remove_query_arg( 'action' ) );
38
  exit;
@@ -55,7 +58,16 @@ function hmbkp_request_download_backup() {
55
  add_action( 'load-tools_page_' . HMBKP_PLUGIN_SLUG, 'hmbkp_request_download_backup' );
56
 
57
  function hmbkp_ajax_is_backup_in_progress() {
58
- echo (int) hmbkp_is_in_progress();
 
 
 
 
 
 
 
 
 
59
  exit;
60
  }
61
  add_action( 'wp_ajax_hmbkp_is_in_progress', 'hmbkp_ajax_is_backup_in_progress' );
@@ -64,4 +76,17 @@ function hmbkp_ajax_calculate_backup_size() {
64
  echo hmbkp_calculate();
65
  exit;
66
  }
67
- add_action( 'wp_ajax_hmbkp_calculate', 'hmbkp_ajax_calculate_backup_size' );
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  function hmbkp_request_do_backup() {
25
 
26
  // Are we sure
27
+ if ( !isset( $_GET['action'] ) || $_GET['action'] !== 'hmbkp_backup_now' || hmbkp_is_in_progress() || !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || ini_get( 'safe_mode' ) )
28
  return false;
29
+
30
  // Schedule a single backup
31
  wp_schedule_single_event( time(), 'hmbkp_schedule_single_backup_hook' );
32
 
33
+ // Remove the once every 60 seconds limitation
34
+ delete_transient( 'doing_cron' );
35
 
36
+ // Fire the cron now
37
+ spawn_cron();
38
+
39
  // Redirect back
40
  wp_redirect( remove_query_arg( 'action' ) );
41
  exit;
58
  add_action( 'load-tools_page_' . HMBKP_PLUGIN_SLUG, 'hmbkp_request_download_backup' );
59
 
60
  function hmbkp_ajax_is_backup_in_progress() {
61
+
62
+ if ( !hmbkp_is_in_progress() )
63
+ echo 0;
64
+
65
+ elseif ( get_option( 'hmbkp_status' ) )
66
+ echo get_option( 'hmbkp_status' );
67
+
68
+ else
69
+ echo 1;
70
+
71
  exit;
72
  }
73
  add_action( 'wp_ajax_hmbkp_is_in_progress', 'hmbkp_ajax_is_backup_in_progress' );
76
  echo hmbkp_calculate();
77
  exit;
78
  }
79
+ add_action( 'wp_ajax_hmbkp_calculate', 'hmbkp_ajax_calculate_backup_size' );
80
+
81
+ function hmbkp_ajax_cron_test() {
82
+
83
+ $response = wp_remote_get( site_url( 'wp-cron.php' ) );
84
+
85
+ if ( !is_wp_error( $response ) && $response['response']['code'] != '200' )
86
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( '%s is returning a %s response which could mean cron jobs aren\'t getting fired properly. BackUpWordPress relies on wp-cron to run back ups in a separate process.', 'hmbkp' ), '<code>wp-cron.php</code>', '<code>' . $response['response']['code'] . '</code>' ) . '</p></div>';
87
+ else
88
+ echo 1;
89
+
90
+ exit;
91
+ }
92
+ add_action( 'wp_ajax_hmbkp_cron_test', 'hmbkp_ajax_cron_test' );
admin.page.php CHANGED
@@ -1,15 +1,15 @@
1
  <div class="wrap<?php if ( hmbkp_is_in_progress() ) { ?> hmbkp_running<?php } ?>">
2
 
3
- <?php screen_icon( 'tools' ); ?>
4
 
5
  <h2>
6
 
7
  <?php _e( 'Manage Backups', 'hmbkp' ); ?>
8
 
9
  <?php if ( hmbkp_is_in_progress() ) : ?>
10
- <a class="button add-new-h2" <?php disabled( true ); ?>><img src="<?php echo site_url( 'wp-admin/images/wpspin_light.gif' ); ?>" width="16" height="16" /><?php _e( 'Backup Running', 'hmbkp' ); ?></a>
11
 
12
- <?php elseif ( !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) ) : ?>
13
  <a class="button add-new-h2" <?php disabled( true ); ?>><?php _e( 'Back Up Now', 'hmbkp' ); ?></a>
14
 
15
  <?php else : ?>
@@ -21,7 +21,7 @@
21
 
22
  </h2>
23
 
24
- <?php if ( is_dir( hmbkp_path() ) && is_writable( hmbkp_path() ) ) : ?>
25
 
26
  <p>
27
 
@@ -40,11 +40,11 @@
40
  else
41
  $what_to_backup = '<code>' . __( 'files', 'hmbkp' ) . '</code>'; ?>
42
 
43
- <?php printf( __( 'Your %s will be automatically backed up every day at %s to %s.', 'hmbkp' ), $what_to_backup , '<code title="' . sprintf( __( 'It\'s currently %s on the server.', 'hmbkp' ), date( 'H:i' ) ) . '">' . date( 'H:i', wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) . '</code>', '<code>' . trailingslashit( hmbkp_path() ) . '</code>' ); ?>
44
 
45
  <?php endif; ?>
46
 
47
- <span class="hmbkp_estimated-size"><?php printf( __( 'Each backup will be approximately %s.', 'hmbkp' ), get_transient( 'hmbkp_estimated_filesize' ) ? '<code>' . hmbkp_calculate() . '</code>' : '<code class="calculate">' . __( 'Calculating Size...', 'hmbkp' ) . '</code>' ); ?></span>
48
 
49
  </p>
50
 
@@ -74,13 +74,17 @@
74
  <?php endif; ?>
75
  <?php endif ; ?>
76
 
 
 
 
 
77
  <?php $backup_archives = hmbkp_get_backups();
78
  if ( count( $backup_archives ) ) : ?>
79
 
80
  <table class="widefat" id="hmbkp_manage_backups_table">
81
  <thead>
82
  <tr>
83
- <th scope="col"><?php _e( 'Completed Backups', 'hmbkp' ); ?></th>
84
  <th scope="col"><?php _e( 'Size', 'hmbkp' ); ?></th>
85
  <th scope="col"><?php _e( 'Actions', 'hmbkp' ); ?></th>
86
  </tr>
@@ -88,8 +92,8 @@
88
 
89
  <tfoot>
90
  <tr>
91
- <th><?php printf( _n( 'Only the most recent backup will be saved.', 'The %d most recent backups will be saved.', hmbkp_max_backups(), 'hmbkp' ), hmbkp_max_backups() ); ?></th>
92
- <th><?php printf( __( 'Total %s', 'hmbkp' ), hmbkp_total_filesize() ); ?></th>
93
  <th></th>
94
  </tr>
95
  </tfoot>
@@ -119,38 +123,41 @@
119
 
120
  <h4><?php _e( 'Advanced Options', 'hmbkp' ); ?></h4>
121
 
122
- <p><?php printf( __( 'You can %s any of the following %s in your %s to control advanced options.', 'hmbkp' ), '<code>define</code>', '<code>Constants</code>', '<code>wp-config.php</code>' ); ?></p>
123
 
124
  <dl>
125
 
126
- <dt><code>HMBKP_PATH</code></dt>
127
- <dd><?php printf( __( 'The path to folder you would like to store your backup files in, defaults to %s', 'hmbkp' ), '<code>' . hmbkp_path() . '</code>' ); ?></dd>
 
 
 
128
 
129
- <dt><code>HMBKP_MYSQLDUMP_PATH</code></dt>
130
- <dd><?php printf( __( 'The path to your %s executable. Will be used for the %s part of the backup if available.', 'hmbkp' ), '<code>mysqldump</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>' ); ?></dd>
131
 
132
- <dt><code>HMBKP_ZIP_PATH</code></dt>
133
- <dd><?php printf( __( 'The path to your %s executable. Will be used to zip up your %s if available.', 'hmbkp' ), '<code>zip</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>' ); ?></dd>
134
 
135
- <dt><code>HMBKP_DISABLE_AUTOMATIC_BACKUP</code></dt>
136
- <dd><?php _e( 'Completely disables the automatic backup. You can still back up using the "Back Up Now" button.', 'hmbkp' ); ?></dd>
137
 
138
- <dt><code>HMBKP_MAX_BACKUPS</code></dt>
139
- <dd><?php _e( 'Number of backups to keep, older backups will be deleted automatically when a new backup is completed.', 'hmbkp' ); ?></dd>
140
 
141
- <dt><code>HMBKP_FILES_ONLY</code></dt>
142
- <dd><?php printf( __( 'Backup %s only, your %s will %s be backed up.', 'hmbkp' ), '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>' ); ?></dd>
143
 
144
- <dt><code>HMBKP_DATABASE_ONLY</code></dt>
145
- <dd><?php printf( __( 'Backup %s only, your %s will %s be backed up.', 'hmbkp' ), '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>' ); ?></dd>
146
 
147
- <dt><code>HMBKP_DAILY_SCHEDULE_TIME</code></dt>
148
- <dd><?php printf( __( 'The time that the daily backup should run. Uses 24 hour clock format %s.', 'hmbkp' ), '<code>23:00</code>' ); ?></dd>
149
 
150
  </dl>
151
 
152
  </div>
153
 
154
- <p class="howto"><?php printf( __( 'If you need help getting things working you are more than welcome to email us at %s and we\'ll do what we can.', 'hmbkp' ), '<a href="mailto:support@humanmade.co.uk">support@humanmade.co.uk</a>' ); ?></p>
155
 
156
  </div>
1
  <div class="wrap<?php if ( hmbkp_is_in_progress() ) { ?> hmbkp_running<?php } ?>">
2
 
3
+ <?php screen_icon( 'backupwordpress' ); ?>
4
 
5
  <h2>
6
 
7
  <?php _e( 'Manage Backups', 'hmbkp' ); ?>
8
 
9
  <?php if ( hmbkp_is_in_progress() ) : ?>
10
+ <a class="button add-new-h2" <?php disabled( true ); ?>><img src="<?php echo site_url( 'wp-admin/images/wpspin_light.gif' ); ?>" width="16" height="16" /><?php echo get_option( 'hmbkp_status' ); ?></a>
11
 
12
+ <?php elseif ( !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || ini_get( 'safe_mode' ) ) : ?>
13
  <a class="button add-new-h2" <?php disabled( true ); ?>><?php _e( 'Back Up Now', 'hmbkp' ); ?></a>
14
 
15
  <?php else : ?>
21
 
22
  </h2>
23
 
24
+ <?php if ( is_dir( hmbkp_path() ) && is_writable( hmbkp_path() ) && !ini_get( 'safe_mode' ) ) : ?>
25
 
26
  <p>
27
 
40
  else
41
  $what_to_backup = '<code>' . __( 'files', 'hmbkp' ) . '</code>'; ?>
42
 
43
+ <?php printf( __( 'Your %s will be automatically backed up every day at %s into %s.', 'hmbkp' ), $what_to_backup , '<code title="' . sprintf( __( 'It\'s currently %s on the server.', 'hmbkp' ), date( 'H:i' ) ) . '">' . date( 'H:i', wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) . '</code>', '<code>' . hmbkp_path() . '</code>' ); ?>
44
 
45
  <?php endif; ?>
46
 
47
+ <span class="hmbkp_estimated-size"><?php printf( __( 'Each backup will be roughly %s.', 'hmbkp' ), get_transient( 'hmbkp_estimated_filesize' ) ? '<code>' . hmbkp_calculate() . '</code>' : '<code class="calculate">' . __( 'Calculating Size...', 'hmbkp' ) . '</code>' ); ?></span>
48
 
49
  </p>
50
 
74
  <?php endif; ?>
75
  <?php endif ; ?>
76
 
77
+ <?php if ( defined( 'HMBKP_EMAIL' ) && HMBKP_EMAIL && is_email( HMBKP_EMAIL ) ) : ?>
78
+ <p>&#10003; <?php printf( __( 'A copy of each backup will be emailed to %s.', 'hmbkp' ), '<code>' . HMBKP_EMAIL . '</code>' ); ?></p>
79
+ <?php endif; ?>
80
+
81
  <?php $backup_archives = hmbkp_get_backups();
82
  if ( count( $backup_archives ) ) : ?>
83
 
84
  <table class="widefat" id="hmbkp_manage_backups_table">
85
  <thead>
86
  <tr>
87
+ <th scope="col"><?php printf( __( '%d Completed backups', 'hmbkp' ), count( $backup_archives ) ); ?></th>
88
  <th scope="col"><?php _e( 'Size', 'hmbkp' ); ?></th>
89
  <th scope="col"><?php _e( 'Actions', 'hmbkp' ); ?></th>
90
  </tr>
92
 
93
  <tfoot>
94
  <tr>
95
+ <th><?php printf( _n( 'Only the most recent backup will be saved', 'The %d most recent backups will be saved', hmbkp_max_backups(), 'hmbkp' ), hmbkp_max_backups() ); ?></th>
96
+ <th><?php printf( __( 'Total %s, %s available', 'hmbkp' ), hmbkp_total_filesize(), hmbkp_size_readable( disk_free_space( ABSPATH ), null, '%01u %s' ) ); ?></th>
97
  <th></th>
98
  </tr>
99
  </tfoot>
123
 
124
  <h4><?php _e( 'Advanced Options', 'hmbkp' ); ?></h4>
125
 
126
+ <p><?php printf( __( 'You can %s any of the following %s in your %s to control advanced options. %s. Defined %s will be highlighted.', 'hmbkp' ), '<code>define</code>', '<code>Constants</code>', '<code>wp-config.php</code>', '<a href="http://codex.wordpress.org/Editing_wp-config.php">' . __( 'The Codex can help', 'hmbkp' ) . '</a>', '<code>Constants</code>' ); ?></p>
127
 
128
  <dl>
129
 
130
+ <dt<?php if ( defined( 'HMBKP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_PATH</code></dt>
131
+ <dd><?php printf( __( 'The path to folder you would like to store your backup files in, defaults to %s.', 'hmbkp' ), '<code>' . hmbkp_path() . '</code>' ); ?></dd>
132
+
133
+ <dt<?php if ( defined( 'HMBKP_MYSQLDUMP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_MYSQLDUMP_PATH</code></dt>
134
+ <dd><?php printf( __( 'The path to your %s executable. Will be used for the %s part of the back up if available.', 'hmbkp' ), '<code>mysqldump</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>' ); ?></dd>
135
 
136
+ <dt<?php if ( defined( 'HMBKP_ZIP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_ZIP_PATH</code></dt>
137
+ <dd><?php printf( __( 'The path to your %s executable. Will be used to zip up your %s and %s if available.', 'hmbkp' ), '<code>zip</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>' ); ?></dd>
138
 
139
+ <dt<?php if ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DISABLE_AUTOMATIC_BACKUP</code></dt>
140
+ <dd><?php printf( __( 'Completely disables the automatic back up. You can still back up using the "Back Up Now" button. Defaults to %s.', 'hmbkp' ), '<code>(bool) false</code>' ); ?></dd>
141
 
142
+ <dt<?php if ( defined( 'HMBKP_MAX_BACKUPS' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_MAX_BACKUPS</code></dt>
143
+ <dd><?php printf( __( 'Number of backups to keep, older backups will be deleted automatically when a new backup is completed. Detaults to %s.', 'hmbkp' ), '<code>(int) 10</code>' ); ?></dd>
144
 
145
+ <dt<?php if ( defined( 'HMBKP_FILES_ONLY' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_FILES_ONLY</code></dt>
146
+ <dd><?php printf( __( 'Backup %s only, your %s will %s be backed up. Defaults to %s.', 'hmbkp' ), '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>', '<code>(bool) false</code>' ); ?></dd>
147
 
148
+ <dt<?php if ( defined( 'HMBKP_DATABASE_ONLY' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DATABASE_ONLY</code></dt>
149
+ <dd><?php printf( __( 'Backup %s only, your %s will %s be backed up. Defaults to %s.', 'hmbkp' ), '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>', '<code>(bool) false</code>' ); ?></dd>
150
 
151
+ <dt<?php if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DAILY_SCHEDULE_TIME</code></dt>
152
+ <dd><?php printf( __( 'The time that the daily back up should run. Defaults to %s.', 'hmbkp' ), '<code>23:00</code>' ); ?></dd>
153
 
154
+ <dt<?php if ( defined( 'HMBKP_EMAIL' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_EMAIL</code></dt>
155
+ <dd><?php printf( __( 'Attempt to email a copy of your backups. Value should be email address to send backups to. Defaults to %s.', 'hmbkp' ), '<code>(bool) false</code>' ); ?></dd>
156
 
157
  </dl>
158
 
159
  </div>
160
 
161
+ <p class="howto"><?php printf( __( 'If you need help getting things working you are more than welcome to email us at %s and we\'ll do what we can to help.', 'hmbkp' ), '<a href="mailto:support@humanmade.co.uk">support@humanmade.co.uk</a>' ); ?></p>
162
 
163
  </div>
assets/hmbkp.css CHANGED
@@ -1,11 +1,16 @@
 
1
  .hmbkp_running .add-new-h2 img { margin: 0 3px -4px -9px; opacity: 0.3; }
2
  .button.disabled, .button[disabled], .button[disabled="disabled"] { cursor: default; }
3
  .button.disabled:active, .button[disabled]:active, .button[disabled="disabled"]:active { background: #F2F2F2 url(../../../../wp-admin/images/white-grad.png) repeat-x; }
4
  tfoot p { margin: 0; font-weight: normal; }
5
  #hmbkp_advanced-options { display: none; }
6
  #hmbkp_advanced-options dl { overflow: hidden; margin: 20px 0; }
7
- #hmbkp_advanced-options dt { float: left; width: 250px; clear: both; border-top: 1px solid #DFDFDF; padding: 7px 0; }
8
- #hmbkp_advanced-options dd { color: #666; margin-left: 250px; border-top: 1px solid #DFDFDF; padding: 7px 0; }
 
9
  .hmbkp_manage_backups_row .delete { color: #BC0B0B; }
10
  .hmbkp_manage_backups_row .delete:hover { color: red; }
11
- .completed th, .completed td { background-color: #FFFFE0; }
 
 
 
1
+ #icon-backupwordpress.icon32 { background: url(icon_backupwordpress_32x32.png); }
2
  .hmbkp_running .add-new-h2 img { margin: 0 3px -4px -9px; opacity: 0.3; }
3
  .button.disabled, .button[disabled], .button[disabled="disabled"] { cursor: default; }
4
  .button.disabled:active, .button[disabled]:active, .button[disabled="disabled"]:active { background: #F2F2F2 url(../../../../wp-admin/images/white-grad.png) repeat-x; }
5
  tfoot p { margin: 0; font-weight: normal; }
6
  #hmbkp_advanced-options { display: none; }
7
  #hmbkp_advanced-options dl { overflow: hidden; margin: 20px 0; }
8
+ #hmbkp_advanced-options dt { float: left; width: 250px; clear: both; padding: 6px 0; margin: 1px 0; }
9
+ #hmbkp_advanced-options dd { color: #666; padding: 7px 0 7px 250px; border-top: 1px solid #DFDFDF; margin: 0; }
10
+ #hmbkp_advanced-options dd:last-child { border-bottom: 1px solid #DFDFDF; }
11
  .hmbkp_manage_backups_row .delete { color: #BC0B0B; }
12
  .hmbkp_manage_backups_row .delete:hover { color: red; }
13
+ .completed th, .completed td { background-color: #FFFFE0; }
14
+ .hmbkp_active:before { content: "\00a0 \2713 "; font-size: 11px; }
15
+ .hmbkp_active, .hmbkp_active code, #hmbkp_advanced-options .hmbkp_active + dd { background: #E5F7E8; }
16
+ #hmbkp_advanced-options dt:not(.hmbkp_active) + dd { background: #F9F9F9; }
assets/hmbkp.js CHANGED
@@ -12,23 +12,40 @@ jQuery( document ).ready( function( $ ) {
12
  } ).fadeIn();
13
  }
14
  );
15
-
 
 
 
 
 
 
 
 
16
  $( '.hmbkp_advanced-options-toggle' ).click( function() {
17
-
18
  $( '#hmbkp_advanced-options' ).toggle();
19
-
20
  } );
21
 
22
  } );
23
 
24
  function hmbkpRedirectOnBackupComplete() {
25
 
 
 
26
  jQuery.get( ajaxurl, { 'action' : 'hmbkp_is_in_progress' },
 
27
  function( data ) {
28
- if ( data == 0 )
 
 
29
  location.reload( true );
30
- else
 
 
31
  setTimeout( 'hmbkpRedirectOnBackupComplete();', 5000 );
 
 
 
 
32
  }
33
  );
34
 
12
  } ).fadeIn();
13
  }
14
  );
15
+
16
+ $.get( ajaxurl, { 'action' : 'hmbkp_cron_test' },
17
+ function( data ) {
18
+ if ( data != 1 ) {
19
+ $( '.wrap > h2' ).after( data );
20
+ }
21
+ }
22
+ );
23
+
24
  $( '.hmbkp_advanced-options-toggle' ).click( function() {
 
25
  $( '#hmbkp_advanced-options' ).toggle();
 
26
  } );
27
 
28
  } );
29
 
30
  function hmbkpRedirectOnBackupComplete() {
31
 
32
+ img = jQuery( '<div>' ).append( jQuery( '.hmbkp_running a.button[disabled]:first img' ).clone() ).remove().html();
33
+
34
  jQuery.get( ajaxurl, { 'action' : 'hmbkp_is_in_progress' },
35
+
36
  function( data ) {
37
+
38
+ if ( data == 0 ) {
39
+
40
  location.reload( true );
41
+
42
+ } else {
43
+
44
  setTimeout( 'hmbkpRedirectOnBackupComplete();', 5000 );
45
+
46
+ jQuery( '.hmbkp_running a.button[disabled]:first' ).html( img + data );
47
+
48
+ }
49
  }
50
  );
51
 
assets/icon_backupwordpress_16x16.png ADDED
Binary file
assets/icon_backupwordpress_16x16_hover.png ADDED
Binary file
assets/icon_backupwordpress_32x32.png ADDED
Binary file
functions/backup.files.functions.php CHANGED
@@ -37,10 +37,14 @@ function hmbkp_backup_files( $backup_tmp_dir ) {
37
 
38
  // Copy the file
39
  copy( $f, $wordpress_files . hmbkp_conform_dir( $f, true ) );
 
 
 
40
 
41
  endif;
42
 
43
  $i++;
 
44
  endforeach;
45
 
46
  }
@@ -60,7 +64,8 @@ function hmbkp_archive_files( $backup_tmp_dir, $backup_filepath ) {
60
  // Do we have the path to the zip command
61
  if ( hmbkp_zip_path() )
62
  shell_exec( 'cd ' . escapeshellarg( $backup_tmp_dir ) . ' && zip -r ' . escapeshellarg( $backup_filepath ) . ' ./' );
63
-
 
64
  else
65
  hmbkp_archive_files_fallback( $backup_tmp_dir, $backup_filepath );
66
 
37
 
38
  // Copy the file
39
  copy( $f, $wordpress_files . hmbkp_conform_dir( $f, true ) );
40
+
41
+ // Attempt to chown the file so we can delete it
42
+ @chmod( $f, 0644 );
43
 
44
  endif;
45
 
46
  $i++;
47
+
48
  endforeach;
49
 
50
  }
64
  // Do we have the path to the zip command
65
  if ( hmbkp_zip_path() )
66
  shell_exec( 'cd ' . escapeshellarg( $backup_tmp_dir ) . ' && zip -r ' . escapeshellarg( $backup_filepath ) . ' ./' );
67
+
68
+ // If not use the fallback
69
  else
70
  hmbkp_archive_files_fallback( $backup_tmp_dir, $backup_filepath );
71
 
functions/backup.functions.php CHANGED
@@ -12,39 +12,60 @@
12
  */
13
  function hmbkp_do_backup() {
14
 
 
 
 
 
15
  $time_start = date( 'Y-m-d-H-i-s' );
16
 
17
  $filename = $time_start . '.zip';
18
  $filepath = trailingslashit( hmbkp_path() ) . $filename;
19
 
20
- update_option( 'hmbkp_running', $time_start );
 
21
 
22
  // Raise the memory limit
23
- ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
24
- set_time_limit( 300 );
 
 
25
 
26
  // Create a temporary directory for this backup
27
  $backup_tmp_dir = hmbkp_create_tmp_dir( $time_start );
28
 
 
 
29
  // Backup database
30
  if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) )
31
  hmbkp_backup_mysql( $backup_tmp_dir );
32
 
 
 
33
  // Backup files
34
  if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) )
35
  hmbkp_backup_files( $backup_tmp_dir );
36
-
 
 
37
  // Zip up the files
38
  hmbkp_archive_files( $backup_tmp_dir, $filepath );
39
-
 
 
40
  // Remove the temporary directory
41
  hmbkp_rmdirtree( $backup_tmp_dir );
42
-
 
 
 
 
 
43
  // Delete any old backup files
44
  hmbkp_delete_old_backups();
45
 
46
- delete_option( 'hmbkp_running' );
47
-
 
48
  update_option( 'hmbkp_complete', true );
49
 
50
  }
@@ -80,8 +101,8 @@ function hmbkp_get_backups() {
80
  if ( $handle = opendir( $hmbkp_path ) ) :
81
 
82
  while ( false !== ( $file = readdir( $handle ) ) )
83
- if ( ( substr( $file, 0, 1 ) != '.' ) && !is_dir( trailingslashit( $hmbkp_path ) . $file ) )
84
- $files[] = array( 'file' => trailingslashit( $hmbkp_path ) . $file, 'filename' => $file);
85
 
86
  closedir( $handle );
87
 
@@ -115,14 +136,14 @@ function hmbkp_delete_backup( $file ) {
115
 
116
  /**
117
  * Create and return the path to the tmp directory
118
- *
119
  * @param string $date
120
  * @return string
121
  */
122
  function hmbkp_create_tmp_dir( $date ) {
123
 
124
  $backup_tmp_dir = trailingslashit( hmbkp_path() ) . $date;
125
-
126
  if ( !is_dir( $backup_tmp_dir ) )
127
  mkdir( $backup_tmp_dir );
128
 
@@ -132,9 +153,54 @@ function hmbkp_create_tmp_dir( $date ) {
132
 
133
  /**
134
  * Check if a backup is running
135
- *
136
  * @return bool
137
  */
138
  function hmbkp_is_in_progress() {
139
- return (bool) get_option( 'hmbkp_running' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
12
  */
13
  function hmbkp_do_backup() {
14
 
15
+ // Make sure it's safe to do a backup
16
+ if ( !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || ini_get( 'safe_mode' ) )
17
+ return false;
18
+
19
  $time_start = date( 'Y-m-d-H-i-s' );
20
 
21
  $filename = $time_start . '.zip';
22
  $filepath = trailingslashit( hmbkp_path() ) . $filename;
23
 
24
+ // Set as running for a max of 2 hours
25
+ set_transient( 'hmbkp_running', $time_start, 7200 );
26
 
27
  // Raise the memory limit
28
+ ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
29
+ set_time_limit( 0 );
30
+
31
+ update_option( 'hmbkp_status', __( 'Creating tmp directory', 'hmbkp' ) );
32
 
33
  // Create a temporary directory for this backup
34
  $backup_tmp_dir = hmbkp_create_tmp_dir( $time_start );
35
 
36
+ update_option( 'hmbkp_status', __( 'Dumping database to tmp directory', 'hmbkp' ) );
37
+
38
  // Backup database
39
  if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) )
40
  hmbkp_backup_mysql( $backup_tmp_dir );
41
 
42
+ update_option( 'hmbkp_status', __( 'Copying files to tmp directory', 'hmbkp' ) );
43
+
44
  // Backup files
45
  if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) )
46
  hmbkp_backup_files( $backup_tmp_dir );
47
+
48
+ update_option( 'hmbkp_status', __( 'Zipping up tmp directory', 'hmbkp' ) );
49
+
50
  // Zip up the files
51
  hmbkp_archive_files( $backup_tmp_dir, $filepath );
52
+
53
+ update_option( 'hmbkp_status', __( 'Removing tmp directory', 'hmbkp' ) );
54
+
55
  // Remove the temporary directory
56
  hmbkp_rmdirtree( $backup_tmp_dir );
57
+
58
+ // Email Backup
59
+ hmbkp_email_backup( $filepath );
60
+
61
+ update_option( 'hmbkp_status', __( 'Removing old backups', 'hmbkp' ) );
62
+
63
  // Delete any old backup files
64
  hmbkp_delete_old_backups();
65
 
66
+ delete_transient( 'hmbkp_running' );
67
+ delete_option( 'hmbkp_status' );
68
+
69
  update_option( 'hmbkp_complete', true );
70
 
71
  }
101
  if ( $handle = opendir( $hmbkp_path ) ) :
102
 
103
  while ( false !== ( $file = readdir( $handle ) ) )
104
+ if ( ( substr( $file, 0, 1 ) != '.' ) && !is_dir( trailingslashit( $hmbkp_path ) . $file ) && strpos( $file, '.zip' ) !== false )
105
+ $files[] = array( 'file' => trailingslashit( $hmbkp_path ) . $file, 'filename' => $file );
106
 
107
  closedir( $handle );
108
 
136
 
137
  /**
138
  * Create and return the path to the tmp directory
139
+ *
140
  * @param string $date
141
  * @return string
142
  */
143
  function hmbkp_create_tmp_dir( $date ) {
144
 
145
  $backup_tmp_dir = trailingslashit( hmbkp_path() ) . $date;
146
+
147
  if ( !is_dir( $backup_tmp_dir ) )
148
  mkdir( $backup_tmp_dir );
149
 
153
 
154
  /**
155
  * Check if a backup is running
156
+ *
157
  * @return bool
158
  */
159
  function hmbkp_is_in_progress() {
160
+ return (bool) get_transient( 'hmbkp_running' );
161
+ }
162
+
163
+ /**
164
+ * Email backup.
165
+ *
166
+ * @param $file
167
+ * @return bool
168
+ */
169
+ function hmbkp_email_backup( $file ) {
170
+
171
+ if ( !defined('HMBKP_EMAIL' ) || !HMBKP_EMAIL || !is_email( HMBKP_EMAIL ) )
172
+ return;
173
+
174
+ // Raise the memory and time limit
175
+ ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
176
+ set_time_limit( 0 );
177
+
178
+ $download = get_bloginfo( 'wpurl' ) . '/wp-admin/tools.php?page=' . HMBKP_PLUGIN_SLUG . '&hmbkp_download=' . base64_encode( $file );
179
+ $domain = parse_url( get_bloginfo( 'url' ), PHP_URL_HOST ) . parse_url( get_bloginfo( 'url' ), PHP_URL_PATH );
180
+
181
+ $subject = sprintf( __( 'Backup of %s', 'hmbkp' ), $domain );
182
+ $message = sprintf( __( "BackUpWordPress has completed a backup of your site %s.\n\nThe backup file should be attached to this email.\n\nYou can also download the backup file by clicking the link below:\n\n%s\n\nKind Regards\n\n The Happy BackUpWordPress Backup Emailing Robot", 'hmbkp' ), get_bloginfo( 'url' ), $download );
183
+ $headers = 'From: BackUpWordPress <' . get_bloginfo( 'admin_email' ) . '>' . "\r\n";
184
+
185
+ // Try to send the email
186
+ $sent = wp_mail( HMBKP_EMAIL, $subject, $message, $headers, $file );
187
+
188
+ // If it failed- Try to send a download link - The file was probably too large.
189
+ if ( !$sent ) :
190
+
191
+ $subject = sprintf( __( 'Backup of %s', 'hmbkp' ), $domain );
192
+ $message = sprintf( __( "BackUpWordPress has completed a backup of your site %s.\n\nUnfortunately the backup file was too large to attach to this email.\n\nYou can download the backup file by clicking the link below:\n\n%s\n\nKind Regards\n\n The Happy BackUpWordPress Backup Emailing Robot", 'hmbkp' ), get_bloginfo( 'url' ), $download );
193
+
194
+ $sent = wp_mail( HMBKP_EMAIL, $subject, $message, $headers );
195
+
196
+ endif;
197
+
198
+ // Set option for email not sent error
199
+ if ( !$sent )
200
+ update_option( 'hmbkp_email_error', 'hmbkp_email_failed' );
201
+ else
202
+ delete_option( 'hmbkp_email_error' );
203
+
204
+ return true;
205
+
206
  }
functions/backup.mysql.fallback.functions.php CHANGED
@@ -225,8 +225,7 @@ function hmbkp_backup_mysql_fallback( $path ) {
225
  $curr_table = mysql_tablename( $tables, $i );
226
 
227
  // Increase script execution time-limit to 15 min for every table.
228
- if ( !ini_get( 'safe_mode' ) )
229
- @set_time_limit( 15 * 60 );
230
 
231
  // Create the SQL statements
232
  $sql_file .= "# --------------------------------------------------------\n";
225
  $curr_table = mysql_tablename( $tables, $i );
226
 
227
  // Increase script execution time-limit to 15 min for every table.
228
+ set_time_limit( 0 );
 
229
 
230
  // Create the SQL statements
231
  $sql_file .= "# --------------------------------------------------------\n";
functions/backup.mysql.functions.php CHANGED
@@ -51,9 +51,17 @@ function hmbkp_mysqldump_path() {
51
  '/usr/bin/mysqldump',
52
  '/opt/local/lib/mysql6/bin/mysqldump',
53
  '/opt/local/lib/mysql5/bin/mysqldump',
54
- '/opt/local/lib/mysql4/bin/mysqldump'
 
 
 
 
 
 
 
 
55
  );
56
-
57
  // Allow the path to be overridden
58
  if ( defined( 'HMBKP_MYSQLDUMP_PATH' ) && HMBKP_MYSQLDUMP_PATH )
59
  array_unshift( $mysqldump_locations, HMBKP_MYSQLDUMP_PATH );
@@ -63,7 +71,7 @@ function hmbkp_mysqldump_path() {
63
 
64
  // Try to find out where mysqldump is
65
  foreach ( $mysqldump_locations as $location )
66
- if ( shell_exec( 'which ' . $location ) )
67
  $path = $location;
68
 
69
  // Save it for later
@@ -73,7 +81,7 @@ function hmbkp_mysqldump_path() {
73
  endif;
74
 
75
  // Check again in-case the saved path has stopped working for some reason
76
- if ( $path && !shell_exec( 'which ' . $path ) ) :
77
  delete_option( 'hmbkp_mysqldump_path' );
78
  return hmbkp_mysqldump_path();
79
 
51
  '/usr/bin/mysqldump',
52
  '/opt/local/lib/mysql6/bin/mysqldump',
53
  '/opt/local/lib/mysql5/bin/mysqldump',
54
+ '/opt/local/lib/mysql4/bin/mysqldump',
55
+ '\xampp\mysql\bin\mysqldump',
56
+ '\Program Files\xampp\mysql\bin\mysqldump',
57
+ '\Program Files\MySQL\MySQL Server 6.0\bin\mysqldump',
58
+ '\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump',
59
+ '\Program Files\MySQL\MySQL Server 5.4\bin\mysqldump',
60
+ '\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump',
61
+ '\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump',
62
+ '\Program Files\MySQL\MySQL Server 4.1\bin\mysqldump'
63
  );
64
+
65
  // Allow the path to be overridden
66
  if ( defined( 'HMBKP_MYSQLDUMP_PATH' ) && HMBKP_MYSQLDUMP_PATH )
67
  array_unshift( $mysqldump_locations, HMBKP_MYSQLDUMP_PATH );
71
 
72
  // Try to find out where mysqldump is
73
  foreach ( $mysqldump_locations as $location )
74
+ if ( shell_exec( $location ) )
75
  $path = $location;
76
 
77
  // Save it for later
81
  endif;
82
 
83
  // Check again in-case the saved path has stopped working for some reason
84
+ if ( $path && !shell_exec( $path ) ) :
85
  delete_option( 'hmbkp_mysqldump_path' );
86
  return hmbkp_mysqldump_path();
87
 
functions/core.functions.php CHANGED
@@ -4,9 +4,7 @@
4
  * Setup the default options on plugin activation
5
  */
6
  function hmbkp_activate() {
7
-
8
  hmbkp_setup_daily_schedule();
9
-
10
  }
11
 
12
  /**
@@ -23,13 +21,17 @@ function hmbkp_deactivate() {
23
  'hmbkp_path',
24
  'hmbkp_max_backups',
25
  'hmbkp_running',
26
- '_transient_hmbkp_estimated_filesize',
27
- '_transient_timeout_hmbkp_estimated_filesize'
 
28
  );
29
 
30
  foreach ( $options as $option )
31
  delete_option( $option );
32
 
 
 
 
33
  // Clear cron
34
  wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
35
  wp_clear_scheduled_hook( 'hmbkp_schedule_single_backup_hook' );
@@ -44,18 +46,24 @@ function hmbkp_update() {
44
 
45
  // Every update
46
  if ( version_compare( HMBKP_VERSION, get_option( 'hmbkp_plugin_version' ), '>' ) ) :
 
47
  delete_transient( 'hmbkp_estimated_filesize' );
48
  delete_option( 'hmbkp_running' );
 
 
 
 
 
 
 
 
49
  endif;
50
 
51
- // 1.0.x to 1.1
52
  if ( !get_option( 'hmbkp_plugin_version' ) ) :
53
- delete_transient( 'hmbkp_estimated_filesize' );
 
54
  delete_option( 'hmbkp_max_backups' );
55
- delete_option( 'hmbkp_running' );
56
-
57
- // Delete the logs directory
58
- hmbkp_rmdirtree( hmbkp_path() . '/logs' );
59
 
60
  endif;
61
 
@@ -121,17 +129,22 @@ function hmbkp_timestamp() {
121
  */
122
  function hmbkp_conform_dir( $dir, $rel = false ) {
123
 
 
124
  $dir = str_replace( '\\', '/', $dir );
125
  $dir = str_replace( '//', '/', $dir );
126
 
 
127
  $dir = untrailingslashit( $dir );
128
 
 
 
 
 
129
  if ( $rel == true )
130
  $dir = str_replace( hmbkp_conform_dir( ABSPATH ), '', $dir );
131
 
132
  return $dir;
133
  }
134
-
135
  /**
136
  * Take a file size and return a human readable
137
  * version
@@ -248,19 +261,21 @@ function hmbkp_ls( $dir, $files = array() ) {
248
 
249
  $d = opendir( $dir );
250
 
251
- if ( strpos( $dir, hmbkp_path() ) !== false )
252
- return $files;
253
-
254
  while ( $file = readdir( $d ) ) :
255
 
256
- // Ignore current dir and containing dir as well as files in the backups dir
257
- if ( $file == '.' || $file == '..' || strpos( trailingslashit( $dir ) . $file, hmbkp_path() ) !== false || strpos( trailingslashit( $dir ) . $file, WP_CONTENT_DIR . '/backups' ) !== false )
 
 
 
 
 
258
  continue;
259
 
260
- $files[] = trailingslashit( $dir ) . $file;
261
 
262
- if ( is_dir( trailingslashit( $dir ) . $file ) )
263
- $files = hmbkp_ls( trailingslashit( $dir ) . $file, $files );
264
 
265
  endwhile;
266
 
@@ -328,8 +343,8 @@ function hmbkp_calculate() {
328
  ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
329
 
330
  // Check cache
331
- if ( $filesize = get_transient( 'hmbkp_estimated_filesize' ) )
332
- return hmbkp_size_readable( $filesize, null, '%01u %s' );
333
 
334
  $filesize = 0;
335
 
@@ -338,13 +353,10 @@ function hmbkp_calculate() {
338
 
339
  global $wpdb;
340
 
341
- $sql = 'SHOW TABLE STATUS FROM ' . DB_NAME;
342
- $res = $wpdb->get_results( $sql, ARRAY_A );
343
 
344
- foreach ( $res as $r ) :
345
- $filesize += $r['Data_free'];
346
- $filesize += $r['Data_length'];
347
- endforeach;
348
 
349
  endif;
350
 
@@ -353,17 +365,16 @@ function hmbkp_calculate() {
353
  // Get rid of any cached filesizes
354
  clearstatcache();
355
 
356
- $files = hmbkp_ls( hmbkp_conform_dir( ABSPATH ) );
357
-
358
- foreach ( $files as $f ) :
359
- $str = hmbkp_conform_dir( $f, true );
360
- $filesize += @filesize( $f );
361
- endforeach;
362
 
363
  endif;
364
 
365
- // Cache in a transient for a day
366
- set_transient( 'hmbkp_estimated_filesize', $filesize, 86400 );
 
 
 
367
 
368
  return hmbkp_size_readable( $filesize, null, '%01u %s' );
369
 
@@ -378,9 +389,14 @@ function hmbkp_shell_exec_available() {
378
 
379
  $disable_functions = ini_get( 'disable_functions' );
380
 
 
381
  if ( strpos( $disable_functions, 'shell_exec' ) !== false )
382
  return false;
383
 
 
 
 
 
384
  return true;
385
 
386
  }
@@ -402,4 +418,77 @@ function hmbkp_total_filesize() {
402
 
403
  return hmbkp_size_readable( $filesize );
404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
405
  }
4
  * Setup the default options on plugin activation
5
  */
6
  function hmbkp_activate() {
 
7
  hmbkp_setup_daily_schedule();
 
8
  }
9
 
10
  /**
21
  'hmbkp_path',
22
  'hmbkp_max_backups',
23
  'hmbkp_running',
24
+ 'hmbkp_status',
25
+ 'hmbkp_complete',
26
+ 'hmbkp_email_error'
27
  );
28
 
29
  foreach ( $options as $option )
30
  delete_option( $option );
31
 
32
+ delete_transient( 'hmbkp_running' );
33
+ delete_transient( 'hmbkp_estimated_filesize' );
34
+
35
  // Clear cron
36
  wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
37
  wp_clear_scheduled_hook( 'hmbkp_schedule_single_backup_hook' );
46
 
47
  // Every update
48
  if ( version_compare( HMBKP_VERSION, get_option( 'hmbkp_plugin_version' ), '>' ) ) :
49
+
50
  delete_transient( 'hmbkp_estimated_filesize' );
51
  delete_option( 'hmbkp_running' );
52
+ delete_option( 'hmbkp_complete' );
53
+ delete_option( 'hmbkp_status' );
54
+ delete_transient( 'hmbkp_running' );
55
+
56
+ // Check whether we have a logs directory to delete
57
+ if ( is_dir( hmbkp_path() . '/logs' ) )
58
+ hmbkp_rmdirtree( hmbkp_path() . '/logs' );
59
+
60
  endif;
61
 
62
+ // Pre 1.1
63
  if ( !get_option( 'hmbkp_plugin_version' ) ) :
64
+
65
+ // Delete the obsolete max backups option
66
  delete_option( 'hmbkp_max_backups' );
 
 
 
 
67
 
68
  endif;
69
 
129
  */
130
  function hmbkp_conform_dir( $dir, $rel = false ) {
131
 
132
+ // Normalise slashes
133
  $dir = str_replace( '\\', '/', $dir );
134
  $dir = str_replace( '//', '/', $dir );
135
 
136
+ // Remove the trailingslash
137
  $dir = untrailingslashit( $dir );
138
 
139
+ // If we're on Windows
140
+ if ( strpos( ABSPATH, '\\' ) !== false )
141
+ $dir = str_replace( '/', '\\', $dir );
142
+
143
  if ( $rel == true )
144
  $dir = str_replace( hmbkp_conform_dir( ABSPATH ), '', $dir );
145
 
146
  return $dir;
147
  }
 
148
  /**
149
  * Take a file size and return a human readable
150
  * version
261
 
262
  $d = opendir( $dir );
263
 
 
 
 
264
  while ( $file = readdir( $d ) ) :
265
 
266
+ // Ignore current dir and containing dir as well the backups dir
267
+ if ( $file == '.' || $file == '..' )
268
+ continue;
269
+
270
+ $file = hmbkp_conform_dir( trailingslashit( $dir ) . $file );
271
+
272
+ if ( $file == hmbkp_path() )
273
  continue;
274
 
275
+ $files[] = $file;
276
 
277
+ if ( is_dir( $file ) )
278
+ $files = hmbkp_ls( $file, $files );
279
 
280
  endwhile;
281
 
343
  ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
344
 
345
  // Check cache
346
+ if ( $filesize = get_transient( 'hmbkp_estimated_filesize' ) )
347
+ return hmbkp_size_readable( $filesize, null, '%01u %s' );
348
 
349
  $filesize = 0;
350
 
353
 
354
  global $wpdb;
355
 
356
+ $res = $wpdb->get_results( 'SHOW TABLE STATUS FROM ' . DB_NAME, ARRAY_A );
 
357
 
358
+ foreach ( $res as $r )
359
+ $filesize += (float) $r['Data_length'];
 
 
360
 
361
  endif;
362
 
365
  // Get rid of any cached filesizes
366
  clearstatcache();
367
 
368
+ foreach ( hmbkp_ls( ABSPATH ) as $f )
369
+ $filesize += (float) @filesize( $f );
 
 
 
 
370
 
371
  endif;
372
 
373
+ // Account for compression
374
+ $filesize /= 1.9;
375
+
376
+ // Cache in a transient for a week
377
+ set_transient( 'hmbkp_estimated_filesize', $filesize, 604800 );
378
 
379
  return hmbkp_size_readable( $filesize, null, '%01u %s' );
380
 
389
 
390
  $disable_functions = ini_get( 'disable_functions' );
391
 
392
+ // Is shell_exec disabled?
393
  if ( strpos( $disable_functions, 'shell_exec' ) !== false )
394
  return false;
395
 
396
+ // Are we in Safe Mode
397
+ if ( ini_get( 'safe_mode' ) )
398
+ return false;
399
+
400
  return true;
401
 
402
  }
418
 
419
  return hmbkp_size_readable( $filesize );
420
 
421
+ }
422
+
423
+ /**
424
+ * Setup the daily backup schedule
425
+ */
426
+ function hmbkp_setup_daily_schedule() {
427
+
428
+ // Clear any old schedules
429
+ wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
430
+
431
+ // Default to 11 in the evening
432
+ $time = '23:00';
433
+
434
+ // Allow it to be overridden
435
+ if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) && HMBKP_DAILY_SCHEDULE_TIME )
436
+ $time = HMBKP_DAILY_SCHEDULE_TIME;
437
+
438
+ if ( time() > strtotime( $time ) )
439
+ $time = 'tomorrow ' . $time;
440
+
441
+ wp_schedule_event( strtotime( $time ), 'hmbkp_daily', 'hmbkp_schedule_backup_hook' );
442
+ }
443
+
444
+
445
+ /**
446
+ * Get the path to the backups directory
447
+ *
448
+ * Will try to create it if it doesn't exist
449
+ * and will fallback to default if a custom dir
450
+ * isn't writable.
451
+ */
452
+ function hmbkp_path() {
453
+
454
+ $path = get_option( 'hmbkp_path' );
455
+
456
+ // Allow the backups path to be defined
457
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH )
458
+ $path = HMBKP_PATH;
459
+
460
+ // If the dir doesn't exist or isn't writable then use wp-content/backups instead
461
+ if ( ( !$path || !is_writable( $path ) ) && $path != WP_CONTENT_DIR . '/backups' ) :
462
+ $path = WP_CONTENT_DIR . '/backups';
463
+ update_option( 'hmbkp_path', $path );
464
+ endif;
465
+
466
+ // Create the backups directory if it doesn't exist
467
+ if ( is_writable( WP_CONTENT_DIR ) && !is_dir( $path ) )
468
+ mkdir( $path, 0755 );
469
+
470
+ // Secure the directory with a .htaccess file
471
+ $htaccess = $path . '/.htaccess';
472
+
473
+ if ( !file_exists( $htaccess ) && is_writable( $path ) ) :
474
+ require_once( ABSPATH . '/wp-admin/includes/misc.php' );
475
+ insert_with_markers( $htaccess, 'BackUpWordPress', array( 'deny from all' ) );
476
+ endif;
477
+
478
+ return hmbkp_conform_dir( $path );
479
+ }
480
+
481
+ /**
482
+ * The maximum number of backups to keep
483
+ * defaults to 10
484
+ *
485
+ * @return int
486
+ */
487
+ function hmbkp_max_backups() {
488
+
489
+ if ( defined( 'HMBKP_MAX_BACKUPS' ) && is_numeric( HMBKP_MAX_BACKUPS ) )
490
+ return (int) HMBKP_MAX_BACKUPS;
491
+
492
+ return 10;
493
+
494
  }
functions/settings.functions.php DELETED
@@ -1,73 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Setup the daily backup schedule
5
- */
6
- function hmbkp_setup_daily_schedule() {
7
-
8
- // Clear any old schedules
9
- wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
10
-
11
- // Default to 11 in the evening
12
- $time = '23:00';
13
-
14
- // Allow it to be overridden
15
- if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) && HMBKP_DAILY_SCHEDULE_TIME )
16
- $time = HMBKP_DAILY_SCHEDULE_TIME;
17
-
18
- if ( time() > strtotime( $time ) )
19
- $time = 'tomorrow ' . $time;
20
-
21
- wp_schedule_event( strtotime( $time ), 'hmbkp_daily', 'hmbkp_schedule_backup_hook' );
22
- }
23
-
24
-
25
- /**
26
- * Get the path to the backups directory
27
- *
28
- * Will try to create it if it doesn't exist
29
- * and will fallback to default if a custom dir
30
- * isn't writable.
31
- */
32
- function hmbkp_path() {
33
-
34
- $path = get_option( 'hmbkp_path' );
35
-
36
- // Allow the backups path to be defined
37
- if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH )
38
- $path = HMBKP_PATH;
39
-
40
- // If the dir doesn't exist or isn't writable then use wp-content/backups instead
41
- if ( ( !$path || !is_writable( $path ) ) && $path != WP_CONTENT_DIR . '/backups' ) :
42
- $path = WP_CONTENT_DIR . '/backups';
43
- update_option( 'hmbkp_path', $path );
44
- endif;
45
-
46
- // Create the backups directory if it doesn't exist
47
- if ( is_writable( WP_CONTENT_DIR ) && !is_dir( $path ) )
48
- mkdir( $path, 0755 );
49
-
50
- // Secure the directory with a .htaccess file
51
- $htaccess = $path . '/.htaccess';
52
-
53
- if ( !file_exists( $htaccess ) && is_writable( $path ) ) :
54
- require_once( ABSPATH . '/wp-admin/includes/misc.php' );
55
- insert_with_markers( $htaccess, 'BackUpWordPress', array( 'deny from all' ) );
56
- endif;
57
-
58
- return $path;
59
- }
60
-
61
- /**
62
- * The maximum number of backups to keep
63
- *
64
- * @return int
65
- */
66
- function hmbkp_max_backups() {
67
-
68
- if ( defined( 'HMBKP_MAX_BACKUPS' ) && is_numeric( HMBKP_MAX_BACKUPS ) )
69
- return (int) HMBKP_MAX_BACKUPS;
70
-
71
- return 10;
72
-
73
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
icon.png ADDED
Binary file
plugin.php CHANGED
@@ -5,7 +5,7 @@ Plugin Name: BackUpWordPress
5
  Plugin URI: http://humanmade.co.uk/
6
  Description: Simple automated backups of your WordPress powered website. Once activated you'll find me under <strong>Tools &rarr; Backups</strong>.
7
  Author: Human Made Limited
8
- Version: 1.1.4
9
  Author URI: http://humanmade.co.uk/
10
  */
11
 
@@ -70,7 +70,7 @@ add_action( 'admin_init', 'hmbkp_actions' );
70
 
71
  /**
72
  * Hook in an change the plugin description when BackUpWordPress is activated
73
- *
74
  * @param array $plugins
75
  * @return $plugins
76
  */
@@ -90,7 +90,6 @@ require_once( HMBKP_PLUGIN_PATH . '/admin.menus.php' );
90
  // Load the core functions
91
  require_once( HMBKP_PLUGIN_PATH . '/functions/core.functions.php' );
92
  require_once( HMBKP_PLUGIN_PATH . '/functions/interface.functions.php' );
93
- require_once( HMBKP_PLUGIN_PATH . '/functions/settings.functions.php' );
94
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.functions.php' );
95
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.mysql.functions.php' );
96
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.files.functions.php' );
@@ -132,8 +131,44 @@ if ( is_dir( hmbkp_path() ) && !is_writable( hmbkp_path() ) ) :
132
 
133
  endif;
134
 
135
- // Hook in on update core and do a backup
136
- function hmbkp_backup_on_upgrade() {
137
 
138
- }
139
- add_filter( 'update_feedback', 'hmbkp_backup_on_upgrade' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  Plugin URI: http://humanmade.co.uk/
6
  Description: Simple automated backups of your WordPress powered website. Once activated you'll find me under <strong>Tools &rarr; Backups</strong>.
7
  Author: Human Made Limited
8
+ Version: 1.2
9
  Author URI: http://humanmade.co.uk/
10
  */
11
 
70
 
71
  /**
72
  * Hook in an change the plugin description when BackUpWordPress is activated
73
+ *
74
  * @param array $plugins
75
  * @return $plugins
76
  */
90
  // Load the core functions
91
  require_once( HMBKP_PLUGIN_PATH . '/functions/core.functions.php' );
92
  require_once( HMBKP_PLUGIN_PATH . '/functions/interface.functions.php' );
 
93
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.functions.php' );
94
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.mysql.functions.php' );
95
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.files.functions.php' );
131
 
132
  endif;
133
 
134
+ if ( ini_get( 'safe_mode' ) ) :
 
135
 
136
+ function hmbkp_safe_mode_warning() {
137
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( ' %s is running in %s. Please contact your host and ask them to disable %s.', 'hmbkp' ), '<code>PHP</code>', '<a href="http://php.net/manual/en/features.safe-mode.php"><code>Safe Mode</code></a>', '<code>Safe Mode</code>' ) . '</p></div>';
138
+ }
139
+ add_action( 'admin_notices', 'hmbkp_safe_mode_warning' );
140
+
141
+ endif;
142
+
143
+ if ( defined( 'HMBKP_FILES_ONLY' ) && HMBKP_FILES_ONLY && defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY ) :
144
+
145
+ function hmbkp_nothing_to_backup_warning() {
146
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You have both %s and %s defined so there isn\'t anything to back up.', 'hmbkp' ), '<code>HMBKP_DATABASE_ONLY</code>', '<code>HMBKP_FILES_ONLY</code>' ) . '</p></div>';
147
+ }
148
+ add_action( 'admin_notices', 'hmbkp_nothing_to_backup_warning' );
149
+
150
+ endif;
151
+
152
+ if ( get_transient( 'hmbkp_estimated_filesize' ) && disk_free_space( ABSPATH ) <= ( 2 * get_transient( 'hmbkp_estimated_filesize' ) ) ) :
153
+
154
+ function hmbkp_low_space_warning() {
155
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You only have %s of free space left on your server.', 'hmbkp' ), '<code>' . hmbkp_size_readable( disk_free_space( ABSPATH ), null, '%01u %s' ) . '</code>' ) . '</p></div>';
156
+ }
157
+ add_action( 'admin_notices', 'hmbkp_low_space_warning' );
158
+
159
+ endif;
160
+
161
+ if( defined( 'HMBKP_EMAIL' ) && !is_email( HMBKP_EMAIL ) ) :
162
+ function hmbkp_email_invalid(){
163
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( '%s is not a valid email address.', 'hmbkp' ), '<code>' . HMBKP_EMAIL . '</code>' ) . '</p></div>';
164
+ }
165
+ add_action( 'admin_notices', 'hmbkp_email_invalid' );
166
+ endif;
167
+
168
+
169
+ if ( defined( 'HMBKP_EMAIL' ) && get_option( 'hmbkp_email_error' ) ) :
170
+ function hmbkp_email_error(){
171
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . __( 'The last backup email failed to send.', 'hmbkp' ) . '</p></div>';
172
+ }
173
+ add_action( 'admin_notices', 'hmbkp_email_error' );
174
+ endif;
readme.txt CHANGED
@@ -1,21 +1,33 @@
1
  === BackUpWordPress ===
2
- Contributors: willmot, humanmade
3
- Tags: back up, backup, backups
4
  Requires at least: 3.0
5
- Tested up to: 3.1
6
- Stable tag: 1.1.4
7
 
8
  Simple automated backups of your WordPress powered website.
9
 
10
- BackUpWordPress will back up your entire site including your database and all your files once every day.
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  == Installation ==
13
 
14
- 1. Install BackUpWordPress either via the WordPress.org plugin directory, or by uploading the files to your server
15
- 2. Activate the plugin
16
- 3. Sit back and relax safe in the knowledge that your complete site will be backed up every day at 11:00
17
 
18
- The plugin will try to use the `mysqldump` and `zip` commands via shell if they are available, using these will greatly improve the time it takes to back up your site. You can point the plugin in the right direction by defining `HMBKP_ZIP_PATH` and `HMBKP_MYSQLDUMP_PATH` in your `wp-config.php`.
19
 
20
  == Frequently Asked Questions ==
21
 
@@ -27,6 +39,22 @@ Contact support@humanmade.co.uk for help/support.
27
 
28
  == Changelog ==
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  #### 1.1.4
31
 
32
  * Fix a rare issue where database backups could fail when using the mysqldump PHP fallback if `mysql.max_links` is set to 2 or less.
1
  === BackUpWordPress ===
2
+ Contributors: willmot, matheu, joehoyle, humanmade
3
+ Tags: back up, back up, backup, backups, database, zip, db, files, archive
4
  Requires at least: 3.0
5
+ Tested up to: 3.1.2
6
+ Stable tag: 1.2
7
 
8
  Simple automated backups of your WordPress powered website.
9
 
10
+ == Description ==
11
+
12
+ BackUpWordPress will back up your entire site including your database and all your files once every day. It has several advanced options for power users.
13
+
14
+ Features include:
15
+
16
+ * Super simple to use, no setup required.
17
+ * Uses `zip` and `mysqldump` for faster backups if they are available.
18
+ * Option to have each backup file emailed to you.
19
+ * Works on Linux & Windows Server.
20
+ * Control advanced options by defining any of the optional `Constants`.
21
+ * Good support should you need help.
22
+
23
 
24
  == Installation ==
25
 
26
+ 1. Install BackUpWordPress either via the WordPress.org plugin directory, or by uploading the files to your server.
27
+ 2. Activate the plugin.
28
+ 3. Sit back and relax safe in the knowledge that your whole site will be backed up every day.
29
 
30
+ The plugin will try to use the `mysqldump` and `zip` commands via shell if they are available, using these will greatly improve the time it takes to back up your site. If you know about such things then you can point the plugin in the right direction by defining `HMBKP_ZIP_PATH` and `HMBKP_MYSQLDUMP_PATH` in your `wp-config.php`.
31
 
32
  == Frequently Asked Questions ==
33
 
39
 
40
  == Changelog ==
41
 
42
+ #### 1.2
43
+
44
+ * Show live backup status in the back up now button when a back up is running.
45
+ * Show free disk space after total used by backups.
46
+ * Several langauge changes.
47
+ * Work around the 1 cron every 60 seconds limit.
48
+ * Store backup status in a 2 hour transient as a last ditch attempt to work around the "stuck on backup running" issue.
49
+ * Show a warning and disable backups when PHP is in Safe Mode, may try to work round issues and re-enable in the future.
50
+ * Highlight defined `Constants`.
51
+ * Show defaults for all `Constants`.
52
+ * Show a warning if both `HMBKP_FILES_ONLY` and `HMBKP_DATABASE_ONLY` are defined at the same time.
53
+ * Make sure options added in 1.1.4 are cleared on de-activate.
54
+ * Support `mysqldump on` Windows if it's available.
55
+ * New option to have each backup emailed to you on completion. Props @matheu for the contribution.
56
+ * Improved windows server support.
57
+
58
  #### 1.1.4
59
 
60
  * Fix a rare issue where database backups could fail when using the mysqldump PHP fallback if `mysql.max_links` is set to 2 or less.
screenshot-1.png CHANGED
Binary file