tar does not skip empty directories
i'm using tar to create an archive from a mounted share. the archive should only backup files that are newer than "time"
tar --create --gzip --file=/path/to/gzip/file --newer=/path/to/timestamp/file /path/to/files/needing/backup/ this works great because only the files that are newer than the timestamp file are backed up. HOWEVER, since tar searches through all the directories in /path/to/files/needing/backup/ it also backs up empty directories. the files older than --newer get skipped, but that the directories that contain those files get backed up, therefore creating empty directories. so my basic question is, how do i tell tar not to archive empty directories? lrt |
Tar doesn't provide an obvious means of skipping empty directories.
But, you could embed your tar script in a shell script. Let the shell detect empty directories in the search path and skip to the next until a directory with files is found, then apply the tar script to the files in the directory. |
A method can be using find in conjunction with the tar command. First create a file with a timestamp to compare
Code:
touch -t 200710011500 /path/to/reftime Code:
find /path/to/source/dir -cnewer /path/to/reftime -print0 | xargs -0 --no-recursion -zcvf /path/to/archive.tar.gz |
exactly what i was looking for. thank you colucix! (cool screename by the way).
lrt |
there doesn't seem to be a --no-recursion option for xargs
|
Uh oh... sorry, I mispelled the command (forgotten tar). --no-recursion is a tar option
Code:
find /path/to/source/dir -cnewer /path/to/reftime -print0 | xargs -0 tar --no-recursion -zcvf /path/to/archive.tar.gz |
works like a charm thanks again
|
You're welcome! :)
|
All times are GMT -5. The time now is 04:58 AM. |