1

I have strange rsync behaviour. I need to copy all files youngest than 2 days from one folder to another.

So i've mixed rsync with files-from argument and find utility in a script to do what i need to do.

#!/bin/bash
cd /mnt/smb/online/
find . -mtime -2 -print > /tmp/rsynclist
rsync -av --ignore-existing --size-only --files-from=/tmp/rsynclist /mnt/smb/online /mnt/backup/

File /tmp/rsynclist is ok, and have only files that i need (all files not older than 2 days). But rsync seems to ignore that 'files-from' argument and continuing to copy all files from source older.

Where i am mistaking?

Jaels
  • 67
  • 1
  • 11

2 Answers2

3

The problem is not in the rsync command, but in your find. While testing your script I noticed that there are also directories in my rsynclistfile that have been changed, resulting in rsync copying all files under these directories.

To prevent this, add -type f to your find command.

#!/bin/bash
cd /mnt/smb/online/
find . -type f -mtime -2 -print > /tmp/rsynclist
rsync -av --ignore-existing --size-only --files-from=/tmp/rsynclist /mnt/smb/online /mnt/backup/

Afterwards only paths to files should be in the list, giving in the intended result.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
-2

The syntaxe of the rsync command is :

rsync [option] source[x] destination

You had put 2 sources :

  • /tmp/rsynclist ; the right one
  • /mnt/smb/online ; this is wrong and you must delete it

try with :

rsync -av --ignore-existing --size-only --files-from=/tmp/rsynclist  /mnt/backup/
Thomas
  • 4,225
  • 5
  • 23
  • 28
Med
  • 7
  • 2