1
votes

I need to sync a local directory (destination) from the remote server directory (source) with the --delete option. I've got this:

Local directory is /home/user/config and into it

removeit.txt
bar.csv
foo.h
config.conf
scripts <- Is a directory
logs <- Is adirectory

The remote directory is config and into it

bar.csv
foo.h

I want in the local directory after rsync

bar.csv
foo.h
config.conf
scripts <- Is a directory
logs <- Is adirectory

I've tested with multiple options but I can't get a entire rsync command with my needs.

rsync -avz --min-size=1 --delete -e "ssh" [email protected]:./config/ ./config --exclude ./config/scripts --exclude ./config/logs --exclude ./config/device.conf --dry-run

With a list of include files

rsync -avz --min-size=1 --include-from=list --exclude=* --delete-excluded -e "ssh" [email protected]:.config/ config/

But nothing works as I expected. The subfolders in the destination are deleted.

1

1 Answers

0
votes

The man page for rsync has a section on "Include/Exclude Pattern Rules" which you should review. In particular, it looks like you are using ./ to refer to the directory relative of your shell's working directory which won't work the way you want.

Here is a relevant section of the documentation:

if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus /foo would match a name of "foo" at either the "root of the transfer" (for a global rule) or in the merge-file's directory (for a per-directory rule). An unqualified foo would match a name of "foo" anywhere in the tree because the algorithm is applied recursively from the top down; it behaves as if each path component gets a turn at being the end of the filename. Even the unanchored "sub/foo" would match at any point in the hierarchy where a "foo" was found within a directory named "sub". See the section on ANCHORING INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a pattern that matches at the root of the transfer.

The pattern you are using might be causing rsync to look for a folder literally called . which contains a file or folder called scripts or whatever.

Try replacing the relative-ish ./config/ part with / in your exclude patterns. That will anchor the pattern in the "root of transfer" which is the directory you are synchronizing. In other words, try this:

rsync -avz --min-size=1 --delete -e "ssh" [email protected]:./config/ ./config --exclude /scripts --exclude /logs --exclude /device.conf --dry-run

I hope that works. If it's not too late to check, please let me know if this worked for you.