This article provides a quick solution to backup your website files and database.
First we create the directories that will be used to store the backups on the local server:
install rsync if it’s not already installed:
Create SSH key that will be used to login to the remote server. Execute:
Hit ENTER when you are asked where to save the key and to enter passphrase:
Copy the key to the remote server:
Now let’s create the directories on the remote server that will be used to store the backup files and databases:
Install rsync on the remote server if it’s not already installed:
We’ll be using bash script that will be executed from a cronjob everyday at 02:00.
Here it is:
Save it as backup.sh in your user home dir so the path will be /home/user/backup.sh or /root/backup.sh if you are using the root account.
Make it executable:
Create cronjob that will be executing the backup script everyday at 02:00:
Hit CTRL+X and then ENTER to save the new cronjob.
Now you have a solution that will keep backups of your files and database from the last 7 days on your local and remote server.
This may not be the best backup script but it’s OK for my needs.