function dba_auto_backup in Database Administration 5
1 call to dba_auto_backup()
- dba_cron in ./dba.module
File
- ./dba.module, line 339
- Allows administrators direct access to their Drupal database.
Written by Jeremy Andrews <jeremy@kerneltrap.org>, June 2004.
PostgreSQL functionality provided by AAM <aam@ugpl.de>
Major security audit, porting, and maintenance by
Derek…
Code
function dba_auto_backup() {
$backup_started = time();
$path = variable_get('dba_auto_backup_path', file_directory_temp());
$exclude_tables_str = variable_get('dba_auto_backup_exclude_tables', DBA_BACKUP_EXCLUDE);
$exclude_tables = split('[ ,]', $exclude_tables_str);
if (file_check_directory($path, FILE_CREATE_DIRECTORY)) {
$database = dba_get_database();
$filename = format_date(time(), 'custom', 'Y-md-Hi_') . variable_get('dba_default_filename', 'backup.sql');
$backup = "-- Drupal dba.module database dump\n";
$backup .= "--\n";
$backup .= "-- Database: {$database}\n";
$backup .= "-- Date: " . format_date(time(), 'large') . "\n\n";
$tables = dba_get_tables();
foreach ($tables as $table) {
$backup .= dba_backup_table($table, TRUE, FALSE, in_array($table, $exclude_tables) ? FALSE : TRUE);
}
if (variable_get('dba_auto_backup_bzip2', 0)) {
$backup = bzcompress($backup, 9);
$filename = $filename . '.bz2';
}
else {
if (variable_get('dba_auto_backup_gzip', 0)) {
if (version_compare(phpversion(), '4.2', '>=')) {
$backup = gzencode($backup, 9, FORCE_GZIP);
}
else {
$backup = gzencode($backup, FORCE_GZIP);
}
$filename = $filename . '.gz';
}
}
if ($fp = fopen($path . "/{$filename}", 'wb')) {
fwrite($fp, $backup);
fclose($fp);
variable_set('dba_auto_backup_last', $backup_started);
if (variable_get('dba_auto_backup_mail', 0)) {
$attachment = new stdClass();
$attachment->path = $path . "/{$filename}";
$attachment->filename = $filename;
dba_mail_backup($attachment);
}
}
}
}