Simple Backup and Restore of a complete Linux system



# Create a full backup of the Linux system

tar -cvpznf /backup/backup.tgz -g /backup/ --exclude=/backup/backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/media --exclude=/sys / 

#tar cvpzf /backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/media --exclude=/sys /


WARNING!! This will overwrite every single file on your partition with the one in the backup archive!

To complete the restore the directories that we excluded in the above backup command using the “exclude” flag will be created afterwrads:

tar xvpfz /backup.tgz -C /

mkdir /proc
mkdir /lost+found
mkdir /mnt
mkdir /media
mkdir /sys

By using the “tar” command to backup your data, you have the ability to extract any file or directory out of the “backup.tgz” file for recovery, for instance, if you have a corrupt or mis-configured file called “file” in the directory “/directory” you want to recover, you could simply issue the command:

tar -zxvpf /backup.tgz /directory/file