How to Set Up Automated Backups for a Dedicated Server
Photo by Forian Krumm on Unsplash
Having a dedicated server for your website needs is a great way to increase your resources and production. However, you’ll also need to set up backups for your dedicated servers. Without an automated backup system, your data is at risk of being lost or modified. There are a few different ways you can set up and manage your dedicated server backup, depending on what your technical comfort level is and the type of backup you wish to pursue.
Data Backup Explained
Data backup is a way to protect your company and website from hacking and unintended losses. Technology is evolving every day, but there are still hiccups in any online system. Servers can experience power outages or fires or can be hacked by knowledgeable infiltrators. By backing up your data, you can restore your website and information. As long as you back up your dedicated server frequently, you won’t have to make up much if something goes wrong.
Backup Storage vs. Backup Server
A backup server is another way you can protect your website and data without backing up your server. Backup servers are entirely separate dedicated servers that can be activated in case of an emergency. These servers host the same data as your main servers and can keep your website running and your data safe if something happens to your main servers. A dedicated server backup, however, won’t keep your website up and will require fixes to be made before your online services are up again.
Backup Storage Activation
Before you can start relying on your backup for dedicated servers, you have to activate it. Whatever your chosen method is, you’ll need to go into your server and management software to set it up. Manual backups require this step every time. An automated backup, however, only needs the initial activation. It will then run continuously as you dictate, so you don’t have to worry about it unless you want to change the settings.
Accessing your backup data depends on the method chosen to create it. Most of the time, you can access your dedicated server’s backup by logging into your WHM or cPanel and navigating to the backup menu. Third-party backup software and cloud backups will have their own website or software you’ll need to use to locate and access your backup.
Modifying and Deleting Backups
Your backup data can be modified or deleted from your chosen server backup software. Logging in will give you access to your list of backups. It’s a good idea to keep a handful of backups at any one time in case one backup isn’t fully functional. You can delete old backups to free up storage space for new backups as time goes on.
Backup Drive for Dedicated Server
Although there are cloud options available, having a physical dedicated backup drive is the best way to protect your data. When setting up your dedicated server, you’ll need a main disk drive that can hold the operating system and data for the everyday usage of your server. At the same time you’re setting this up, you should also set up a secondary physical drive that has the same capacity as your main drive if not larger. When configuring your automatic backups with this two-drive system, you can send the data to your backup drive as well. This way, if your server fails or there’s a malfunction with your main drive, you have everything you need on your separate backup drive and can restore your site with minimal time and energy.
Disk Space Options
Most backup services will have an allocated disk space you can use to store your backups. Many times, this space is enough to hold a few restorations at a time. If you feel that you need to keep track of more saves, you may need to purchase more disk space. Contact your backup service provider and see what options are available. You’ll be able to upgrade to a higher account and store more backups for your dedicated server.
Dedicated Server Backup Options
There are several different methods you can utilize to back up your dedicated server. Which you choose to use will depend on how your dedicated server is set up and your level of comfort with computers and scripting/coding.
Method #1: cPanel Backup
cPanel backups are the easiest to set up and control. If your dedicated server is managed through a cPanel account, it’s recommended you use the cPanel for configuring your automatic backups.
Log into your cPanel account. Your login information should have been emailed to you when you first set up your dedicated server.
On the home screen, navigate to the Files section and click on the Backup option.
Find the Full Backup area and click on the Download a Full Account Backup option.
Once you have done this, you’ll see a Generate a Full Backup area. Find the Backup Destination list box and select the location you would like to save your backup to.
Backups can be saved on your home directory. You can also transfer them to another site using FTP or SCP. However, you will need to have the remote server address, username, and password to do so.
Emails confirming when a backup is complete are sent by default. However, when activating your backup, you can check the Do Not Send Email Notification of Backup Completion to avoid these.
Once your settings are in order, click on Generate Backup. cPanel will begin automatically backing up your dedicated server.
To generate automatic backups, navigate to the Scheduling and Retention settings. Here you will be able to configure daily, weekly, or monthly backups. You will be able to choose how many backup versions you’d like stored on your account. You can run multiple types of automatic backups at the same time (such as a daily and a monthly).
Method #2: JetBackup
You can use JetBackup, a third-party server backup program, through your WHM settings to create automatic backups. JetBackup is easy to use and is a good mid-level option for those who have some computer know-how but don’t want to (or can’t) use cPanel for their server backups. JetBackup can be bought as an add-on for your hosting service with HostForWeb, in which case the initial configuration settings will already be set. You can still change or alter the backup settings as needed.
Log into your WHM.
Navigate to the JetBackup section and select Backup Jobs.
Click on Create New Backup Job.
Configure the settings to determine the structure of your backups. With JetBackup, you can structure your backups in the following ways:
Incremental – Only back up the data that is new or changed since the last backup.
Archived – Create an uncompressed archive backup. These are faster to generate but will take up more of your disk space.
Compressed – Create a compressed archive backup. These take up less disk space but require more time to generate.
To restore any version of your server, you can log into your cPanel account and navigate to the JetBackup menu. Here you can see the restoration points available to use.
Photo by Markus Spiske on Unsplash
Method #3: Bash Script and Cron Job Backup
Creating a Bash script will allow you to have more control over your backups. This method requires a certain level of scripting and coding and is generally only recommended for those experienced with this knowledge.
Creating a Bash Script
Log in to your dedicated server’s account with SSH.
Type the following command to create a directory where your backup files will be stored (replace ‘username’ with your username)
You can change the name of the directory by replacing ‘backup’ with what you would like to name it in the following steps.
Next, you’ll need to create a file in the directory backup. You can use any text editor you’d like to create and edit this file. You can create the file by typing in a command as such
Place the following code into your file.
backup_files="/home /var/spool/mail /etc /root /boot /opt"
echo "Backing up $backup_files to $dest/$archive_file"
tar czf $dest/$archive_file $backup_files
echo "Backup finished"
ls -lh $dest
There are variables of the code you’ll need to configure yourself to make sure it works properly. Make sure you configure the following variables as you need.
$backup_files: The directories you would like to backup.
$day: The day of the week you would like to create an archive file.
$hostname: The short hostname of the system.
$archive_file: The full archive filename.
$dest: The destination of the archive file.
Save the file and close your text editor.
Before you’re finished, you need to make the file executable. To do so, type the following command (replace ‘username’ with your username)
[Copychmod +x /home/username/backup/backup-cron.sh]
Now that your Bash script is up and ready to run, you need to call it from a cron job.
Setting up a Cron Job Backup
Method #1 – cPanel
If your dedicated server runs through cPanel support, you can use this to set up your cron job backups.
Log in to your cPanel account.
Navigate to the advanced settings on your home screen and click Cron Jobs.
Cron Jobs will send an email to your entered address whenever the backup is run.
Under the Add New Cron Job option, indicate the interval you’d like between running the command.
Type the required command into the Command Text Box. For the Bash script already created, run the following command (replace ‘username’ with your username)
Confirm your settings and click Add New Cron Job.
Method #2 – Command Line
If your dedicated server does not have cPanel support, you can use the command line to set up your cron job backups.
Log in to your account with SSH.
Type the following command to gain access to the cron configuration file
Type i to enter insert mode.
Add the following lines of code to the cron configuration
[# Run backup at 23:50hrs every day
50 23 * * * /bin/sh/home/username/backup/backup-cron.sh
Modify the time and date interval as you would like.
If you would like to receive an email confirmation every time cron runs your script, include the following line of code as well (replace email@example.com with your email)
Close the editor and press Esc. Then type :wq and press enter.
If you see [crontab: installing new crontab], your work has been saved, and your cron job backup is ready to go.
You can quickly view the cron configuration file by typing the following command
FAQ for Dedicated Server Backups
How often should I back up my dedicated server?
How often you back your dedicated server up will depend on the number of changes your server undergoes. If your server doesn’t update regularly and is mainly for static pages, you won’t need a backup as often. Frequently updated servers, however, should get regular backups weekly or even daily. No matter the type of sites your server hosts, you should aim to make a backup monthly at least to secure any data changes.
How does server backup work?
A server backup takes the information on your dedicated server and saves a copy of the information on an external drive or in a cloud system. You can then use the data files on these storages to restore your system should anything happen. All the information your dedicated server stored will be stored on your backup system. This way, nothing is permanently lost or damaged.
What are the types of dedicated server backup?
You can back up your dedicated server in a number of ways. cPanel lets you quickly and easily set up your server backups and access them at any time. You can also use a third-party backup system such as JetBackup. For those who want additional control and have some background coding and scripting knowledge, Bash scripts can be utilized with cron jobs to configure your dedicated server backups.
Is it safe to back up data on a dedicated server?
Not only is it safe to back up data on a dedicated server, it’s required for safety. If you’re worried about your data being online or in an area other than your server, you can use a dedicated hard drive to store your backups. Without any backups at all, your dedicated server could suffer a malfunction or be targeted by malware, leaving you with lost data and information. Keeping your dedicated server backed up is the only way to ensure safety and security.