wordpress daily backup
Monday, July 31, 2006 6:09:14 PM
#!/bin/sh
todaydate=`date +%u`
longdate=`date +%m%d%Y`
ebkname="/var/backup/wordpress/wp-ebk-sql_$longdate.sql.bz2"
bkname2="/var/backup/wordpress/wp-bk-sql_$longdate.sql.bz2"
bkname="/var/backup/wordpress/wp-bk-sql_$todaydate.sql.bz2"
if [ -e $bkname ]
then
filesize=`du -b $bkname | awk ' { print $1 }'`
fi
if [ ! -d "/var/backup/wordpress/" ]
then
mkdir -p /var/backup/wordpress/
fi
mysqldump --add-drop-table -u ****** --database wordpress --password=****** | bzip2 -c > /tmp/wpsql
if [ `du -b /tmp/wpsql | awk ' { print $1 }'` -lt $filesize ]
then
mv -f $bkname $ebkname
echo "Emergency-Backup $ebkname "`date` >> /var/log/wpbk.log
fi
mv -f /tmp/wpsql $bkname
echo "Daily-Backup $bkname "`date` >> /var/log/wpbk.log
if [ $todaydate -eq 7 ]
then
cp -f $bkname $bkname2
echo "Weekly-Backup $bkname2 "`date` >> /var/log/wpbk.log
fi
exit
This can be consider a dirty coding, no comments at all. We need it fast and this is the one. We put this in /etc/cron.daily and restart crond service.
Okay I will briefly explain what my script have done. My script help us to do daily and weekly backup on wordpress database using mysqldump. It will backup 7 copy of database just in case anything goes wrong and it allows us to refers back. So if today is monday, it will backup as name "wp-ebk-sql_1.sql.bz2" and tuesday will be "wp-ebk-sql_2.sql.bz2" and until next week of monday, the file will be replace. This is daily backup. Every sunday, it will backup a copy with long date, that copy will stay permenently unless you delete it. This is weekly backup.
Another backup I called it as Emergency backup. Before I do daily backup, I ll check last weekday backup file. If it is exist, then compare the file size. If it's file size is larger than new backup files, that means something wrong might already happen. Then I will not replace the file at first, I ll backup that file with long date and carry on the replacement.
Each time I do the backup, I will log it for reference.















