0

How do I create a tar.gz from

  1. A list of FULL PATH files (such as /root/test/abcd/123.txt )
  2. that includes both directories AND files
  3. that preserves the ownership AND permissions of both files and directories when extracted?

This is how my list of files (dbfiles.log) looks like:

[oracle@test ~]$ cat dbfiles.log
/u01/app/oracle/product/12.2.0/dbhome_1/dbs/initDEVR.ora
/u01/app/oracle/product/12.2.0/dbhome_1/dbs/orapwDEVR
/u01/app/oracle/product/12.2.0/dbhome_1/dbs/spfileDEVR.ora
/u01/app/oracle/oradata/DEVR/control01.ctl
/u01/app/oracle/oradata/DEVR/control02.ctl
/u01/app/oracle/oradata/DEVR/redo01.log
/u01/app/oracle/oradata/DEVR/redo02.log
/u01/app/oracle/oradata/DEVR/redo03.log
/u01/app/oracle/oradata/DEVR/sysaux01.dbf
/u01/app/oracle/oradata/DEVR/system01.dbf
/u01/app/oracle/oradata/DEVR/temp01.dbf
/u01/app/oracle/oradata/DEVR/undotbs01.dbf
/u01/app/oracle/oradata/DEVR/users01.dbf
[oracle@test ~]$

This is how I am doing it today:

tar -czvf TARFILENAME.tar.gz -T dbfiles

However it requires manual permission configuration after extracting. By the way, I have to use sudo to extract the file, so directories get root:root ownership and not the original oracle:oinstall as needed.

I found some references suggesting that tar's flag --no-recursion could solve the problem:

tar -zcf file.tgz --no-recursion abc --recursion abc/def

I believe this is the right approach, but I'm not sure how can I make this work with my file list. Maybe using find to go through the list and send output to the tarball? I'm honestly not sure.

  • tar -p preserves permissions – Panki Oct 15 at 11:42
  • 1
    Read man tar or info tar. – waltinator Oct 15 at 12:13
1

for compressing you can use tar -cvpf filename.tar.gz directory.

while extracting, use --same-owner parameter. for e.g. tar -xvzf --same-owner filename.tar.gz

| improve this answer | |
  • A hostile person again removed a usefull comment. So let me add it again: The tar command does not implement an option called --same-owner, so you seem to use a tar clone. But in your example command line, any tar compatible command needs to use the argument --same-owner as argument to the f keyletter. If the tar clone you are using behaves otherwise, it is broken. – schily Oct 16 at 14:18
0

I end up finding the solution. Here it is in case someone else needs:

awk -F/ '{ d=$1; for (i=2; i <= NF; i++) { print d; d=d "/" $i }; print d }' dbfiles | awk '{ if (index(old,$0 "/") != 1) { old=$0; print } }' | tar czvf $LOCALFS/$TARFILENAME.tar.gz --no-recursion -T -

Thanks to who have answered my initial question.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.