Menu

Documentation about Backing-Up under Linux

Tux

At another page, I have described how I backup Windows machines. Under Windows, I prefer image backups because the integration between user data and the OS is tight, especially for user settings. Back-up under Windows is simplified by the fact that volume-shadow-copy technology is built-in, which means that you can back-up a running system.

When installing Debian Linux, I had decided to keep things simple and not use LVM (Logical Volume Manager). LVM offers similar functionality to Windows shadow copy. E.g. LVM allows to back-up a system while it is running.

When not using LVM, it may seem you have to boot the PC from an external medium in order to back-up, because only then you can be sure there are no files in an intermediate state (especially data bases).

However, when using the flexibility Linux offers, you can avoid that for the most part:

Hence I do two separate and different back-up processes:

  1. I run a file based back-up of /home as root, while the PC is booted normally, but only root is logged in
  2. To back up the other disk (=the system disk), I boot a live Debian-system from an USB-stick. Then I back-up the system-disk partition as an image back-up.

1. File-Based Back-up

I use the tar program for file backups, because

To make backing-up as easy as possible and to avoid manual errors, I developed a shell script, that automates the back-up process. You can download the script as part of the file ./tr-lnx-bckp.zip

Manifest

The file ./tr-lnx-bckp.zip contains the following files:

File Name Comment
readme.txt Text version of this web site
tr-tar-backup Shell script for file based backup using tar
tr-pcl-backup Shell script for image backup using partclone

Installation

Backup Process

Script tr-tar-backup Functionality

The script tr-tar-backup provides the following functionality:

Back-Up Scheme

The script tr-tar-backup implements a simple two set rotation scheme. A backup target disk shall have two target directories: A and B. The purpose is to always have two full back-ups available. The two sets rotate each month. In the same month, further back-ups are run as "differential" back-ups. The frequency of the differential back-ups is up to the (root) user, e.g. weekly, or daily, or when required.

The following graphics visualise this rotation scheme. Time runs from left to right. The blue bars symbolise the back-up data. The longer thicker bars stand for full back-ups, the thinner shorter bars stand for differential back-ups. Normally, differential back-ups will get bigger over the course of a month:

Monthly Back-up Scheme

Note that after two months, the first set gets deleted, such that only two months of back-ups are available at any point in time.

The scheme implemented by tr-tar-backup allows for a longer back-up history, when you add another back-up drive. This is visualised in the following graphics:

scheme-y.edraw.svg

A second drive with partition label MYBCKP02 gets only connected to the PC every six months. It will thus contain two full back-ups which reach up to one year back in time. Note that this drive will never contain differential back-ups because of the month logic in the tr-tar-backup script.

Of course you could connect a third drive to receive full back-ups. Such a drive could be stored safely at a different building.

2. Image Back-up

tr-tar-backup described in the previous section only backs up /home. The file ./tr-lnx-bckp contains another script tr-pcl-backup. It employs the partclone tool (Debian package partclone) to do an image back-up of the system-disk.

tr-pcl-backup needs to be started from a disk that is different from the system disk to be backed-up. The simplest method to achieve this is to temporarily connect a drive to the PC via USB and boot the PC from that drive.

For this purpose, I generated a small live Debian Linux system using the online tool https://fai-project.org/FAIme/live/. I stored the script file tr-pcl-backup on a separate "DATA" partition on the USB stick. The FAI tool offers to create such a partition. However, any live Linux system could be used to run tr-pcl-backup. The only requirement is, that partclone is already part of the live system or can be added without much effort.

The image back-up does not take long, because the system disk of my PC only uses about 25 GB. Hence I did not feel the need to implement a rotation scheme, i.e. tr-pcl-backup always creates a full image back-up.

tr-pcl-backup can also work with multiple back-up target drives.

Caveat: tr-pcl-backup currently supports only one PC to be backed up, because the PC's hostname is hardwired in the script. I will amend that in a future version of the script.

About tar

tar, whose name comes from "tape archive", is an old and proven utility. It is available for all Unix-like operating systems.

There seem to be two major tar variants:

Comparison of Functionality of the Two Variants

