How to use tar for archive & compression

From DISI
Revision as of 20:11, 20 July 2018 by Benrwong (talk | contribs) (explained tar command; provided example of sending tarball over SSH.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Use tar to group together a collection of files, preserving user/group ownerships and permissions, into one single, compressed archive file. The resulting tar file (tarball) that is created with the tar command helps with storing old data and makes it convenient for moving around over the network.

Create a tarball and stream it over SSH to migrate data to a new server

Scenario: We have a lot of old user data on nfs-home & nfs-work and I want to archive their data and send it over SSH to archive server, nfs-ex9.

Data to migrate: nfs-work:/export/work/<username> Migration destination: nfs-ex9:/ex9/archive/departed/<dataorigin>.<username>.tar

While on nfs-work:

$ tar -cvzf - /export/work/adler | ssh nfs-ex9 "cat > /export/ex9/archive/departed/nfs-work.adler.tar.gz"
-c: create archive
-v: verbose output
-z: use gzip compression
-f: file argument
-: dash means output to standard output.  The argument in this location is generally for naming the tarball that is created on the local filesystem but since we are going to pipe to ssh, 
we are sending to stdout. | ssh nfs-ex9 "cat > /export/ex9/archive/departed/nfs-work.adler.tar.gz": pipes the stdout from the tar create command and sends it over ssh to nfs-ex9 where it will be output as a file named
"nfs-work.adler.tar.gz"