Index: dba.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dba/dba.module,v
retrieving revision 1.21.2.1
diff -u -F^f -r1.21.2.1 dba.module
--- dba.module	24 Mar 2005 08:39:52 -0000	1.21.2.1
+++ dba.module	13 May 2005 23:47:06 -0000
@@ -86,9 +86,34 @@ function dba_menu($may_cache) {
   return $items;
 }
 
+function dba_cron() {
+  if (variable_get('dba_auto_backups', NULL) &&
+       (time() - variable_get('dba_last_timestamp', '') >= variable_get('dba_timestamp',  259200)) &&
+       file_check_directory(variable_get('dba_default_path', '/var/backups'), 0, 'dba_default_path')) {
+
+    $path = variable_get('dba_default_path', '/var/backups') . '/' .format_date(time(), 'custom', 'Y_m_d_H_i') . '_' . variable_get('dba_default_filename', 'backup.sql');
+    $data = dba_backup_tables(dba_get_tables(),$path,TRUE);
+    file_save_data($data, $path);
+    variable_set('dba_last_timestamp',  time());
+  }
+}
+
 function dba_settings() {
   // Backups
   $group = form_textfield(t('Default backup filename'), 'dba_default_filename', variable_get('dba_default_filename', 'backup.sql'), 45, 255, t('Default filename to use when backing up multiple tables.  If backing up only one table, the filename will default to the name of the table.  You will have an opportunity to modify this filename when you actually perform the backup.'));
+  $period = drupal_map_assoc(array(60, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
+
+  $group .= form_checkbox(t('Automatic backups'), 'dba_auto_backups', 1, variable_get('dba_auto_backups', NULL), t('Enable automatic backups'));
+  if (variable_get('dba_auto_backups', NULL)) {
+    file_check_directory(variable_get('dba_default_path', '/var/backups'), 0, 'dba_default_path');
+  }
+  else {
+    $attributes = array('disabled'=>'disabled');
+    $extra = 'disabled="disabled"';
+  }
+  $group .= form_textfield(t('Default backup path'), 'dba_default_path', variable_get('dba_default_path', '/var/backups'), 30, 255, t('Directory where backups will be stored. Note that this directory must never be accessible from the web! Please learn about security and file permissions first. For all peple with access to these backup files, will be able to read all your crucial information.'),$attributes);
+  $group .= form_select(t('Automatic backup interval'), 'dba_timestamp', variable_get('dba_timestamp', 259200), $period, t('Interval for automatic backup of the database into files. Requires crontab.'),$extra);
+
   $output = form_group(t('Database backup'), $group);
 
   // MySQL
@@ -175,16 +200,8 @@ function dba_admin() {
     case t('Backup table'):
     case t('Backup tables'):
       if (user_access('dba administer database')) {
-        $database = dba_get_database();
-        $backup = "-- Drupal dba.module database dump\n--\n-- Database: $database\n-- Date: " . format_date(time(), 'large') ."\n\n";
-        foreach (explode(',', $edit['tables']) as $table) {
-          $backup .= dba_backup_table($table);
-        }
+        dba_backup_tables(explode(',', $edit['tables']),$edit['file_name']);
       }
-      Header("Content-type: application/octet-stream");
-      Header("Content-Disposition: attachment; filename=". $edit['file_name']);
-      echo $backup;
-      exit(0);
       break;
     case t('Empty'):
       if (dba_get_active_tables($edit, 0)) {
@@ -794,6 +811,24 @@ function dba_backup_table($table) {
   return $output;
 }
 
+//Backup More tables
+function dba_backup_tables($tables, $file_name, $return = FALSE) {
+  $database = dba_get_database();
+  $backup = "-- Drupal dba.module database dump\n--\n-- Database: $database\n-- Date: " . format_date(time(), 'large') ."\n\n";
+   foreach ($tables as $table) {
+     $backup .= dba_backup_table($table);
+   }
+   if (!$return) {
+    Header("Content-type: application/octet-stream");
+    Header("Content-Disposition: attachment; filename=". $file_name);
+    echo $backup;
+    exit(0);
+   }
+   else {
+     return $backup;
+   }
+}
+ 
 // Delete table contents
 function dba_delete_table($table) {
   if (_is_mysql()) {
