#! /usr/bin/perl -w #--------------------------------- # CONFIGURATION CONSTANTS #--------------------------------- #name of the database to restore. # This can be the same as the db that was backed up # or to create a new db from backup, enter a new name my $DB = "TEST_SML"; #name of database that was backed up. May be the same value as $DB. my $SOURCE = "TEST_SML"; #directory where backups are located my $BACKUP_DIR = "/usr2/databases/backup/nightly/"; #time stamp for the backup to be restored my $BACKUP_TIME = "20030404155017"; # Location of DB2 data directory my $INSTANCE_DIR = "/usr2/ldasdb"; # Set to 1 to apply the logs; 0 to just restore backup my $APPLY_LOGS = 1; #-------------------------------- # Main #-------------------------------- #Use without rolling forward to leave database in a usable state. my $restore_no_logs = "db2 \"RESTORE DATABASE $SOURCE FROM $BACKUP_DIR " . "TAKEN AT $BACKUP_TIME TO $INSTANCE_DIR INTO $DB " . "WITH 2 BUFFERS BUFFER 1024 WITHOUT ROLLING FORWARD WITHOUT PROMPTING \" "; # Use the following to apply the logs. This HAS NOT been tested with live data. my $restore = "db2 RESTORE DATABASE $SOURCE FROM $BACKUP_DIR " . "TAKEN AT $BACKUP_TIME TO $INSTANCE_DIR INTO $DB " . "WITH 2 BUFFERS BUFFER 1024 WITHOUT PROMPTING " ; my $apply_logs = "db2 ROLLFORWARD DATABASE $DB TO END OF LOGS AND STOP "; if ($APPLY_LOGS) { print $restore,"\n"; system $restore; print $apply_logs,"\n"; system $apply_logs; }else{ print $retore_no_logs,"\n"; system $retore_no_logs; }