Servers

Linux Server Backups + [Two Popular Linux Backup Utilities You Can Use Right Away!]

Linux server backups

In the event of a disaster, the first priority is to bring the website and business apps back online. The idea is to minimize the loss of revenue and reputation caused by the non-availability of the website.

That’s why you need a simple backup process in place so that the data on your servers is regularly saved at a secure location.

This article introduces the importance of Linux server backups and then goes into the details of how you can back up your data using the popular Linux utilities.

But first, let’s start with an overview of the idea of server backup.

The Idea of Linux Server Backup

As a system administrator, backing up your Linux server(s) is one of the regular tasks on your management checklist.

The idea behind Linux server backup is to protect the hosted websites and applications from data loss. Backing up servers, especially mission-critical servers, is essential to the more extensive disaster recovery process. Given the importance of server backups, it’s no surprise that you can find several types of backup methods, including full backup, incremental backup, and differential backup.

But before going into the details of these backup types, it’s important to understand why we need to back up servers.

Why Should You Back Up Your Servers?

Everyone who’s ever worked with a hosted website knows that regularly backing up server data is essential to get it back online after a disaster.

Many people assume that data loss can only occur when a server comes under attack. While that’s true, hardware failures are an equally important factor in data loss. That’s why server backups are essential to maintaining server and application health.

Server backups also become important when you’re testing new software components. In some cases, when a software component fails, you might end up losing all the data on the server. That’s when you can quickly restore the data from a backup and get back to testing with minimum delays.

You should also know that Linux server backup is not a haphazard process. You need a well-coordinated strategy to get the most out of the server backup process.

Introducing the 3-2-1 Linux Server Backup Strategy

For laypeople, backing up server data involves making multiple copies of data. However, this uncoordinated effort doesn’t help because it often results in multiple versions of server data without any systematic approach to taking backups or saving the archives.

In contrast, we highly recommend the 3-2-1 strategy that brings order to your server backup processes.
Here’s a brief explanation of the idea:

3 indicates that you need a primary backup archive and two additional copies of the data.

2 indicates that you should keep the three archives in two different media. This enhances the element of redundancy.

1 indicates that you should keep at least one of the three archives at an offsite location. This generally means a different location from the server you are backing up.

The 3-2-1 strategy is an excellent way of setting up redundancy in server backup. It ensures that you always have access to a backup archive, regardless of the severity of the incident.

Linux Server Backup Process Types

Now that you know the theoretical background of the idea of backing up server data, it’s appropriate to discuss the three popular ways of server backup.

Full Backup

A full backup is a complete copy of all data saved to a backup server. The archive contains all the server’s files, directories, and system state information. It is typically performed weekly or monthly (depending upon the frequency of data updates). This is the best option to restore server data to its original state in case of complete loss of the server data. However, the downside of the process is that taking full backup needs a lot of time and requires a lot of storage space.

Incremental Backup

Incremental backup is a strategy that only copies files that have changed since the last backup. Many sysadmins typically take incremental backups once a day.

This method usually results in a small archive because it contains just the changes made to server files in the previous 24 hours.

The advantage of incremental backup is that it is faster and requires less storage space than a full backup. However, incremental backups are often unable to restore server data completely. As a result, in the event of complete data loss or corruption, incremental backups must be combined with the most recent full backup to restore the server to a previous normal state.

Differential Backup

A differential backup falls somewhere between a full backup and an incremental backup.

In this backup method, the process copies all files that have changed since the last full backup. Sysadmins generally take a differential backup daily or weekly depending upon the frequency of data updates and the importance of data). The archive contains the differences between the current state of the data and the previous full backup.

Unlike incremental backups, differential backups include all changes made to the data since the last full backup, not just the changes since the last backup of any type. This often results in a larger archive size than an incremental backup. In the event of data loss or corruption, you must combine a differential backup with the most recent full backup to restore the system to the previous state.

How to Take a Linux Server Backup

As discussed earlier, we need both a strategy and an optimized process for managing the backups for a Linux server.

We have discussed the strategy part in detail earlier in this article. So let’s discuss the requirements of the backup process.

First and most importantly, choose what type of data you need to back up. This is critical because the choice affects both the backup frequency and the storage requirements for the backup archives.

Secondly, choose the backup type you want to create. While a full backup is the first choice, you should consider a combination of incremental or differential backups and a full server backup.

A related decision is when you would initiate the backup process. This is very important because when the backup process runs, it consumes server resources. This could potentially slow down server response.

Next, you must choose the tools you wish to use for the process execution. You can choose from several utilities, including rsync and tar. We will discuss both of these tools in the next section.

While you’re there, you should also select the location where you would store the backup.

These decisions help streamline the backup process.

The Popular Utilities for Taking Linux Server Backup

Linux offers several utilities for backing up your data. We’ll discuss two popular options to help you pick the right tool for backing up your data.

The rsync Utility

Rsync (the full form is remote sync) is a well-known backup utility tool that syncs files remotely from one location to another.

This utility has become popular because of the seamless sync process and simple syntax. This allows sysadmins of all skill levels to use the tool for setting up server backup.

Here’s what the syntax looks like:

# rsync [OPTIONS] source destination

The real power of the rsync tool lies in the versatile options. Here are the most commonly used options:

‘-a’ (archive) conserves the file attributes and re-creates the directory structure.

‘-h’ (human-readable) is used to format the output in a human-readable format.
‘-z’ (compress) compresses the data or files while transferring data to the destination.
‘-v’ (verbose) outputs all the process details.

Why Should You Consider the rsync Utility?

