Linux backup and restore filesystem –notes

A quick note on how to backup and restore (if necessary) the filesystem. We go to the root directory (/) and as root we run:

tar cvpzf backup.tgz --exclude=/lost+found --exclude=/backup.tgz /

c: create new archive
v: verbose
p: preserve permissions
z: gzip
f: use file (name of file=backup.tgz)

We exclude all the directories that we don’t want to back up (and especially the backup file itself!) and … run it!

In order to restore the system, we go again to the root directory and (as root) we run:

tar xvpfz backup.tgz -C /

WARNING: this will overwrite everything we have under your root directory (everything … means everything!).

-C: change to directory

After that, we re-create the excluded directories (like: mkdir lost+found) and we reboot our system!


Leave a Reply

Your email address will not be published. Required fields are marked *