daily pastebin goal
69%
SHARE
TWEET

Wordpress Auto-Backup via SSH

sufehmi Feb 18th, 2018 (edited) 196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. ### THIS SCRIPT ASSUMES THE FOLLOWING
  4. # 1/ You can do SSH password-less login to the server
  5. #   How : https://easyengine.io/tutorials/linux/passwordless-authentication-ssh/
  6. # 2/ You have created a correct ~/.my.cnf file
  7. #   How : https://easyengine.io/tutorials/mysql/mycnf-preference/
  8.  
  9. wordpress_server=MyUser@MyServer.com
  10. wordpress_location=/home/MyUser/MyWebsite
  11. backup_location=/MyDisk/MyBackup
  12.  
  13. mysql_server=mysql.MyWebsite.com
  14. mysql_database=MyDatabase_db
  15.  
  16. # ====== START BACKUP ============
  17.  
  18. today=`date +%A`
  19.  
  20. # backup database
  21. ssh  $wordpress_server "mysqldump -h $mysql_server $mysql_database > $wordpress_location/db-$today.mysql"
  22. ssh  $wordpress_server "gzip $wordpress_location/db-$today.mysql"
  23.  
  24. # download everything
  25. rsync -avuz $wordpress_server:$wordpress_location/* $backup_location/
  26.  
  27. # delete database backup
  28. # so no one can download it via the website
  29. ssh $wordpress_server "rm $wordpress_location/db-$today.mysql.gz"
  30.  
  31. # done !
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top