WordPress Auto-Backup via SSH

This script will enable you to backup your WordPress websites automatically. Just put it in a crontab / automatic scheduling software somewhere.

Also available on Pastebin : https://pastebin.com/nZ2fiL8j

Enjoy.

=====
#!/bin/bash

### THIS SCRIPT ASSUMES THE FOLLOWING
# 1/ You can do SSH password-less login to the server
# How : https://easyengine.io/tutorials/linux/passwordless-authentication-ssh/
# 2/ You have created a correct ~/.my.cnf file
# How : https://easyengine.io/tutorials/mysql/mycnf-preference/

wordpress_server=MyUser@MyServer.com
wordpress_location=/home/MyUser/MyWebsite
backup_location=/MyDisk/MyBackup

mysql_server=mysql.MyWebsite.com
mysql_database=MyDatabase_db

# ====== START BACKUP ============

today=`date +%A`

# backup database
ssh $wordpress_server "mysqldump -h $mysql_server $mysql_database > $wordpress_location/db-$today.mysql"
ssh $wordpress_server "gzip $wordpress_location/db-$today.mysql"

# download everything
rsync -avuz --delete $wordpress_server:$wordpress_location/* $backup_location/

# delete database backup
# so no one can download it via the website
ssh $wordpress_server "rm $wordpress_location/db-$today.mysql.gz"

# done !

17 thoughts on “WordPress Auto-Backup via SSH

  1. untuk implementasinya apakah akan sulit mas? saya kurang tahu dan paham cara penerapannya gimana supaya bisa backup via SSH ini..

  2. Hello would you mind sharing which blog platform you’re working with? I’m looking to start my own blog in the near future but I’m having a hard time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S Apologies for getting off-topic but I had to ask!

Leave a Reply

Your email address will not be published. Required fields are marked *