Operating System - HP-UX
1753826 Members
8144 Online
108805 Solutions
New Discussion юеВ

backup files modified in the last 7 days

 
SOLVED
Go to solution
Adam Noble
Super Advisor

backup files modified in the last 7 days

Hi all,

I have a scenario whereby a customer wants to generate a tar file of all files modified in the last 7 days. I thought this would be quite simple. I created a dummy tar file then ran:-

I ran find /noddy -type f -mtime -7 | xargs tar -rf /tmp/dummy.tar

This appeared to work fine then I noticed a lot of errors due to files with strange file naming conventions that its saying it effectively could not find. Is there a better way of doing this?

Thanks
6 REPLIES 6
Yogeeraj_1
Honored Contributor

Re: backup files modified in the last 7 days

hi,

can you post the exact error messages?

It could be that you do not have enough permissions to access some of the files in the /noddy directory.

revert
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
F Verschuren
Esteemed Contributor

Re: backup files modified in the last 7 days

hi, I never used the -r option, can it be that you forget to remove the old file?
/tmp/dummy.tar?
that will cause that you potentialy are edding files to a tar file whit the same name, I guess that can gave strange errors!
Matti_Kurkela
Honored Contributor
Solution

Re: backup files modified in the last 7 days

In HP-UX, the combination of find+xargs is sensitive to spaces in file names.

With GNU tools, the way to handle complex filenames safely in commands like this is to use the "-print0" option of GNU find and the "-0" option of GNU xargs.

HP-UX has the same functionality implemented in a different way: the HP-UX find has the "-exec {} \+" syntax. Note the plus sign instead of semi-colon.

Try a command like

find /noddy -type f -mtime -7 -exec tar -rf /tmp/dummy.tar {} \+

This should be as efficient as the find+xargs combination, but capable of handling filenames with spaces and/or all kinds of special characters.
MK
Adam Noble
Super Advisor

Re: backup files modified in the last 7 days

Spot on Matti exactly what I was looking for the exec command worked fine.
F Verschuren
Esteemed Contributor

Re: backup files modified in the last 7 days

forget my last remark, this is working:
[nlxsms01:root:/home/nl11588]# find ./joke | xargs tar -rf /tmp/dummy.tar
[nlxsms01:root:/home/nl11588]# find ./joke | xargs tar -rf /tmp/dummy.tar
[nlxsms01:root:/home/nl11588]# find ./joke | xargs tar -rf /tmp/dummy.tar
[nlxsms01:root:/home/nl11588]# tar -tvf /tmp/dummy.tar
rwxr-x--- 18588/10000 0 Dec 3 12:48 2007 ./joke/
rwxr-x--- 18588/10000 0 Dec 3 12:48 2007 ./joke/
rwxr-x--- 18588/10000 0 Dec 3 12:48 2007 ./joke/
rwxr-x--- 18588/10000 0 Dec 3 12:48 2007 ./joke/
rwxr-x--- 18588/10000 0 Dec 3 12:48 2007 ./joke/
rwxr-x--- 18588/10000 0 Dec 4 13:59 2007 ./joke/
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/1
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/2
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/1
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/2
rwxr-x--- 18588/10000 0 Dec 4 13:59 2007 ./joke/
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/1
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/2
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/1
rw-r--r-- 0/3 0 Dec 4 13:59 2007 ./joke/2
[nlxsms01:root:/home/nl11588]#
Dennis Handly
Acclaimed Contributor

Re: backup files modified in the last 7 days

You shouldn't be using tar nor xargs with find.
You instead should use cpio, which takes the list of files from stdin, or use pax(1), which combines the best of cpio/tar:
$ find /noddy -type f -mtime -7 | pax -w -f /tmp/dummy.tar

>Matti: the combination of find+xargs is sensitive to spaces in file names.

pax(1) handles the spaces fine.