1833861 Members
1969 Online
110063 Solutions
New Discussion

help with find

 
SOLVED
Go to solution
rleon
Regular Advisor

help with find

Hello

I am doing a small migration.
Last week I copied all of the data from mounta to mountb. This copy took about 14 hours do to the amount of data.

Now instead of taking 14 hours I would like to run a find command to find files newer then 7 days and copy them from mounta to mountb.

The problem is that my find syntax does not seem to be smart enough to copy them into the correct directory / subdirectory structure.

How can I find files newer then 7 days and make sure that file gets copied into the correct directory.

Thanks

5 REPLIES 5
Redhat
Trusted Contributor
Solution

Re: help with find


cd /mounta
find . -depth -mtime -7 -print |cpio -pmvdu /mountb

Hope it will help

see man pages for cpio
Jeff_Traigle
Honored Contributor

Re: help with find

Sounds like rsync would be a better choice of tools for this.
--
Jeff Traigle
KapilRaj
Honored Contributor

Re: help with find

I am sure "find /source -print | cpio -pdm /destination" will do the job. The cpio command make sure that it does not try to copy things that are already in the target.

Regards,

Kaps
Nothing is impossible
spex
Honored Contributor

Re: help with find

Hello,

This shell script has received only cursory testing by me, so use with care:

#!/usr/bin/sh

typeset -i MAXAGE=7
typeset SRCMP=/mounta
typeset DSTMP=/mountb

for F in $(find ${SRCMP} -type f -mtime -${MAXAGE} -print)
do
DIRNAME=${F%/*}
BASENAME=${F##*/}
DSTPATH=${DSTMP}${DIRNAME#${SRCMP}}
if [ ! -d ${DSTPATH} ]
then
mkdir -p ${DSTPATH}
echo "*** Created directory ${DSTPATH}"
fi
echo "Copying ${F} to ${DSTPATH}"
cp -p ${F} ${DSTPATH}
done

exit 0

PCS
Raj D.
Honored Contributor

Re: help with find

You can also use fbackup for selectively pickup the files and restore using frecover on the fly.

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "