Create incremental backup in linux using tar
Last Updated :
02 Jun, 2022
As a system administrator, it’s a regular task to backup the data. There are two types of backup, incremental and full backup. In the full backup, the user needs to back up all the data every time. But in incremental backup, the user takes a backup of data that has been modified or newly added since the last backup.
How does incremental backup work?
Incremental backup works based on the file’s modification time. If the file has not been modified since the last backup, it would be skipped while taking the incremental backup. On the other hand, if the file has been modified and the date is more recent than the last backup date, the file would be backed up.
In this article, we will see how to create and restore the incremental backup in Linux using the tar command.
Create files
First, we will create a data folder with some files for taking backup,
Create full backup
In order to create an incremental backup, the user needs to take a full backup initially. It is also called Level0 incremental backup which is the copy of all source files.
tar -cvf level0.tar -g data.snar data
We will use the following arguments,
* data take backup of this directory
* level0.tar name of the backup file
* data.snr create snapshot of data directory
Create incremental backup
Before creating an incremental backup, we will create, update and delete files under the data directory,
Next, we will run the following command to create an incremental backup which is called Level1 incremental backup where we could see the file which is newly added and whose content got changed alone backed up.
Thus, we have created one full backup and one incremental backup. Next, we will see how to restore an incremental backup and the command to list the files present in it.
Restore incremental backup
We will first delete the data directory before restoring it,
rm -rf /root/data
Next, we will restore data from the full backup file which is the source of all files,
The following command lists the files present in a full backup,
tar –list –incremental –verbose –verbose –file level0.tar
In the below output, Y indicates that the file is present in the backup.
Now, we will restore from an incremental backup file,
To list the files present in incremental backup,
tar –list –incremental –verbose –verbose –file level1.tar
In the below output, N indicates the file is not present and Y indicates the file is present in the backup.
We will see the following files in the /root/data directory once the incremental backup is restored,
Full Vs Incremental Vs Differential Backup
Type
|
Pros
|
Cons
|
Full |
- Provides a full copy of data
- Best protection
|
- Consume more time to take backup
- Needs a lot of storage space.
|
Incremental |
- Take less time to backup than a full backup.
- Less storage space.
|
- Time-consuming to restore the files
- All the backups are needed to restore the entire file system.
|
Differential |
- Short restore time than incremental
|
- Can grow to a bigger size than incremental
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...