Here are a couple of reasons why you should consider using the rsync utility

  1. rsync simplifies the process of connecting and transferring data from the local to remote systems.
  2. During the transfer process, rsync manages file compression, which greatly helps with bandwidth consumption.
  3. rsync is great from the server performance perspective because it consumes fewer resources than other options, such as the ” cp” or “scp” command.

An Overview of Linux Server Backup With rsync

Let’s overview how you can use rsync to transfer data backup from a remote server to a local server.

You are already familiar with the basic syntax.

Here, the source is your remote server, and the destination is your local server.

Before setting up the transfer, you must ensure that rsync is available on the server. If not, use the following command to install it:

# yum install rsync

After installing rsync in the Linux server, you must generate an SSH key that will be used to authenticate the connection between the two systems (whether the local machine or a remote server).

Use the following command to generate the SSH key.

# ssh-keygen -t rsa -b 4096 -f ~/.ssh/ssh_rsync.key

If you see a prompt, leave it blank and press the “Enter” key twice.

In the ~/.ssh folder, you can now see two new files.

The first is the ssh_rsync.key (containing the private key), and the second file is ssh_rsync.key.pub (containing the public key).

The next step is setting up a remote server to store our backup. For that, you must add a user. For this, login into the server using SSH and add a new user with the following command:

#useradd -m ssh_rsync

Next, you must authenticate your local system. For this, first, go to the /.ssh_rsync directory, open the public key within /.ssh_rsync.key.pub, and copy all the file content.

At this point, we’re done with the local system. Now, we’ll move to the remote server.

Follow these steps:

  1. Switch to user rsync_ssh
  2. Change ownership of a backup_file
  3. Copy ssh_key into the authentication file
  4. Change ownership of the file

First, at the remote server, run the following commands to configure the backup

#sudo su ssh_rsync

#mkdir -m 0700 $HOME/.ssh

#echo "ssh-rsa AAAAB... user@host" > $HOME/.ssh/key_authenticated

#chmod 0644 $HOME/.ssh/key_authenticated

When the commands finish, the local server will be authenticated with the remote server.

Next, you need to configure the SSH file (generally located in the ~/.ssh/config folder). Use the following command to open the file in Vim.

#vim $HOME/.ssh/config

In this file, add the following line:

hostname remote- server_ip

user ssh_rsync

IdentityFile ~/.ssh/ssh_rsync.key

Now, finally, you need to sync the files on both destinations. To sync the source and destination directories, run the following command on your local server

#rsync -avz --progress ~/Documents/ backup_server:~/Documents

Now it is time to reduce your effort for the backup and use cron for the backup.

Start by creating a cron job with the following command. This command will sync the files of both the local and remote servers. Also, note that the cron job runs every 30 minutes. You can adjust this time to your preferences.

#(crontab -l; echo "*/30 * * * * rsync -avz --progress ~/Documents/ backup_server:~/Documents > /dev/null 2>&1";) | crontab

Next, make sure the cron is set correctly with the following command:

#crontab -l

The tar Utility

Tar (short for tape archive) is a very useful Linux utility that compresses a large file into a small one.

Let’s see how tar works:

Start by creating a folder with the mkdir command.

#mkdir directory_name

Next, use the following command to compress that directory.

#tar -cvfz directory_name.tar.gz destination_path

Next, let’s see how to use the tar utility for server backup.

Use tar for Linux Server Backup.

Now we will take a remote server backup and store it on the local server.

For this activity, we need ssh and root access to the servers. Here’s how you can use the SSH command:

#ssh [email protected] "tar -czvf - /path/to/backup/dir" > backup.tar.gz

Here,

-c” instructs tar to create a new archive,

-z” indicates that tar should compress the archive using the gzip utility,

-v” indicates that the tar command should output verbose information during the backup process,

Note that you might be asked to enter a password and an authentication key.

Other Options for Linux Server Backup

We have already covered two great utilities for backing up Linux servers. While these utilities are the most commonly used, there are other options. We’ll now mention two more utilities you can consider.

  1. rsnapshot

As the name indicates, this utility is related to the rsync utility. It is great for generating incremental backups of files, directories, and databases. It stores multiple copies of the data.

  1. Windows Backup

Created by Microsoft, this utility takes a backup of your files, folder, and database. It is so flexible that you can take incremental backups, compress and encrypt archives. It also works great with external drives.

Conclusion

Backup is a critical aspect of managing Linux servers. You need a regular backup process to make sure you can quickly recover from an incident and get your server back online. We mentioned two popular backup utilities to back up your server data.

You should come up with a solid backup plan that covers all important aspects of the backup process, including the time when the backup process would run, the location where the backup archive would be stored, and how you would implement the 3-2-1 strategy.

FAQ

Why is it important to back up a Linux server?

Backing up a Linux server is important because, in case of data loss, corruption, or any other disaster, you can easily restore your data and bring your server back into business.

How often should I back up my Linux server?

The frequency of backups depends on the amount of data you have and how often it changes. Generally, you should perform full backups at least once a week, incremental backups daily, and differential backups once daily or every few days.

How do I test my Linux server backups?

You can test your Linux server backups by performing a restore to a separate test environment. This will help you verify that your backups are working correctly and that you can recover your data in case of an emergency.

What should I do in case of a backup failure?

In case of a backup failure, you should immediately investigate the cause of the failure and attempt to rectify the issue. If necessary, you may need to back up your data until the issue is resolved manually.

Prem

Prem Patil is a full-time Linux System Administrator at RedSwitches. He is an engineer who has customer satisfaction as his priority. He provides solutions for clients via tickets and calls. He loves to read books and write poetry. Reach out to him at [email protected].

Related articles

Latest articles