5 test_load_dbs.pl - test load dbs on a redundant server, to be run by cron
9 test_load_dbs.pl test loads the databases specified in a conf file, test_load_dbs.conf.
11 The conf file contains two columns of paths to database dumps to be restored and the name of the database to be given in the redundant server.
15 Lukas Mueller <lam87@cornell.edu>
21 my $conf = shift || "/root/test_load_dbs.conf";
23 open(my $F, "<", $conf);
27 my ($dbdump, $dbname) = split /\s+/;
29 print "Processing $dbname from dump file $dbdump\n";
30 if (! -e
$dbdump || -s
$dbdump == 0) {
31 print "The file $dbdump does not exist of is empty. NOT TEST LOADING $dbdump!!!\n";
35 backup_db
($dbdump, $dbname);
37 print "Completed $dbname.\n\n\n";
40 print "Completed conf file $conf\n. Have a nice day!\n\n";
46 # test if database exists
49 $ENV{DBDUMP
} = $dbdump;
50 $ENV{DBNAME
} = $dbname;
52 ##system('echo DBDUMP = $DBDUMP');
53 ##system('echo DBNAME = $DBNAME');
55 system('sudo -u postgres psql -l | grep -q $DBNAME && sudo -u postgres dropdb -U postgres $DBNAME'); ### deanx - Oct 02 2007 - originally the createdb statement was part of the DB load
56 # below. But I found that caused login/sudo confusion and failed. now
57 # the createdb is simply a seperate step
58 # print "Create new database for the daily build of $dbdump...\n";
59 system('sudo -u postgres createdb -E SQL_ASCII $DBNAME');
62 print "Loading database from dump (this may take a while...)\n";
63 # reload the database from file given as parameter
64 system('time { zcat -f "$DBDUMP" ; echo COMMIT ; } | sudo -u postgres psql -U postgres --echo-all --variable AUTOCOMMIT=off --variable ON_ERROR_STOP=t --dbname $DBNAME > ${2:-/tmp/build_creation_log\_$DBNAME} 2>&1 || { sudo -u postgres dropdb -U postgres $DBNAME; echo Database load failed! > /dev/stderr ; exit 1; } ');