Tar command to take absolute path

Hi All,
I am trying to create a tar from absolute path then transfer that file to another machine.
But tar is not taking the absolute (full) path.
Could you please help. I tried tar -cvf option at source and tar -xvf option at destination

My variable has 3 files with full path

LIST="/var/tmp/ROLLabc.20191203 /var/tmp/ROLLdef.20191203 /var/tmp/ROLLghi.20191203"

I am using simple loop to tar the file

for filename in $LIST
do
        echo "Transferring $filename to xyz machine...!"
       tar -cvf - $filename |ssh -p222 username@<Some JUMPBOX> "ssh user@<xyz machine> \"cd /var/tmp; tar -xvf -\""
done

Error i get is:

Transferring /var/tmp/ROLLabc.20191203 to xyz...!
a /var/tmp/ROLLabc.20191203 535K
tar: Removing leading '/' from '/var/tmp/ROLLabc.20191203'
x var/tmp/ROLLabc.20191203, 95298 bytes, 5069 tape blocks

Try adding the -P option to both tar commands and omit the change directory.
Since you are extracting full paths, you do not need to cd to anywhere.

 tar -Pcvf - $filename |ssh -p222 username@<Some JUMPBOX> "ssh user@<xyz machine> 'tar -Pxvf -'"

Also, operating system and shell help us help you.

Hope that helps
Regards
Peasant.

2 Likes

Thank you Peasant. This worked.