Pages

Friday, November 27, 2009

Website backup script

This script has many issues. The biggest is that it is dumping xml from mysql. There currently is not a good restoration path from an xml export.

I'll be updating this script using svn for versions and a one insert per line mysqldump for more effective diffs.



#!/ramdisk/bin/bash

function updateCurrent(){
linkcurrent=$1
newfile=$2

if [ -h ${linkcurrent} ] ; then
linktarget=`/usr/bin/readlink ${linkcurrent}`

rm ${linkcurrent}

if [ -e ${linktarget} ] && diff ${linktarget} ${newfile} > /dev/null; then
rm -rf ${linktarget}
fi
fi

ln -s ${newfile} ${linkcurrent}
}

dts=`/bin/date +\%Y\%m\%d\%H\%M\%S`
currentSqlLink='/path/to/home/tmp/sqlCurrent'
currentTarLink='/path/to/home/tmp/tgzCurrent'

newSql="/path/to/home/backups/uniquieName-${dts}"
newTar="/path/to/home/backups/emz-${dts}"

mysqldump -X --user=db_user --password=secret --skip-dump-date --host=127.0.0.1 db_name > $newSql
updateCurrent ${currentSqlLink} ${newSql}

tar -cf ${newTar} /path/to/home/web_root/
updateCurrent ${currentTarLink} ${newTar}


No comments:

Post a Comment