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.
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.
Not using LVM has the consequence that I need to boot the PC from an external medium in order to back-up the system, because only then you can be sure that there are no files/data bases, that are in an intermediate state.
However, I used the flexibility Linux offers in the following way:
sudo, because root's home directory is /root and this directory is not part of the /home directory/home directory/home on a separate disk partition
/home read-only before back-up to make sure that no write access takes place while back-up is running/home is quite large, I put it on a separate hard disk driveHence I do two different back-op processes:
/home as root, while the PC is booted normally, but only root is logged in
For 1. I adopted tar for file backups, because it
For 2. I generated a live Debian Linux system using https://fai-project.org/FAIme/live/ and use the partclone tool (Debian package partclone) to do an image back-up of the system-disk.
This image back-up does not take long, because the system disk only uses about 25 GB.
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:
tar. This is available on most Linux systems. However, there is also a port available for Windows. For example, I got GNU tar version 1.30 from 2017 as part of git for Windows.tar. This is available on systems like FreeBSD, but is also standard on Mac OS. Since Windows 10 1903, it is also part of the standard Windows command line tools (it had been introduced the same time as curl)
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.
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:
Similar for files that were moved: they appear
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:
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
c stands for "create"z for gzip compressionv for verbose messagesg is short hand for --listed-incremental.
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 on-line 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
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
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.
tar manual
https://www.gnu.org/savannah-checkouts/gnu/tar/manual/tar.html#Backupssnar file
https://etutorials.org/Linux+systems/how+linux+works/Chapter+13+Backups/13.4+Using+tar+for+Backups+and+Restores/--listed-incremental and --newer
https://unix.stackexchange.com/questions/307530/what-is-the-difference-between-tars-newer-and-listed-incremental-options