As others have identified, the problem with your command is that it includes directories, and tar archives them recursively. If a directory has been modified recently, all the files in it and its subdirectories get included, whether they have been modified or not.
If you don't care to back up directory metadata, then just tell find
not to print directory names. It isn't enough to omit the root: the same thing can happen with subdirectories too.
find "$SOURCEDIR" -mtime -1 ! -type d -print | xargs -r tar -rcf "$ARCHIVE"
Using xargs fails with file names containing spaces and some other special characters. This is easy to fix: use -exec
instead of xargs
.
find "$SOURCEDIR" -mtime -1 ! -type d -exec tar -rcf "$ARCHIVE" {} +
If you want to back up directory metadata, let find
print everything and instead tell tar
not to recurse into subdirectories. Since find
is doing the recursion, tar
doesn't need to.
find "$SOURCEDIR" -mtime -1 -exec tar -rcf "$ARCHIVE" --no-recursion {} +
With this approach, you can avoid the use of tar -rc
and instead solve the problem of repeated tar invocations by first creating an archive with only the root directory, and then appending to it in batches. (Why the root directory? Because GNU tar is afraid of creating an empty archive.)
tar -cf "$ARCHIVE" --no-recursion "$SOURCEDIR"
find "$SOURCEDIR" -mindepth 1 -mtime -1 -exec tar -rf "$ARCHIVE" --no-recursion {} +
Best Answer
Options are case sensitive. Your command as written is simultaneously trying to extract data (
-x
) and create it (-c
). From context it looks like you actually want to change directory for the extraction (-C
). The untested command therefore becomes,Please note that generally you shouldn't be writing into a root level folder (
/satrap_dir
). That's what your own home directory is for.