LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2015, 09:31 AM   #1
mtsoule
Member
 
Registered: Aug 2012
Posts: 35

Rep: Reputation: Disabled
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
 
Old 02-24-2015, 09:34 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,167

Rep: Reputation: 889Reputation: 889Reputation: 889Reputation: 889Reputation: 889Reputation: 889Reputation: 889
try adding -type f for just files to feed to tar. it seems like it is sending tar the . directory.
 
Old 02-24-2015, 09:38 AM   #3
mtsoule
Member
 
Registered: Aug 2012
Posts: 35

Original Poster
Rep: Reputation: Disabled
I tried -type f and received the same results. this is weird!
 
Old 02-24-2015, 01:09 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,618

Rep: Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577
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.
 
1 members found this post helpful.
Old 02-24-2015, 01:16 PM   #5
mtsoule
Member
 
Registered: Aug 2012
Posts: 35

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to search for a pattern of a tar ball and pipe that name to tar to extract linux_newb Linux - General 2 02-27-2012 05:28 PM
PIPE find results to tar not behaving as expected. a1danel Linux - Newbie 4 01-15-2011 02:50 PM
how to pipe my tar file linux_10_1 Linux - Newbie 2 04-11-2006 12:28 PM
tar problems, trying to pipe through split microsoft/linux Linux - Software 13 03-04-2006 09:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration