Yay Linux! Using tar to pull and compress a directory from a remote server

#### Using tar to pull and compress a directory on a remote server. ####

I have a remote server which has /u01 and /u02 mount points on it. This server keeps dying before the night DBA can get into it to grab files for a rebuild.

I wanted to pull down both the /u01 and /u02 directories, to preserve them. I initially used rsync for it’s “restartable” characteristics. This didn’t do what I wanted as far as preserving permissions, so I decided to use the tar utility. The remote server does not have enough free space on it to create the tar and then copy it off. So I used tar and ssh to compress, pull down and create the tar.gz on my local machine.

After looking around and finding a bunch of to complicated solutions, I came upon a simpler command string.

So this is what I did.
(Kev, remember this as it is useful!)

—-

ssh root@srv03 ‘tar cvfz – /u01’ > /kftmp/srv03_u01/srv03_u01.tgz

—-

Since the was a directory that my regular use does not have full access to I did have to enable root ssh. This was disabled right after the transfer.

I ended up with a tar gz file on my local system which, while owned by me, had preserved the file ownership and permissions of the original /u01 file system.

—-
root@SoftKitty:/kftmp# ls -lh srv03_u01/
total 396M
-rw-rw-r– 1 kfitzgerald kfitzgerald 395M Aug 3 17:38 srv03_u01.tgz
root@SoftKitty:/kftmp#
—-

Yay Linux!
K-Dog. The_Kev
:wq

Comments

  1. alcoholfueledmachine says:

    would -p or -a not work in rsync? neat idea I hadn’t thought of!

    • Hmmm… Could work…. but I found another advantage to a .tgz. That is that I can move it around as a package and don’t have to keep worrying about permissions.

  2. falseflag says:

    What the hell? An on-topic linux post? I thought this was a inappropriately titled blog about Thursday Night Board Games!

  3. alcoholfueledmachine says:

    Since when do you have permissions on your package?