rsnapshot Once Set, Can Automatically Incrementally Backup. rsnapshot is a Free Software intended to use on CLI for server backups. It is essentially a filesystem snapshot utility based on more older tool rsync. rsync takes snapshots of local and remote filesystems, and rotates the snapshots according to your settings. Here is How To Set Up rsnapshot For Backup Of WordPress on Cloud Server/VPS. We discussed about cheap cloud servers/VPS like VPSdime and Aruba cloud. Their cheaper cost make them excellent to use as backup servers. However, SSH needs to be secured with proper configaration of iptables and fail2ban. As they are accessible over public internet, the setup of second cheap server as backup server does have minimum matters of security. Our recommended way of keeping monthly backup is using some cloud storage which can be locked down as private. We can use free Dropbox for that purpose of backup or OpenStack Swift based object storage. However, that way is usually slower. In other words, we need multiple ways of backup and rsnapshot way not going to harm! You can also look at official Github repo of rsnapshot for documentations :
1 | https://github.com/rsnapshot |
How To Set Up rsnapshot For Backup Of WordPress on Cloud Server/VPS
Thankfully, rsnapshot
is available on repositories of commonly used server OS, so we can easily install rsnapshot on the server that you would like to use as your backup server with these kind of command :
1 2 | apt install rsnapshot yum install rsnapshot |
Now, cd
to /etc
and look if /etc/rsnapshot.conf.default
file exists. In that case simply :
---
1 | cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf |
If /etc/rsnapshot.conf.default
file does not exist, then create a backup of /etc/rsnapshot.conf
file :
1 | cp /etc/rsnapshot.conf /etc/rsnapshot.conf.default |
That is for future reference. You can always run configtest :
1 | rsnapshot configtest |
To backup another server, backup server will need to be able to connect through SSH. We need to generate SSH keys to authenticate, run this on backup server :
1 | sudo ssh-keygen -t rsa |
We will not use a passphrase for this key because we want these servers to auto-connect. Press ENTER through all of the prompts to accept the defaults. We now have a public and private key pair. We need to transfer our public key to the machine we will be backing :
1 | sudo ssh-copy-id -i /root/.ssh/id_rsa.pub root@IP-of-server-to-backup |
Now, test from backup server :
1 | sudo ssh root@IP-of-server-to-backup |
You should not face password prompt. Return back to backup server.
Now, open that configuration file :
1 | nano /etc/rsnapshot.conf |
Arch Linux has good documentation :
1 | https://wiki.archlinux.org/index.php/Rsnapshot |
Decide where you would like to store backups. Peoples usually use directory like /backup
as backup location. On settings, that will be the path :
1 | snapshot_root /backup/ |
Uncomment the cmd_ssh
line to allow for remote backup and cmd_du
lines :
1 2 | cmd_ssh/usr/bin/ssh cmd_du/usr/bin/du |
That cmd_du
enables accurate disk usage reports. Uncomment the ssh_args
section :
1 | ssh_args-p 25000 |
What directories to backup is written in this style :
1 | backup root@IP-of-server-to-backup:/etc/ example.com/ |
Backup interval part will be like this :
1 2 3 4 | retainhourly 6 retaindaily 7 retainweekly 4 retainmonthly 3 |
You can test :
1 2 | sudo rsnapshot configtest sudo rsnapshot -t hourly |
rsnapshot has all scripts, including cron :
1 | sudo nano /etc/cron.d/rsnapshot |
That will look after editing like this :
1 2 3 4 | 0 */4 * * * root /usr/bin/rsnapshot hourly 30 3 * * * root /usr/bin/rsnapshot daily 0 3 * * 1 root /usr/bin/rsnapshot weekly 30 2 1 * * root /usr/bin/rsnapshot monthly |
You can check disk space :
1 | rsnapshot du |
So, you understood that WordPress PHP files, images will be pulled to backup server. But what about MySQL? rsnapshot
has lot of scripts, and for MySQL, below is brief list of works to setup :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | apt-get install mysql-client cp /usr/share/doc/rsnapshot/examples/utils/backup_mysql.sh /usr/local/bin/ chown root.root /usr/local/bin/backup_mysql.sh chmod o-w /usr/local/bin/backup_mysql.sh nano /usr/local/bin/backup_mysql.sh # replace ## /usr/bin/mysqldump --all-databases > mysqldump_all_databases.sql # with ## /usr/bin/mysqldump --defaults-file=/etc/mysql/debian.cnf --all-databases > mysqldump_all_databases.sql # use below command to dump a single database : ## /usr/bin/mysqldump --defaults-file=/etc/mysql/debian.cnf DATABASE > DATABASE.SQL nano /etc/rsnapshot.conf # Under BACKUP POINTS / SCRIPTS add ## backup_script/usr/local/bin/backup_mysql.shlocalhost/mysqldump/ # test rsnapshot configtest |
rsnapshot is great tool. There are lot of scripts with huge documentation :
1 | https://github.com/rsnapshot/rsnapshot/tree/master/utils |