TAR BACKUP SYSTEM – EXCLUDE SELF and VIRTUAL FILESYSTEMS

Since we want to backup all of the system recursively which starts at /

Syntax:

tar [options and archive savelocation] [archive start location] { --exclude="[exact name of file, or regex to match files]" }
[options and archive savelocation] can be something like this:
-zcvf [save location] – this makes a .tgz file or a .tar.gz file (tar first then gz compression)
zcvf [save location] – this makes a .tgz file or a .tar.gz file (tar first then gz compression)
-cvf [save location] – this makes a .tar file (no compression)
cvf [save location] – this makes a .tar file (no compression)

NOTE: that the – with the save and compress type options is optional (its for the single letter arguments that its optional – so dont miss the double dash on exclude)

[archive start location] is where the archiving will start, to grab the home folder just put /home, to grab one file just put /location/to/one/file/hello.txt, to grab the whole system just put /

{ –exclude=”[exact name of file, or regex to match files]” } I put this part in curly braces to signify that you can have any number of these exclude statements. The part within the parenthesis must match exactly to the file you dont want to save (if saving the whole system you should exclude the file that your archiving to – the [save location] file, also should exclude things like /proc and /sys and maybe /dev). So if you want to exclude a whole folder like /proc, you cant just type “/proc”, you have to match every file and subfolder so you have to type “/proc/*”

Examples to make a tar gz file:

# tar -zcvf /save/location/archive.tgz / --exclude="/save/location/archive.tgz"
# tar -zcvf /save/location/archive.tgz / --exclude="/save/location/archive.tgz" --exclude="/proc/*" --exclude="/sys/*"
# tar zcvf /save/location/archive.tgz / --exclude="/save/location/archive.tgz"
# tar zcvf /save/location/archive.tgz / --exclude="/save/location/archive.tgz" --exclude="/proc/*" --exclude="/sys/*"

Examples to make a tar file:

# tar -cvf /save/location/archive.tar / --exclude="/save/location/archive.tgz"
# tar -cvf /save/location/archive.tar / --exclude="/save/location/archive.tgz" --exclude="/proc/*" --exclude="/sys/*"
# tar cvf /save/location/archive.tar / --exclude="/save/location/archive.tgz"
# tar cvf /save/location/archive.tar / --exclude="/save/location/archive.tgz" --exclude="/proc/*" --exclude="/sys/*"

Extra Compression to tar file:
This Optional extra step if you used tar (not helpful if you used tar.gz because double compression isnt good)
If you went with the tar option, you can now use the better compression algo 7z.

# apt-get update
# apt-get install p7zip-full

The 7z command has the syntax that looks like this:
7z a [save location] [file names or folder names, can be a list of files, space seperated]

You can see more details just by typing “7z” and hitting enter and reading the short but helpful help message that comes up

# 7z a /save/location/archive.tar.7z /save/location/archive.tar

 

Leave a Reply

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