First - Get some sort off-server location that you can backup your stuff on a regular basis, I recommend ServerSync, they provide Raid-6 (2-drive redundant failure protection) with no transfer limit, and they're pretty cheap, 5$ a month for 20GB of storage or 10$ for 50GB (I'm doing the 50GB plan). Can be FTP'd, SSH, SCP, Rsync, etc.
Second - Prepare your remote location to receive the backup, for example, on mine I just simply created a folder called backup, followed by the server name, resulting in /home/kbeezie/backup/kbeezie.com/.
Third - create a bash script to backup your databases, followed by actually committing the rsync process. Make a file , say backup.sh
(repeat the mysqldump line for as many databases as you have)
we'll need to make sure the script can be executed so on the server after uploading it (preferably to your home folder, but not in a publicly accessible folder such as where your website files lie, since you'll have database passwords in the shell script)
We'll then want to setup a cron job, to perform this backup nightly, lets say 3AM based on the server time.
Then type in the following (if it pulls up vi, press 'i' to insert text, then ESC to get out of insert mode, then shift+zz to save and exit)
The last bit silences the output.
If you wish to manually execute the backup script you can do so by directly calling it.
If you wish to just run the rsync command and see progress as it runs, do the following.
example
On my personal VPS, I run an nginx webserver, no control panel, all my websites are store under /opt/html, my database backups get store under /opt/mysql_backup, so the above script would be something like this.
The first time it runs it'll transfer every file I have under /opt/html, every other time it runs, it'll only transfer files that have been changed (in which case the database backups will always transfer because they're new files with new dates, remove the date from the file name if you want the backups to overwrite the latest mysql backup in the same folder.)
if by some chance your mysql files are huge you can add this just above the rsync line of your bash script (which I may not have correct, so any like minded folks correct me if I'm wrong)
The above will compress all the mysql backups of the date originally dumped, then remove the original dumps leaving the tar gzip compressed file ready to be sync'd
PS: Anyone signing up for IonVz can have this done for them as a signup bonus (or as a regular part of managed support, so you have your own backup on top of the backup we already do).
The Serversync people are also very helpful if you have any questions about how to get something backed up, or the various ways to connect to your serversync account, including how to mount your remote storage as a drive on your system.
Second - Prepare your remote location to receive the backup, for example, on mine I just simply created a folder called backup, followed by the server name, resulting in /home/kbeezie/backup/kbeezie.com/.
Third - create a bash script to backup your databases, followed by actually committing the rsync process. Make a file , say backup.sh
(repeat the mysqldump line for as many databases as you have)
Code:
#!/bin/sh
date=`date '+%m-%d-%y'`
mysqldump -u database_username -pdatabase_password database_name > ~/mysql_backup/database_name.$date
rsync -e ssh -az /home/username/ username@serversync-ip:/home/username/backup/server-name/
we'll need to make sure the script can be executed so on the server after uploading it (preferably to your home folder, but not in a publicly accessible folder such as where your website files lie, since you'll have database passwords in the shell script)
Code:
chmod +x backup.sh
We'll then want to setup a cron job, to perform this backup nightly, lets say 3AM based on the server time.
Code:
crontab -e
Then type in the following (if it pulls up vi, press 'i' to insert text, then ESC to get out of insert mode, then shift+zz to save and exit)
Code:
0 3 * * * /path/to/backup.sh > /dev/null 2>&1
The last bit silences the output.
If you wish to manually execute the backup script you can do so by directly calling it.
Code:
/path/to/backup.sh
If you wish to just run the rsync command and see progress as it runs, do the following.
Code:
rsync -e ssh -avvz --progress /home/username/ username@serversync-ip:/home/username/backup/server-name/
example
On my personal VPS, I run an nginx webserver, no control panel, all my websites are store under /opt/html, my database backups get store under /opt/mysql_backup, so the above script would be something like this.
Code:
#!/bin/sh
date=`date '+%m-%d-%y'`
mysqldump -u database_username -pdatabase_password database_name > /opt/mysql_backup/database_name.$date
#times the number of extra mysql databases
rsync -e ssh -az /opt/html/ username@serversync-ip:/home/username/backup/server-name/
The first time it runs it'll transfer every file I have under /opt/html, every other time it runs, it'll only transfer files that have been changed (in which case the database backups will always transfer because they're new files with new dates, remove the date from the file name if you want the backups to overwrite the latest mysql backup in the same folder.)
if by some chance your mysql files are huge you can add this just above the rsync line of your bash script (which I may not have correct, so any like minded folks correct me if I'm wrong)
Code:
tar zcf /path/to/mysql_backup/mysql_$date.tar.gz /path/to/mysql_backup/*.$date
rm -Rf /path/to/mysql_backup/*.$date
The above will compress all the mysql backups of the date originally dumped, then remove the original dumps leaving the tar gzip compressed file ready to be sync'd
PS: Anyone signing up for IonVz can have this done for them as a signup bonus (or as a regular part of managed support, so you have your own backup on top of the backup we already do).
The Serversync people are also very helpful if you have any questions about how to get something backed up, or the various ways to connect to your serversync account, including how to mount your remote storage as a drive on your system.