0

I have two systems that I'm splitting processing between, and I'm trying to find the most efficient way to move the data between the two. I've figured out how to tar and gzip to an archive on the first server ("serverA") and then use rsync to copy to the remote host ("serverB"). However, when I untar/unzip the data there, it saves the archive including the full path name from the original server. So if on server A my data is in:

/serverA/directory/a/lot/of/subdirs/myData/*

and, using this command:

tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz /serverA/directory/a/lot/of/subdirs/myData/

Everything in .../myData is successfully tarred and zipped in myData-archive.tar.gz

However, after copying the archive, when I try to untar/unzip on the second host (I manually log in here to finish the processing, the first step of which is to untar/unzip) using this command:

tar -zxvf /serverB/current/directory/myData-archive.tar.gz

It untars everything in my current directory (serverB/current/directory/), however it looks like this:

/serverB/current/directory/serverA/directory/a/lot/of/subdirs/myData/Data*ext

How should I formulate both the tar commands so that my data ends up in a directory called

/serverB/current/directory/dataHERE/ 

?

I know I'll need the -C flag to untar into a different directory (in my case, /serverB/current/directory/dataHERE ), but I still can't figure out how to make it so that the entire path is not included when the archive gets untarred. I've seen similar posts but none that I saw discussed how to do this when moving between to different hosts.

UPDATE: per one of the answers in this question, I changed my commands to:

  1. tar/zip on serverA:

    tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz serverA/directory/a/lot/of/subdirs/myData/ -C /serverA/directory/a/lot/of/subdirs/ myData
    
  2. and, untar/unzip:

    tar -zxvf /serverB/current/directory/myData-archive.tar.gz -C /serverB/current/directory/dataHERE
    

And now, not only does it untar/unzip the data to:

/serverB/current/directory/dataHERE/

like I wanted, but it also puts another copy of the data here:

/serverB/current/directory/serverA/directory/a/lot/of/subdirs/myData/

which I don't want. How do I need to fix my commands so that it only puts data in the first place?

Community
  • 1
  • 1
user20408
  • 679
  • 2
  • 7
  • 23
  • Isn't this the same as http://stackoverflow.com/questions/18681595/tar-a-directory-but-dont-store-full-absolute-paths-in-the-archive?rq=1? – melpomene Jan 22 '17 at 02:02
  • @melpomene I looked there first and tried some of the solutions and it kind of worked except, in addition to untarring/unzipping the data into /serverB/current/directory/dataHERE/, it ALSO copied the data to: /serverB/current/directory/serverA/directory/a/lot/of/subdirs/myData/Data*ext and i'm not sure why – user20408 Jan 22 '17 at 23:06
  • @melpomene but it will work for now, i'll just have to delete the duplicate data. it'd be nice if i wasnt (seemingly) doing it twice but oh well – user20408 Jan 22 '17 at 23:13

2 Answers2

0

On serverA do

( cd /serverA/directory/a/lot/of/subdirs; tar -zcvf myData-archive.tar.gz myData; )
AlexP
  • 4,370
  • 15
  • 15
0

After some more messing around, I figured out how to achieve what I wanted:

To tar on serverA:

tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz -C /serverA/directory/a/lot/of/subdirs/ myData

Then to untar on serverB:

tar -zxvf /serverB/current/directory/myData-archive.tar.gz -C /serverB/current/directory/dataHERE
user20408
  • 679
  • 2
  • 7
  • 23