I have writted a bash script to backup folders and files from a machine to our backup server. My goal is to exclude all the files older than 6 months from this weekly backup. To do that, I used a find command to build a txt file which contains the path of these files.

find . -type f -mtime -200 -fprintf $SCRIPT_DIR/Exclusions.txt "%P\n"

And then I used the option "--include-from" of rsync.

rsync . -e ssh -qrtl --exclude-from=$SCRIPT_DIR/Exclusions.txt $USER@$DEST_SRV:$DEST_DIR

The result was the backup worked but not the inclusion. So all the files were backuped even these older than 6 months.

How can I do for this ?

Thanks in advance


According to man pages,

--exclude=PATTERN       exclude files matching PATTERN
--exclude-from=FILE     read exclude patterns from FILE
--include=PATTERN       don't exclude files matching PATTERN
--include-from=FILE     read include patterns from FILE

The exclusion is made reading pattern from files, and not according to the files names themselves.

I agree including/excluding files according to names could be handful as well, but this is not how it works.

You could try something like this in order to include files newer than 1 week ago:

--files-from=<(find . -mtime -7 -print0)
  • It doesn't work. The task never ends and doesn't backup any files on the server. – gerem Jun 15 '15 at 11:19
  • Please provide the exact command line which your say never ends – philippe Jun 15 '15 at 11:31
  • rsync . -e ssh -qrtl --files-from=<(find . -mtime -7 -print0) $USER@$DEST_SRV:$DEST_DIR – gerem Jun 15 '15 at 11:35

Ok I resolved my issue! The "find" line stay the same:

find . -type f -mtime -200 -fprintf $SCRIPT_DIR/includes.txt "%P\n"

And I use the "--files-from" option instead of "--exclude-from"

rsync . -e ssh -qrtl --files-from=$SCRIPT_DIR/includes.txt $USER@$DEST_SRV:$DEST_DIR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.