View Single Post
Old 6th July 2012, 15:25
Diggy Diggy is offline
Junior Member
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts


Thanks for your response. I can test what you wrote, but here's what I came up with, and it works:

#first day of previous month
FIRST_DAY=`date -d "-1 month -$(($(date +"%d")-1)) days" +"%b%e"`
#first day of this month
LAST_DAY=`date -d "-0 month -$(($(date +"%d")-1)) days" +"%b%e"`
#name file to be used by tar
FILENAME="backup"`date --date="last month" +%Y%m`".txt"
#date part of tar file name
FILEDATE=`date --date="last month" +%Y_%m`
#create file to be used by tar
#create start and end dates of backup directories to be tarred
touch --date "$FIRST_DAY" /tmp/start
touch --date "$LAST_DAY" /tmp/end
#identify the directories to be tarred and add them to the file to be used by tar
find /data/nightly_data_backup -type d -newer /tmp/start -not -newer /tmp/end -print | sort > $FILENAME
#start portmap service
service portmap start
#open connection to NAS
mount -t nfs netdisk219:/mnt//vol001/volume02/Archive/Database /backup
#back up the database directories to NAS
tar -czf /backup/$FILEDATE".tar.gz" --files-from $FILENAME
#close connection to NAS
umount /backup
#stop portmap service
service portmap stop
#clean up
rm -f /tmp/start /tmp/end
rm -f /root/$FILENAME

The script runs on a CentOS 6.2 system. More elegant solutions might be available but, as I mentioned, it works. I'll test it again next month and, if it still works as expected, I'll create a monthly cron job to run it.

Hope it helps with your learning.


Last edited by Diggy; 6th July 2012 at 15:42.
Reply With Quote