Skip to content

Instantly share code, notes, and snippets.

@craSH
Created December 21, 2009 19:12
Show Gist options
  • Save craSH/261160 to your computer and use it in GitHub Desktop.
Save craSH/261160 to your computer and use it in GitHub Desktop.
A very simple script to save differential backups of a wordpress installation directory and it's database. Should be easy enough to adapt to other needs.
#!/bin/bash
# You must init a git repo in $backup_root for this to work
# You must also have a remote repo added per $git_remote
# It's assumed that you have your remote git host configured
# via ~/.ssh/config or something for automatic login with a key
# Local stuff
wwwroot="/var/www/your-blog/" # Trailing slash is important (for rsync)
db_name="blog_db"
db_user="blog_user"
db_pass="blog_passwd"
# Backup things
backup_root="/backups/your-backup-dir"
backup_www="${backup_root}/wwwroot/" # Trailing slash is important (for rsync)
backup_db="${backup_root}/database_backup.sql"
backup_err="${backup_root}/backup_errors.log"
# Git settings
git_remote="remote_backup"
# Make sure the backup_www dir exists
mkdir -p $backup_www
# Rsync the files
rsync -a -P $wwwroot $backup_www >/dev/null 2>$backup_err
# Dump the database
mysqldump --create-options $db_name -u $db_user --password=${db_pass} > $backup_db 2>>$backup_err
# Commit changes to git
cd $backup_root
git add . >/dev/null 2>>$backup_err
git commit -m "Automatic backup" >/dev/null 2>>$backup_err
# Push the git repo to remote host for backup
git push $git_remote master >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment