Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to keep file ownership while using tar

Tags:

unix

tar

perl

I am currently writing an automatic backup script for our servers. i am using the UNIX tar command in the script to archive the code repositories.

in my PERL script i am using the tar command as follows:

system("tar -jcpf $destPath/$string.tar.bz2 -X $exclusionFile $targetPath");

i want to keep file ownerships when extracting the tar archive. i tried to list the tar archive contents with

tar -jtvf

and the list contained the correct file ownerships for each file, but when extracting the archive, the file ownership changes to the current user.

is there any way to extract a tar archive and keep the original file ownerships for each file?

like image 520
DontCareBear Avatar asked Jun 24 '13 10:06

DontCareBear


1 Answers

Supply the option --same-owner to tar while extracting.

tar --help tells:

   --same-owner
          create extracted files with the same ownership
like image 101
devnull Avatar answered Sep 27 '22 19:09

devnull