Backing up your Deki Wiki involves two steps: backing up your database and your file attachments.
Backing up your database
You can do this from command line by issuing the following command:
mysqldump -udbusername -p db_name > db_name.sql
Backing up your attachments
cd /path/to/wiki/;
tar cvzpf attachments.tar.gz attachments
Restoring your database
mysql -udbusername -p db_name <>
Restoring your attachments
cd /path/to/wiki/;
tar xvzpf attachments.tar.gz
Using Crontab for automated backups
The following is an example of automated backups. This assumes that /mnt/hgfs/BackupWiki is available to dump backups to outside the VM image (e.g. a directory on another disk) and the result is 7 daily backups a week tagged by day (e.g. Thu.attachments-backup.tar.gz and Thu.wikidb-backup.sql). (Note: it would be nice for someone to document how to do this via SCP,FTP or rsync for those that don't have mnt/hgfs/BackupWiki configured).
The backup_script
#!/bin/bash
today="$(date +%a)"
#dump today's database
mysqldump -u root -ppassword wikidb > /mnt/hgfs/BackupWiki/$today.wikidb-backup.sql
#dump today's attachments
cd /var/www/deki-hayes/
tar czf /mnt/hgfs/BackupWiki/$today.attachments-backup.tar.gz attachments
The script above creates files with a name like "Sun.wikidb-backup.sql". i,.e. only the day of the week is prepended to the backup name. You can format the date any way you like. Type man date at the command prompt to see all formatting possibilities (begin with %).
A useful one is
today="$(date + %Y-%m-%d)"
whch results in files like "2008-01-25.wikidb-backup.sql"
Make a cron job ("crontab -e" to create and edit) to run the script automatically.
The script below runs the backup_script daily at 4 am.
# m h dom mon dow command
0 04 * * * sh $PATH_TO_YOUR_SCRIPT/backup_script > /var/tmp/dekiwiki.backup.log 2>&1
NOTE: Alternatives to the sh in the above command are bash, ksh or csh depending upon the shell that you are using. You may also precede the backup_script with a simple ". " (dot) to execute the shell script. In order to execute the backup command without the above sh or equivalent you give backup_script execute permission with the command "chmod 700 backup_script".
The 2>&1 in the above crontab command redirects errors in executing the command to the /var/tmp/dekiwiki.backup.log which you should review for errors which may keep you backup from completing successfully. Always verify that that the crontab backup has run as specified to ensure that you have valid backups of your database and attachments.
No comments:
Post a Comment