tar is mostly used to do backups. It used to be used to do backups on physical tapes. The functionality still reflects limitations of tapes. For example the tar "update" mode will write the updated file(s) to the end of the archive, while leaving the older information in the archive untouched. This is because "seeking" on a tape was slow and costly.

Incremental backups using "update" mode

To do incremental backups, you might consider using the "update" mode, to add new or updated files to the archive. This mode is supported by both BSD tar and GNU tar.

To restore, you would use the "extract" mode together with option -k "Keep (don't overwrite) existing files". However, this approach does not cater for files that were deleted in the source between the full backup and subsequent updates. Also files that were renamed would appear twice after extract:

  1. under their old name, and
  2. under their new name.

Similar for files that were moved: they appear

  1. at their old location, and
  2. at their new location.

Another drawback of "update" is the fact, that it works only on uncompressed archives. This is due to the fact that tar compresses after creating the archive and before writing to tape/file. The approach seems to be due to legacy constraints:

Incremental backups using the "listed-incremental" option

GNU tar has additional functionality for incremental backups. This is not available in BSD tar. GNU tar creates and maintains an additional file with meta data along side the archive file. The standard extension for this file is snar. Example syntax:

tar -czvg mybackup_full.snar -f mybackup_full.tgz dir-to-backup

The options

An additional option p ‑ to preserve meta data like access rights ‑ is only relevant for extract.

There is no mention of the "differential backup" strategy in the GNU tar documentation. However, the GNU tar manual (see section 5.) calls a full backup a "level 0" backup and the first incremental backup "level 1". The manual explicitly states that you might want to do more level 1 backups by creating a "working copy" of the snar file created at level 0. I tend to call this approach a differential backup. The approach would be:

cp mybackup_full.snar mybackup_diff-1.snar
tar -czvg mybackup_diff-1.snar -f mybackup_diff-1.tgz dir-to-backup

Extract from Incremental Backups

To restore or "extract" from incremental backups, the GNU tar manual stipulates to also use option --listed-incremental with =/dev/null as argument (it could be any argument). So with just a full and a level 1 backup:

tar -xzpf mybackup_full.tgz
tar -xzpg /dev/null -f mybackup_diff-1.tgz

The following alternative also works:

tar --incremental -xzpf mybackup_diff-1.tgz

To list what is going on, you might do:

tar --incremental -tvvzpf mybackup_diff-1.tgz

Caveats

tar stores "device numbers" in the snapshot file and also uses these to check if a file has changed since the last backup. You might want to use --no-check-device option to avoid a full backup if device numbers change for some reason. There is a tar-snapshot-edit (tar-edit-snapshot ?) utility to deal with such snapshot file issues.

References

  1. https://unix.stackexchange.com/questions/13093/how-to-add-update-a-file-to-an-existing-tar-gz-archive
  2. Introduction to the tar command line syntax https://www.computernetworkingnotes.com/linux-tutorials/tar-command-examples-in-linux.html
  3. Introduction to the syntax of incremental backups https://www.computernetworkingnotes.com/linux-tutorials/create-and-restore-incremental-backups-in-linux-with-tar.html
  4. Explains level 1 (=differential) and multi-level backups http://paulwhippconsulting.com/blog/using-tar-for-full-and-incremental-backups/
  5. The tar manual https://www.gnu.org/savannah-checkouts/gnu/tar/manual/tar.html#Backups
  6. Also explains why to copy the snar file https://etutorials.org/Linux+systems/how+linux+works/Chapter+13+Backups/13.4+Using+tar+for+Backups+and+Restores/
  7. Difference between --listed-incremental and --newer https://unix.stackexchange.com/questions/307530/what-is-the-difference-between-tars-newer-and-listed-incremental-options
  8. More details on incremental backups https://floatingoctothorpe.uk/2018/incremental-tar-backups.html
  9. Torture-testing Unix Backup and Archive Programs https://web.archive.org/web/20010622155048id_/http://reality.sgi.com/zwicky_neu/testdump.doc.html

Last change: 2026-03-14
© 2002-2026 Dr. Thomas Redelberger redetho(a‍t)gmx.de

Close menu