3 # Called by cron to backup a database, or all databases
6 require './mysql-lib.pl';
8 if ($ARGV[0] eq "--all") {
10 @dbs = grep { &supports_backup_db($_) } &list_databases();
11 $cmode = $config{'backup_cmode_'};
14 $ARGV[0] || die "Missing database parameter";
20 # Run and check before-backup command (for all DBs)
21 $bok = &execute_before(undef, STDOUT, 0, $config{'backup_'}, undef);
23 print "Before-backup command failed!\n";
28 # Check if MySQL is running
29 if (!$config{'host'}) {
30 ($r, $out) = &is_mysql_running();
32 print "MySQL does not appear to be running : $out\n";
33 print "Backups cannot be performed.\n";
40 $sf = $all ? "" : $db;
42 $dir = &date_subs($config{'backup_'});
43 &make_dir($dir, 0755) if ($config{'backup_mkdir_'});
44 $file = $dir."/".$db.".sql".
45 ($config{'backup_compress_'.$sf} == 1 ? ".gz" :
46 $config{'backup_compress_'.$sf} == 2 ? ".bz2" : "");
49 $file = &date_subs($config{'backup_'.$db});
52 print STDERR "No backup file set for database $db\n";
55 @compat = $config{'backup_compatible_'.$sf} ?
56 ( $config{'backup_compatible_'.$sf} ) : ( );
57 push(@compat, split(/\0/, $in{'backup_options_'.$sf}));
58 @tables = split(/\s+/, $config{'backup_tables_'.$sf});
61 # Run and check before-backup command (for one DB)
62 $bok = &execute_before($db, STDOUT, 0, $file, $all ? undef : $db);
64 print "Before-backup command failed!\n";
71 $err = &backup_database($db, $file,
72 $config{'backup_compress_'.$sf},
73 $config{'backup_drop_'.$sf},
74 $config{'backup_where_'.$sf},
75 $config{'backup_charset_'.$sf},
79 $config{'backup_single_'.$sf});
81 print "Backup of database $db to file $file failed:\n";
86 &execute_after($db, STDOUT, 0, $file, $all ? undef : $db);
90 &execute_after(undef, STDOUT, 0, $config{'backup_'}, undef);