en:linux:backup:tar

Draft Newest draft | Approver: psycore

This is an old revision of the document!


Linux backup with tar

How to make a backup of directories with tar? You can read about it in this tutorial.

Single directory structures can be backed up well with “tar”. You simply create an archive:

tar -cpvlf meinArchiv.tar /Pfad/zu/meinen/Originalen

An archive is now created with the following buttons:

  • -c : create/create
  • -p : permissions/get me the rights and owners
  • -v : verbose/show what is archived
  • -l : link?/do not follow links to other partitions
  • -f : file/it is a file, so in this case a file is created

The path to the archive can be absolute (/path/… ) or relative (./path/… or path/… ).

You can now compress the archive, e.g. with gzip:

gzip meinArchiv.tar

Before downloading the file, e.g. from a web server, you should calculate the md5 sum for verification. “md5sum” generates a unique number that changes if the downloaded file differs from the original.

The md5 sum of a file can be calculated as follows:

md5sum meinArchiv.tar.gz

After downloading “myArchive.tar.gz”, run the programme again on the target computer and you can compare the numbers.

You can also redirect the output of md5sum to a file and download it at the same time. This way you always have the total with the backup:

md5sum meinArchiv.tar > meinArchiv.md5sum.txt

Once the archive has been gzipped, it can be unpacked with:

tar -xzvf meinArchiv.tar.gz
  • -x : extract/extract
  • -z : zip/decompress
  • -v : verbose/display on the console what is being unpacked
  • -f : it is a file

If the archive has not been compressed, simply omit the z:

tar -xvf meinArchiv.tar

If you only want to restore individual files from the archive, enter them after the archive name:

tar -xvf meinArchiv.tar /Pfad/zu/meinen/Originalen/config.conf

You can look into an archive and unpack parts or all of it with MidnightCommander (mc).

Further help is available:

man tar
  • en/linux/backup/tar.1698175108.txt.gz
  • Last modified: 2023/10/24 21:18
  • by psycore