TITex,
Thanks for your response. I can test what you wrote, but here's what I came up with, and it works:
#!/bin/bash
#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
touch $FILENAME
#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.
Diggy
Last edited by Diggy; 6th July 2012 at 14:42.
|
Recent comments
2 hours 55 min ago
12 hours 23 min ago
13 hours 13 min ago
16 hours 46 min ago
21 hours 10 min ago
21 hours 32 min ago
23 hours 42 min ago
1 day 9 hours ago
1 day 14 hours ago
1 day 16 hours ago