Guest User

Untitled

a guest
Mar 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/bin/bash
  2. # You must init a git repo in $backup_root for this to work
  3. # You must also have a remote repo added per $git_remote
  4. # It's assumed that you have your remote git host configured
  5. # via ~/.ssh/config or something for automatic login with a key
  6.  
  7. # Local stuff
  8. wwwroot="/var/www/your-blog/" # Trailing slash is important (for rsync)
  9. db_name="blog_db"
  10. db_user="blog_user"
  11. db_pass="blog_passwd"
  12.  
  13. # Backup things
  14. backup_root="/backups/your-backup-dir"
  15. backup_www="${backup_root}/wwwroot/" # Trailing slash is important (for rsync)
  16. backup_db="${backup_root}/database_backup.sql"
  17. backup_err="${backup_root}/backup_errors.log"
  18.  
  19. # Git settings
  20. git_remote="remote_backup"
  21.  
  22. # Make sure the backup_www dir exists
  23. mkdir -p $backup_www
  24.  
  25. # Rsync the files
  26. rsync -a -P $wwwroot $backup_www >/dev/null 2>$backup_err
  27.  
  28. # Dump the database
  29. mysqldump --create-options $db_name -u $db_user --password=${db_pass} > $backup_db 2>>$backup_err
  30.  
  31. # Commit changes to git
  32. cd $backup_root
  33. git add . >/dev/null 2>>$backup_err
  34. git commit -m "Automatic backup" >/dev/null 2>>$backup_err
  35.  
  36. # Push the git repo to remote host for backup
  37. git push $git_remote master >/dev/null 2>&1
Add Comment
Please, Sign In to add comment