Creating a .tar.gz Backup on Linux
Very useful commmand to make a .tar.gz compressed backup of important directories.
tar stands for tape archive which can be used to turn many files and directories into a single file, great for backup and storage.
The syntax:
tar [-options] /directory/of/new/file.tar /files/to/backup/*
So, in this example, we want to backup /var/www to /var/backup.tar.gz (.gz are further compressed).
We would use this command:
tar -pczf /var/backup.tar.gz /var/www/*
What the options mean:
-f = read to/from the named file (instead of the device /tape) -t = list contents of .tar file -p = maintain permissions (users/groups) -r = append to a .tar file -v = verbose (tells you everything its doing) -x = extract contents of .tar file -z = compress files (not so useful for minc files)
Then, if we wanted to extract the backup.
tar -zxvf backup.tar.gz
Hope this helps, very useful command.
Especially if you can run it on a cronjob.
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
No comments yet.
Leave a comment