CodeSpud

Linux: Snippet – Backup using Tar and gzip

December 07, 2008

linuxscriptbash

As a programmer i have to make multiple revisions of a project on a remote site. Getting things wrong and messing up the files tend to happen more often than I am comfortable with. Fortunately, making quick backups in linux is a breeze. You can either make a folder and just copy your existing files via recursive cp command or; archive it using tar and gzip. Personally, I prefer archives since they tend to be smaller and easy to manage.

Install tar and gzip
You can be hardcore and download the source for tar and gzip and recompile them.
 
Or you can use apt-get or yum(Yellow dog Updater, Modified ? — weird name ) to do it for you.
yum install tar
yum install gzip
Sample commands
Archive a folder ( -c means create )
tar cvf - folder | gzip > archive.tar.gz
Archive a file
tar cvf - filename | gzip > archive.tar.gz
Archive files
tar cvf - filename1 filename2 | gzip > archive.tar.g
Alternative format (-z means use gzip to compress)
tar cvzf /path/to/dir/archive.tar.gz filename
tar cvzf /path/to/dir/archive.tar.gz filename1 filename
Extracting (-x means extract )
tar xvzf /path/to/dir/archive.tar.gz
There are other ways and tools to make your archives. But we’ll continue with that some other time. For the really lazy, I’ll make a bash script that uses tar and gzip in a later post so watch for that.
I hope my article helped some newbies out there. Mabuhay!
By @codespud  
DISCLAIMER This is my personal weblog and learning tool. The content within it is exactly that – personal. The views and opinions expressed on the posts and the comments I make on this Blog represent my own and not those of people, institutions or organisations I am affiliated with unless stated explicitly. My Blog is not affiliated with, neither does it represent the views, position or attitudes of my employer, their clients, or any of their affiliated companies.