Linux backup with tar

Draft | Approver: psycore

Linux backup with tar

How to make a backup of directories with tar? You can find out in this tutorial.

Introduction

Individual directory structures can be easily backed up 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 owner
  • -v : verbose/show what is archived
  • -l : link?/do not follow links to other partitions
  • -f : file/it is a file, in this case a file is created

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

Zipping

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

gzip meinArchiv.tar

md5sum

Before you download the file from a web server, for example, you should calculate the md5 sum to check it. “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 figures.

The output of md5sum can also be redirected to a file and downloaded at the same time. This way you always have the total with the backup:

md5sum meinArchiv.tar > meinArchiv.md5sum.txt

Unpack

You can unpack the archive again after it has been gzipped with :

tar -xzvf meinArchiv.tar.gz
  • -x : extract/unzip
  • -z : zip/decompress
  • -v : verbose/print on the console what will be 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 use MidnightCommander (mc) to look into an archive and unpack parts or all of it.

Further help is available:

man tar
en/linux/backup/tar.txt · Last modified: 2023/11/10 00:41
CC Attribution-Noncommercial-Share Alike 4.0 International