Rsync Remote Sync and Folder Merging
The 'r' in 'rsync' Stands for Remote
I knew that you were able to sync folders such as with a USB but it I didn't realise that you can synchronise folders with a server, including those in your ~/.ssh/config. You just need to put a colon after the name so it knows it's not a directory.Good Defaults and a Million Options
When I first used rsync I copied a very long command from Stack Overflow, having read what each argument was for and deciding well this is going to take ages to learn. I'll wait until I need this tool again so I don't forget.
When I went to use it again, I had a look at the manpage.
It turns out that -a (short for archive) does basically everything you need; it's short for -rlptgoD. I've seem some examples online that use those letters in combination with -a unnecessarily. This looks daunting but in fact only does the following:
- -r recursive
- -l copying symlinks as symlinks
- preserve file metadata: -p permissions, -t modification times, -g groups, -o owner
- -D preserve device files device files (root only)
This is exactly what you'll want most of the time. Another thing you want most of the time is to not bother replacing files if the size and modify time are the same, which is the default; there are options to avoid this if needed.
-v is for verbose and it's probably a good choice.
If you're unsure about what's going to happen, use -n or --dry-run to try it without the changes.
Copying a Folder vs its Contents
rsync -av ./src server:destIt might not be obvious the first time, but this command results in 'dest' containing the folder 'src'. If you wanted the contents of 'src' to become contents of 'dest', not only does ./src/* work but so does simply ./src/ without the asterisk. However the asterisk is needed for cp.
Comments
Post a Comment