1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
<?php pb_backupbuddy::status( 'details', 'Started backup_integrity_check() function.' ); $serial = self::get_serial_from_file( $file );
// User selected to rescan a file. if ( pb_backupbuddy::_GET( 'reset_integrity' ) == $serial ) { pb_backupbuddy::alert( 'Rescanning backup integrity for backup file `' . basename( $file ) . '`' ); pb_backupbuddy::flush(); }
$createdFileOptions = false; if ( ! file_exists( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ) ) { // No fileoptions so get some minimal information from DAT file within zip. require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' ); $zipbuddy = new pluginbuddy_zipbuddy( backupbuddy_core::getLogDirectory() . 'fileoptions/' ); if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/backupbuddy_dat.php' ) === true ) { // Post 2.0 full backup $backup_type = 'full'; $pass = true; } if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php' ) === true ) { // Pre 2.0 full backup $backup_type = 'full'; $pass = true; } if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'backupbuddy_dat.php' ) === true ) { // DB backup $backup_type = 'db'; $pass = true; } $backup_dat = self::getDatArrayFromZip( $file ); /* echo 'DAT:<pre>'; print_r( $backup_dat ); echo '</pre>'; */ $options = $backup_dat; //['profile']; $createdFileOptions = true; }
$options = array_merge( array( 'skip_database_dump' => '0', ), $options );
$scan_notes = array();
// Get backup fileoptions. if ( $fileoptions != '' ) { $backup_options = &$fileoptions; $backup_options_options = &$backup_options->options; } else { //if ( file_exists( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ) ) { require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); pb_backupbuddy::status( 'details', 'Fileoptions instance #44.' ); $backup_options = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = false, $ignore_lock = false, $create_file = true ); // Will create file to hold integrity data if nothing exists. if ( true !== ( $result = $backup_options->is_ok() ) ) { pb_backupbuddy::status( 'error', __('Fatal Error #9034 C. Unable to access fileoptions data.', 'it-l10n-backupbuddy' ) . ' Error on file `' . backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' . '`: ' . $result ); pb_backupbuddy::status( 'haltScript', '' ); // Halt JS on page. return false; } if ( ! is_array( $backup_options->options ) ) { $backup_options->options = array(); } $backup_options_options = &$backup_options->options; }
// We did not have a fileoptions file so we are rebuilding portions of it using information found in the DAT file. if ( true === $createdFileOptions ) { $backup_options_options['breakout_tables'] = $options['breakout_tables']; $backup_options_options['table_sizes'] = $options['tables_sizes']; $backup_options_options['type'] = $options['backup_type']; $options = $options['profile']; }
if ( isset( $backup_options_options['profile'] ) ) { $options = $backup_options_options['profile']; $options = array_merge( pb_backupbuddy::settings( 'profile_defaults' ), $options ); }
// If breakout tables set in options but not fileoptions then copy over. eg from DAT file. /* if ( ! isset( $backup_options_options['breakout_tables'] ) && isset( $options['breakout_tables'] ) ) { $backup_options_options['breakout_tables'] = $options['breakout_tables']; } */
// Return if cached. if ( isset( $backup_options_options['integrity'] ) && ( count( $backup_options_options['integrity'] ) > 0 ) && ( pb_backupbuddy::_GET( 'reset_integrity' ) != $serial ) ) { // Already have integrity data and NOT resetting this one. pb_backupbuddy::status( 'details', 'Integrity data for backup `' . $serial . '` is cached; not scanning again.' ); return $backup_options_options['integrity']; } elseif ( pb_backupbuddy::_GET( 'reset_integrity' ) == $serial ) { // Resetting this one. pb_backupbuddy::status( 'details', 'Resetting backup integrity stats for backup with serial `' . $serial . '`.' ); } else { // No integrity data; not resetting. Just keep going... }
// Integrity check disabled. Skip. if ( ( ( pb_backupbuddy::$options['profiles'][0]['integrity_check'] == '0' ) ) && ( pb_backupbuddy::_GET( 'reset_integrity' ) == '' ) && ( isset( $options['integrity_check'] ) ) && ( $options['integrity_check'] == '0' ) ) { // Integrity checking disabled. Allows run if manually rescanning on backups page. pb_backupbuddy::status( 'details', 'Integrity check disabled. Skipping scan.' ); $file_stats = @stat( $file ); if ( $file_stats === false ) { // stat failure. pb_backupbuddy::status( 'error', 'Error #4539774. Unable to get file details ( via stat() ) for file `' . $file . '`. The file may be corrupt or too large for the server.' ); $file_size = 0; $file_modified = 0; } else { // stat success. $file_size = $file_stats['size']; $file_modified = $file_stats['mtime']; } unset( $file_stats );
$integrity = array( 'status' => 'Unknown', 'tests' => array(), 'scan_time' => 0, 'detected_type' => 'unknown', 'size' => $file_size, 'modified' => $file_modified, 'file' => basename( $file ), 'comment' => false, ); $backup_options_options['integrity'] = array_merge( pb_backupbuddy::settings( 'backups_integrity_defaults' ), $integrity ); $backup_options->save();
return $backup_options_options['integrity']; }
//***** BEGIN CALCULATING STATUS DETAILS.
$backup_type = '';
if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) { require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' ); pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( backupbuddy_core::getBackupDirectory() ); }
$previous_status_serial = pb_backupbuddy::get_status_serial(); // Store current status serial setting to reset back later. if ( true !== $skipLogRedirect ) { pb_backupbuddy::status( 'details', 'Redirecting status logging temporarily.' ); pb_backupbuddy::set_status_serial( 'zipbuddy_test' ); // Redirect logging output to a certain log file. }
// Look for comment. pb_backupbuddy::status( 'details', 'Verifying comment in zip archive.' ); $raw_comment = pb_backupbuddy::$classes['zipbuddy']->get_comment( $file ); $comment = backupbuddy_core::normalize_comment_data( $raw_comment ); $comment = $comment['note'];
$tests = array(); pb_backupbuddy::status( 'details', 'NOTE: It is normal to see several "File not found" messages in the next several log lines.' );
// Check for DAT file. $pass = false; pb_backupbuddy::status( 'details', 'Verifying DAT file in zip archive.' ); if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/backupbuddy_dat.php' ) === true ) { // Post 2.0 full backup $backup_type = 'full'; $pass = true; } if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php' ) === true ) { // Pre 2.0 full backup $backup_type = 'full'; $pass = true; } if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'backupbuddy_dat.php' ) === true ) { // DB backup $backup_type = 'db'; $pass = true; } $tests[] = array( 'test' => 'BackupBuddy data file', 'pass' => $pass, );
if ( isset( $options['type'] ) && ( 'files' == $options['type'] ) ) { pb_backupbuddy::status( 'details', 'Files only backup type so skipping scan of database files in backup as it is not applicable.' ); } else { // Non-files only backup so check for DB. // Check for DB .sql file. $pass = false; $db_test_note = ''; pb_backupbuddy::status( 'details', 'Verifying database SQL file in zip archive.' ); if ( isset( $backup_options_options['table_sizes'] ) && ( count( $backup_options_options['table_sizes'] ) > 0 ) ) { // BB v5.0+. && ( $backup_options_options['data_version'] >= 1 ) // Look for missing SQL files. $pass = true; if ( ! isset( $backup_options_options['force_single_db_file'] ) ) { $backup_options_options['force_single_db_file'] = false; } else { if ( true === $backup_options_options['force_single_db_file'] ) { pb_backupbuddy::status( 'details', 'Forcing to a single db_1.sql file WAS enabled for this backup. Only db_1.sql files will be checked for.' ); } else { pb_backupbuddy::status( 'details', 'Forcing to a single db_1.sql file was NOT enabled for this backup.' ); } } pb_backupbuddy::status( 'details', 'BackupBuddy v5.0+ format database datected.' ); if ( 'db' == $backup_options_options['type'] ) { // DB. pb_backupbuddy::status( 'details', 'Database-only type backup.' ); if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'db_1.sql' ) === true ) { // Commandline based. pb_backupbuddy::status( 'details', 'Command line based database dump type.' ); if ( isset( $backup_options_options['breakout_tables'] ) && ( count( $backup_options_options['breakout_tables'] ) > 0 ) && ( true !== $backup_options_options['force_single_db_file'] ) ) { // Verify broken out table SQL files exist. pb_backupbuddy::status( 'details', 'Some tables were broken out. Checking for them (' . implode(',', $backup_options_options['breakout_tables'] ) . '). (DB type)' ); foreach( $backup_options_options['breakout_tables'] as $tableName ) { $databaseFile = $tableName . '.sql'; if ( ! pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, $databaseFile ) ) { pb_backupbuddy::status( 'error', 'Missing database file `' . $databaseFile . '` in backup. Err 3849474b.' ); $pass = false; break; } } } } else { // PHP-based. pb_backupbuddy::status( 'details', 'PHP based database dump type.' ); foreach( $backup_options_options['table_sizes'] as $tableName => $tableSize ) { $databaseFile = $tableName . '.sql'; if ( ! pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, $databaseFile ) ) { pb_backupbuddy::status( 'error', 'Missing database file `' . $databaseFile . '` in backup. Err 383783.' ); $pass = false; break; } else { $backup_type = 'db'; } } } } else { // Full / MS / Export. pb_backupbuddy::status( 'details', 'Not database-only type backup.' ); if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/db_1.sql' ) === true ) { // Commandline based. pb_backupbuddy::status( 'details', 'Command line based database dump type.' ); if ( isset( $backup_options_options['breakout_tables'] ) && ( count( $backup_options_options['breakout_tables'] ) > 0 ) && ( true !== $backup_options_options['force_single_db_file'] ) ) { // Verify broken out table SQL files exist. pb_backupbuddy::status( 'details', 'Some tables were broken out. Checking for them (' . implode(',', $backup_options_options['breakout_tables'] ) . '). (DB type)' ); foreach( $backup_options_options['breakout_tables'] as $tableName ) { $databaseFile = 'wp-content/uploads/backupbuddy_temp/' . $serial . '/' . $tableName . '.sql'; if ( ! pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, $databaseFile ) ) { pb_backupbuddy::status( 'error', 'Missing database file `' . $databaseFile . '` in backup. Err 3849474c.' ); $pass = false; break; } } } } else { // PHP-based. pb_backupbuddy::status( 'details', 'PHP based database dump type.' ); foreach( $backup_options_options['table_sizes'] as $tableName => $tableSize ) { $databaseFile = 'wp-content/uploads/backupbuddy_temp/' . $serial . '/' . $tableName . '.sql'; if ( ! pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, $databaseFile ) ) { pb_backupbuddy::status( 'error', 'Missing database file `' . $databaseFile . '` in backup. Backup type: `' . $backup_options_options['type'] . '`. Err 358383.' ); $pass = false; break; } else { $backup_type = 'full'; } } } } $db_test_note = 's (' . count( $backup_options_options['table_sizes'] ) . ' tables)'; } elseif ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/db_1.sql' ) === true ) { // post 2.0 full backup $backup_type = 'full'; $pass = true; if ( isset( $backup_options_options['breakout_tables'] ) && ( count( $backup_options_options['breakout_tables'] ) > 0 ) ) { // Verify broken out table SQL files exist. pb_backupbuddy::status( 'details', 'Some tables were broken out. Checking for them (' . implode(',', $backup_options_options['breakout_tables'] ) . '). (full type)' ); foreach( $backup_options_options['breakout_tables'] as $tableName ) { $databaseFile = 'wp-content/uploads/backupbuddy_temp/' . $serial . '/' . $tableName . '.sql'; if ( ! pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, $databaseFile ) ) { pb_backupbuddy::status( 'error', 'Missing database file `' . $databaseFile . '` in backup. Err 3849474.' ); $pass = false; break; } } } } elseif ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'db_1.sql' ) === true ) { // db only backup 2.0+. 5.0+ can have this if breaking out tables only partially. $backup_type = 'db'; $pass = true; if ( isset( $backup_options_options['breakout_tables'] ) && ( count( $backup_options_options['breakout_tables'] ) > 0 ) ) { // Verify broken out table SQL files exist. pb_backupbuddy::status( 'details', 'Some tables were broken out. Checking for them (' . implode(',', $backup_options_options['breakout_tables'] ) . '). (db type)' ); foreach( $backup_options_options['breakout_tables'] as $tableName ) { $databaseFile = $tableName . '.sql'; if ( ! pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, $databaseFile ) ) { pb_backupbuddy::status( 'error', 'Missing database file `' . $databaseFile . '` in backup. Err 3847583.' ); $pass = false; break; } } } } elseif ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/temp_' . $serial . '/db.sql' ) === true ) { // pre 2.0 full backup $backup_type = 'full'; $pass = true; } elseif ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'db.sql' ) === true ) { // db only backup pre-2.0 $backup_type = 'db'; $pass = true; } if ( true !== $pass ) { //if ( count( $backup_options_options['table_sizes'] ) > 0 ) { //} } if ( '1' == $options['skip_database_dump'] ) { if ( false === $pass ) { pb_backupbuddy::status( 'warning', 'WARNING: Database .SQL does NOT exist because database dump was set to be skipped based on settings. Use with caution. The database was NOT backed up.' ); } else { // DB dump set to be skipped but was found. Just in case... pb_backupbuddy::status( 'warning', 'Warning #58458749. Database dump was set to be skip _BUT_ database file WAS found?' ); } $pass = true; $db_test_note = ' <span class="pb_label pb_label-warning">' . __( 'Database skipped', 'it-l10n-backupbuddy' ) . '</span>'; $scan_notes[] = '<span class="pb_label pb_label-warning">' . __( 'Database skipped', 'it-l10n-backupbuddy' ) . '</span>'; } $tests[] = array( 'test' => 'Database SQL file' . $db_test_note, 'pass' => $pass, ); }
// Use filename to determine backup type if detectable as it is more authoritive than the above guesses. if ( false !== stristr( $file, '-db-' ) ) { $backup_type ='db'; } elseif ( false !== stristr( $file, '-full-' ) ) { $backup_type ='full'; } elseif ( false !== stristr( $file, '-files-' ) ) { $backup_type ='files'; } else { // Filename determination was not conclusive. Leave as-is based on deduced backup type determined earlier. }
// Check for wp-config.php file if full backup. if ( 'full' == $backup_type ) { $pass = false; pb_backupbuddy::status( 'details', 'Verifying WordPress wp-config.php configuration file in zip archive.' ); if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-config.php' ) === true ) { $pass = true; } if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/wp-config.php' ) === true ) { $pass = true; } if ( false === $pass ) { if ( isset( $options['excludes'] ) ) { if ( false !== stristr( $options['excludes'], 'wp-config.' ) ) { pb_backupbuddy::status( 'warning', 'Warning: An exclusion containing wp-config.php was found. Exclusions: `' . str_replace(array("\r", "\r\n", "\n"), '; ', $options['excludes'] ) . '`.' ); } } } $tests[] = array( 'test' => 'WordPress wp-config.php file (full backups only)', 'pass' => $pass, ); } // end if full backup.
// Get zip scan log details. pb_backupbuddy::status( 'details', 'Retrieving zip scan log.' ); $temp_details = pb_backupbuddy::get_status( 'zipbuddy_test' ); // Get zipbuddy scan log. $scan_log = array(); foreach( $temp_details as $temp_detail ) { $scan_log[] = json_decode( $temp_detail )->{ 'data' }; } if ( true !== $skipLogRedirect ) { pb_backupbuddy::set_status_serial( $previous_status_serial ); // Stop redirecting log to a specific file & set back to what it was prior. pb_backupbuddy::status( 'details', 'Stopped temporary redirection of status logging.' ); }
pb_backupbuddy::status( 'details', 'Calculating integrity scan status,' );
// Check for any failed tests. $is_ok = true; $integrity_description = ''; foreach( $tests as $test ) { if ( $test['pass'] !== true ) { $is_ok = false; $error = 'Error #389434. Integrity test FAILED. Test: `' . $test['test']. '`. '; pb_backupbuddy::status( 'error', $error ); $integrity_description .= $error; } }
if ( true === $is_ok ) { $integrity_status = 'Pass'; } else { $integrity_status = 'Fail'; } pb_backupbuddy::status( 'details', 'Status: `' . $integrity_status . '`. Description: `' . $integrity_description . '`.' );
//***** END CALCULATING STATUS DETAILS.
// Get file information from file system. pb_backupbuddy::status( 'details', 'Getting file details such as size, timestamp, etc.' ); $file_stats = @stat( $file ); if ( $file_stats === false ) { // stat failure. pb_backupbuddy::status( 'error', 'Error #4539774b. Unable to get file details ( via stat() ) for file `' . $file . '`. The file may be corrupt or too large for the server.' ); $file_size = 0; $file_modified = 0; } else { // stat success. $file_size = $file_stats['size']; $file_modified = $file_stats['mtime']; // Created time. } unset( $file_stats );
// Compile array of results for saving into data structure. $integrity = array( 'is_ok' => $is_ok, // bool 'tests' => $tests, // Array of tests. 'scan_time' => time(), 'scan_log' => $scan_log, 'scan_notes' => $scan_notes, // Misc text to display next to status. 'detected_type' => $backup_type, 'size' => $file_size, 'modified' => $file_modified, // Actually created time now. 'file' => basename( $file ), 'comment' => $comment, // boolean false if no comment. string if comment. );
$integrity = array_merge( pb_backupbuddy::settings( 'backups_integrity_defaults' ), $integrity ); if ( is_array( $backup_options_options ) ) { pb_backupbuddy::status( 'details', 'Saving backup file integrity check details.' ); $backup_options_options['integrity'] = $integrity; $backup_options->save(); }
return $integrity;
|