Find & copy

I had a need to get find a few files that had been added or modified within the last 14 days and make a backup of those files.
Not to big of a problem, except that they were hidden amongst 90,000+ other files.

Find to the rescue! The operation comes in two parts.

First I need to create a mirror of the directory structure.

find /exports/ -mtime -14 -type d -exec mkdir -p /root/backup/{} \;

Then we backup the files

find /exports/ -mtime -14 -type f -exec cp -pf '{}' '/root/backup/{}' \;
Source:
http://linux.dsplabs.com.au/find-replicate-mirror-copy-complex-directory-and-file-structure-using-hard-links-p44/

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">