Friday, October 26, 2007

Monthly Backups

Many people I have talked with have a requirement to keep a month end backup for an extended period of time. This is where backupsets can be very helpful, but what do you do when backupsets just wont cut it? Well I have a requirement to keep some month end data for extended periods but all other backups are kept for 30 days. How do I accomplish this? The answer is a shell script. Before the ehanced scheduler came about in TSM 5.3 the only way to get the backup to change to a different type at the end/beginning of the month was to have some script handle it or you could manually control it. So here is a good shell script that looks at the day of the month and if it is the 1st it runs a backup to an alternate nodename. In this example the nodename is the same as the default nodename with -MONTHLY added to the end. We also made a dsm.opt file called dsm.opt.monthly that references the stanza in the dsm.sys with the alternate name. Then schedule this script as a daily command script for the node and it will run the daily incremental to the default nodename every day except on the 1st of the month. I hope this is useful for some of you. Click Read More to see the script.

#!/usr/bin/ksh
#set -x
export PATH=$PATH:.:/etc:/usr/sbin:/bin:/usr/local/lib:
export LIBPATH=$LIBPATH:/usr/odcs/bin
export DSM_LOG=/opt/tivoli/tsm/client/ba/bin
export DSM_DIR=/opt/tivoli/tsm/client/ba/bin
BK_SCRIPT_LOGFILE=/usr/local/scripts/logs/Filesystem-incremental-backup.log
if [ -f $BK_SCRIPT_LOGFILE ]; then
mv $BK_SCRIPT_LOGFILE $BK_SCRIPT_LOGFILE.`date +%d`
printf "`date` - Starting Backup\n" >> $BK_SCRIPT_LOGFILE
fi
printf " test " >> $BK_SCRIPT_LOGFILE
# Modified to use the monthly opt file on the 1st for monthly backups that are
# kept for a extended period of time.


case `date +%d` in
01)
export DSM_CONFIG=/opt/tivoli/tsm/client/ba/bin/dsm.opt.monthly
;;
*)
export DSM_CONFIG=/opt/tivoli/tsm/client/ba/bin/dsm.opt
;;
esac
# Back up the filesystems
#
printf "`date` - Starting the backup of the filesystems.\n" >> $BK_SCRIPT_LOGFILE
# Set the success variable to zero
INCR_BACKUP_SUCCESS=0


/opt/tivoli/tsm/client/ba/bin/dsmc incr >> $BK_SCRIPT_LOGFILE
# /opt/tivoli/tsm/client/ba/bin/dsmc q fi >> $BK_SCRIPT_LOGFILE INCRCODE=$?
if [[ $INCRCODE -ne 0 && $INCRCODE -ne 4 && $INCRCODE -ne 8 ]]
then
printf "`date` - Incremental backup failed - return code: $INCRCODE\n" >> $BK_SCRIPT_LOGFILE
exit 1111
else
printf "`date` - Incremental of $FS successful - return code: $INCRCODE\n" >> $BK_SCRIPT_LOGFILE
fi
printf "`date` - Backup has completed successfully\n" >> $BK_SCRIPT_LOGFILE
echo $?

1 comment:

  1. Thanks Chad,

    That's a really interesting way of doing it that never occurred to me. (I've set up separate schedules to do the same thing before, but this does make a lot of sense)

    ReplyDelete