sufehmi

Wordpress Auto-Backup via SSH

Feb 18th, 2018
853
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×