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
|
Similar Reads
How to Create a File in the Linux Using the Terminal? In this article, we will learn to create a file in the Linux/Unix system using the terminal. In the Linux/Unix system, there are the following ways available to creating files. Using the touch commandUsing the cat commandUsing redirection operatorUsing the echo commandUsing the heredocUsing the dd c
4 min read
rdiff-backup Command in Linux with Examples rdiff-backup is a command in Linux that is used to backup files over server or local machine and even has a feature of incremental backup which means it only contains those files that have been modified or changed. Its source code is written in python and hence it needs a python interpreter to funct
2 min read
How to Compress and Extract Files Using the tar Command on Linux Tar archives are special files that bundle multiple files and directories into a single file, making it easier to store, share, and manage. While tar archives themselves are not compressed, they can be combined with various compression utilities to reduce their size. The tar command is highly versat
3 min read
Most Popular Backup Tools in Linux Backup in Linux is important for preserving data integrity, ensuring disaster recovery, and safeguarding against data loss due to system failures or human errors. Various backup tools are available in Linux, offering features like incremental backups, encryption, compression, and scheduling to meet
9 min read
install command in Linux with examples The 'install' command in Linux is a versatile tool used for copying files and setting their attributes, such as permissions, ownership, and group. Unlike commands like 'cp' that simply copy files, 'install' allows you to fine-tune these settings, making it ideal for installation scripts or manual fi
3 min read