View Single Post
Old 6th July 2012, 21:10
sjau sjau is offline
Local Meanie
Join Date: Apr 2006
Location: Switzerland
Posts: 1,158
Thanks: 4
Thanked 58 Times in 54 Posts

I'm not quite following what you try to backup when....

However I made a few adjustements to your script. Quote whatever you can and for variables you can use ${var} which makes it simpler in quotes to seperate it from other text.


#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}"
"Common sense is not as common as commonly believed" by sjau

Auto-Install Script for ISPConfig and Horde on a Vanilla Debian Stable

Need more Repos for Ubuntu? Repository Generator
Need more Repos for Debian? Debian Repository Generator
Reply With Quote