LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using find and pipe to tar (https://www.linuxquestions.org/questions/linux-newbie-8/using-find-and-pipe-to-tar-4175534947/)

mtsoule 02-24-2015 08:31 AM

Using find and pipe to tar
 
am trying to use tar in combination with find, the goal is to all files in /export that have been modified in the last 24 hours (back up purposes), then tar them so I can untar on the backup server, updating just the modified files.

Perhaps there is a better way, however, I have tried using cpio but the problem come in when I copy to the NAS drive (NTFS) I lose all my owner/group and permissions. I have found that if I tar the files, then copy them to the NAS, when I untar on the server, it will retain the owner/group and permissions.

So… here is what I have tried:

First, I use the find command to see what files should be in the tar archive.
Code:

/export $ find . -depth -mtime 0 -print
./file4
./file3
.

Ok, that looks right, now I will try to pipe that in to tar
Code:

/export $ find . -depth -mtime 0 -print0 | tar -czvf backup.tar.gz --null -T -
./file4
./file3
./
./share/
./share/pdf/
./share/pdf/penny-2014-09-03-11:41.30.pdf
./share/pdf/penny-2014-09-03-14:25.17.pdf
./share/pdf/penny-2014-09-03-11:24.36.pdf
./share/pdf/penny-2014-09-03-14:37.12.pdf
tar: ./share/pdf/.directory: Cannot open: Permission denied
./share/pdf/penny-2014-09-02-14:52.06.pdf
./share/pdf/penny-2014-09-03-12:18.43.pdf
tar: ./share/PDF: Cannot open: Permission denied
./share/file3
tar: ./share/.directory: Cannot open: Permission denied
./dir1/
./dir1/file1
./file4
./file2
./file3
tar: ./.directory: Cannot open: Permission denied
./list
tar: Exiting with failure status due to previous errors

It seems that it is trying to tar all the files in that directory. When I view the files in backup.tar.gz all of the files from /export are in there not just the modified ones

schneidz 02-24-2015 08:34 AM

try adding -type f for just files to feed to tar. it seems like it is sending tar the . directory.

mtsoule 02-24-2015 08:38 AM

I tried -type f and received the same results. this is weird!

rknichols 02-24-2015 12:09 PM

Exactly where in the command line did you add that option. The tests in find are a logical expression (the implied operator is AND) that is evaluated left-to-right. If the "-type f" comes after the "-print0" then it won't affect the output.

And without that "-type f" the problem is obvious. One of the items found was "./", and that will cause tar to recursively search the entire directory tree.

mtsoule 02-24-2015 12:16 PM

Code:

/export $ find . -depth -mtime 0 -print0 -type f | tar -czvf backup.tar.gz --null -T -
then after your post, I retried with

Code:

/export $ find . -depth -type f -mtime 0 -print0 | tar -czvf backup.tar.gz --null -T -
and it seems to work!! many thanks! I will continue to test before putting it in actual use


All times are GMT -5. The time now is 05:53 PM.