Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment