May 11, 2005

Using tar to archive only newer files

Q: We sometimes have multiple people updating project directories and we would like to be able to periodically make an archive of files which have changed so we can update other places where rsync isn't feasible to use. How can we do this?

A: You should be able to combine options for both the tar and find utilities into one line to produce the desired archive.

Tar archive with gzip compression
tar -czf /tmp/myArchive.tgz `find . -newer /path/to/file/to/compare -type f -print`

Regular tar archive
tar -cf /tmp/myArchive.tar `find . -newer /path/to/file/to/compare -type f -print`

If we omitted the "-type f", any directories which contained modified files would also appear in the list, causing tar to add that entire directory. This is not the behaviour we want, so we tell the find utility to restrict its choices to regular files only.

Posted by Eingang at 01:20 PM | Comments (0) | TrackBack