Reputation: 3660
I want to rsync
contents from /local/path
to server:/remote/path
.
The files end with extensions composed by 4 digits
If a file does not exist in remote path, copy the file to remote and remove from local
If a file exists in remote path and the size is no less than the local one, do not copy the file to remote and remove it from local
I tried
rsync -avmhP --include='*.[0-9][0-9][0-9][0-9]' --include='*/' --exclude='*' --size-only --remove-source-files /local/path server:/remote/path
However, some files existing in the remote path remain in local path.
Another question is, why we need --include='*/' --exclude='*'
? Why --include='*.[0-9][0-9][0-9][0-9]'
alone doesn't work for the file filtering?
Upvotes: 1
Views: 1009
Reputation: 3863
Do you mean --remove-sent-file
instead of remove-source-file
?
According to the rsync man page :
--remove-sent-file
This tells rsync to remove from the sending side the files and/or symlinks that are newly created or whose content is updated on the receiving side. Directories and devices are not removed, nor are files/symlinks whose attributes are merely changed.
That's means that only transferred file (the ones whom size changed) are deleted from source. To active the include file, you first need to exclude all the other BUT my include pattern. The 3 arguments you used mean "I excluded all files (--include='*/' --exclude='*'
) but the ones matching my pattern (--include='*.[0-9]{4}'
)
From man page :
--include=PATTERN
don’t exclude files matching PATTERN
--exclude=PATTERN
exclude files matching PATTERN
Upvotes: 1