This article describes the various backup options for Flex Dedicated Server and VPS packages.
The following table summarizes the backup options available for managed and unmanaged VPS and dedicated servers:
|VPS||Automatic backups (files only)||Manual backups|
|Flex Dedicated||Copias de seguridad CDP R1Soft||R1Soft CDP Backups / Manual backups|
Managed VPS customers can use the Server Rewind feature in cPanel to restore server backups. However, Server Rewind only restores files. It does not restore databases, so you must set up your own database backups. For information about how to do this, please see this article.
For Flex Dedicated Server customers, A2 Hosting offers R1Soft CDP (Continuous Data Protection) Backups for an additional fee. R1Soft CDP Backups provide daily backups for the last seven days, and a weekly backup for the last four weeks, for a total of one month of backups. For more information about R1Soft, please see this article.
Unmanaged VPS and Flex Dedicated Server customers are responsible for configuring their own backups. For information about how to do this, read the procedures below.
If you have an unmanaged Flex Dedicated Server or VPS, you are responsible for setting up your own backups. (However, managed VPS and Flex Dedicated Server customers can also configure their own manual backups for extra protection.)
To configure your own backups, use the following procedures.
The first step is to create a Bash script that generates backups of your files. To do this, follow these steps:
Create a file named backup-cron.sh in the backup directory. For example, type the following command:
Add the following code to the backup-cron.sh file. Replace username with your own username, and replace target with the path to the directory that you want to back up:
#!/bin/bash destination_folder=/home/username/backup/`date +%F` archive_file="backup-`date +%H%M`.tar.gz" mkdir -p $destination_folder /bin/tar -czvf $destination_folder/$archive_file /target --exclude='/home/username/backup'
To make the backup-cron.sh file executable, type the following command. Replace username with your own username:
chmod +x /home/username/backup/backup-cron.sh
The Bash script is now ready to run and can be called from a cron job. To set up the cron job, proceed to Step 2: Set up a cron job to run the bash script automatically .
The script in the previous procedure creates compressed backup files on the VPS or dedicated server itself. However, you can also transfer backups to a remote server by using the rsync program.
To set up remote backups, follow these steps:
Create a file named backup-remote.sh in the backup directory. For example, type the following command:
Add the following code to the backup-remote.sh file. Replace username with your own username on the VPS or dedicated server, and replace example.com with the domain name of the VPS or dedicated server. Replace target with the name of the directory that you want to back up:
#!/bin/bash destination_folder=/backup/`date +%F` mkdir -p $destination_folder rsync -e 'ssh -p 7822' -avl --delete --stats --progress firstname.lastname@example.org:/target $destination_folder/
To make the backup-remote.sh file executable, type the following command:
chmod +x /backup/backup-cron.sh
Using cron jobs to automate backups makes your life as a system administrator easier. You don't have to worry about remembering to run a backup script at a certain time. If you have a managed VPS or dedicated server with cPanel support, creating cron jobs is very easy. If you do not have cPanel access, you can set up cron jobs from the command line.
To set up a cron job in cPanel, all you need to do is specify the backup interval (for example, weekly, monthly, etc.) and the command to run. For example, to run the Bash backup script you created above, use the following command. Replace username with your own username:
For detailed information about how to set up a cron job using cPanel, please see this article.
If you have an unmanaged VPS or dedicated server, you can set up cron jobs using the command line. To do this, follow these steps:
Add the following lines to the cron configuration:
# Run backup at 23:50hrs every day 50 23 * * * /bin/sh /home/username/backup/backup-cron.sh
To receive an e-mail message every time cron runs a script, add the following line to the cron configuration file. Replace [email protected] with your own e-mail address:
To save your changes and exit the editor, press Esc, type :wq and then press Enter. You see the following message:
crontab: installing new crontab
To view the cron configuration file without editing it, type the following command:
If you are using MySQL, you can back up databases using the mysqldump command. You can automate this process by running the mysqldump command (or a script that calls it) from a cron job.
The following sample Bash script shows one possible implementation:
#!/bin/bash db_name=dbname db_user=dbusername db_password='dbpassword' backup_filename=$db_name-`date +%F` mysqldump -h localhost -u $db_user -p$db_password $db_name | gzip > /home/username/dbbackup/$backup_filename.sql.gz
This script creates a compressed backup of database dbname in the /home/username/dbbackup directory. The backup filename is composed of the name of the database being backed up, and the current date.
For detailed information about how to create MySQL database backups, please see this article.
For more information about how to set up cron job intervals, please visit http://en.wikipedia.org/wiki/Cron.