3 # Called by cron to backup a database
6 require './postgresql-lib.pl';
8 if ($ARGV[0] eq "--all") {
10 @dbs = &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 STDERR "Before-backup command failed!\n";
29 $sf = $all ? "" : $db;
30 if (!&accepting_connections($db)) {
31 #print STDERR "Database $db is not accepting connections.\n";
34 $format = $config{'backup_format_'.$sf};
35 $mkdir = $config{'backup_mkdir_'.$sf};
36 $suf = $format eq "p" ? "sql" :
37 $format eq "t" ? "tar" : "post";
39 $dir = &date_subs($config{'backup_'});
40 $file = "$dir/$db.$suf";
41 &make_backup_dir($dir) if ($mkdir);
44 $file = &date_subs($config{'backup_'.$db});
46 @tables = split(/\s+/, $config{'backup_tables_'.$sf});
48 print STDERR "No backup file set for database $db\n";
53 # Run and check before-backup command (for one DB)
54 $bok = &execute_before($db, STDOUT, 0, $file, $all ? undef : $db);
56 print STDERR "Before-backup command failed!\n";
63 $err = &backup_database($db, $file, $format, \@tables);
65 print STDERR "Backup of database $db to file $file failed:\n";
70 &execute_after($db, STDOUT, 0, $file, $all ? undef : $db);
74 &execute_after(undef, STDOUT, 0, $config{'backup_'}, undef);