Register
It is currently Sun Apr 20, 2014 10:05 am

mysql database backup: 7 days backup & mail confirmation


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Sep 11, 2007 11:43 am   

Joined: Tue Sep 11, 2007 11:33 am
Posts: 1
i want a script which should backup the mysql database automatically everyday
also should keep only last 7 days back up & a confirmation mail that database backup went fine also date & time of the backup .

i have made a script which takes backup everyday ...however require some help to modify the below script and keep it only for last 7 days script & a confirmation mail

Below is the script which i have made...would appreciate ..if anybody can help me



dt=`date +%d`"-"`date +%m`"-"`date +%y`
BKPFILE1="$HOME/jatin.backup/jatin_dump_${dt}.sql"

cd /home/fic_user/jatin.backup
/usr/bin/mysqldump -u 'username' --p 'password' fic_ashokadb > $BKPFILE1


Top
 Profile  
 PostPosted: Thu Oct 11, 2007 7:40 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 224
Location: London - UK
Yo,

For backups I strongly recommend using a different date format so it's easy to use bash tools to search for particular dates, you should be able to modify my changes back to the old format if required. Also in my opinion mysqlhotcopy is a better backup system (check mysql site) depending on your version of mysql.
This should do, although there are _many_ improvements I would normally put into one of my own backup scripts.

# combining the date commands into 1 command is tidier and easier to read
today=`date +%Y-%m-%d`
# note the use of '-d' switch to specify which date I want
lastweek=`date -d '7 days ago' +%Y-%m-%d`

BKPFILE1="$HOME/jatin.backup/jatin_dump_${today}.sql"
BKPFILEDELETE="$HOME/jatin.backup/jatin_dump_${lastweek}.sql"

cd /home/fic_user/jatin.backup
/usr/bin/mysqldump -u 'username' --p 'password' fic_ashokadb > $BKPFILE1

# check if an old backup file exists
if [ -e $BKPFILEDELETE ]
then
# if so then delete it
rm $BKPFILEDELETE
fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP