Backup strategy and script of MySQL and versioning tool for dev machine
We often think about automating the backups of your production server but you easily forget your development machine. It may not be very important to back up databases but it is not the same for svn and git repositories. If your production server can crash, so can your server or development PC.
Until now, I've been wrongly using the same backup strategy for my prod server and dev server. Why is it wrong? Because making a daily backup at a fixed time is not a good idea when you don't have to do it every day and especially when you don't let your machine on 24 hours a day. Even if my eeebox only needs 20W, over the year it would be a nice useless consumption to leave it on all the time.
So I reviewed my strategy and my scripts. Not being able to determine in advance what time my dev server will be turned on, I start the backup every hour. And of course in order not to redo a backup already made, I added a test if the destination file exists or not.
Backing up MySQL databases
<a>#!/bin/bash #date du jour DATE=`date +%y_%m_%d` #liste des bases LISTEBDD=$( echo 'show databases' | mysql -uroot -pxxxx) for SQL in $LISTEBDD do if [ $SQL != "information_schema" ] && [ $SQL != "mysql" ] && [ $SQL != "Database" ]; then if [ -e /home/backup/sql/$SQL"_mysql_"$DATE.sql.gz ]; then #exit else mysqldump -uroot -pxxxx $SQL | gzip > /home/backup/sql/$SQL"_mysql_"$DATE.sql.gz fi fi done </a>
Saving the SVN repository
<a>#!/bin/bash #date du jour DATE=`date +%y_%m_%d` #liste des dossier LISTEDIR=$(ls /var/svn/) #on boucle sur chaque dossier for DOSSIER in $LISTEDIR do if [-e /home/backup/svn/$DOSSIER"_svn_"$DATE.gz ]; then #exit else svnadmin dump /var/svn/$DOSSIER | gzip > $DOSSIER"_svn_"$DATE.gz && mv $DOSSIER"_svn_"$DATE.gz /home/backup/svn fi done</a>
<a> > crontab -e </a>
<a>0 * * * * sh /root/backup_mysql.sh 0 * * * * sh /root/backup_svn.sh</a>
Add a comment