Differences
This shows you the differences between two versions of the page.
linux_wiki:rsync [2014/11/20 19:28] 127.0.0.1 external edit |
linux_wiki:rsync [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Rsync ====== | ||
- | Rsync is good for local and over the network file copying. | ||
- | If the copy is interrupted, | ||
- | __Useful Options__ | ||
- | |||
- | There are a lot of options to rsync. The ones that I actually use are: | ||
- | * -a, --archive : archive mode, which is the same as | ||
- | * recursive (-r), | ||
- | * copy symlinks as symlinks (-l), | ||
- | * preserve permissions (-p), | ||
- | * preserve modification times (-t), | ||
- | * preserve group (-g), | ||
- | * preserve owner (-o), | ||
- | * preserve device and special files (-D). | ||
- | * -h, --human-readable : output numbers in human readable format | ||
- | * -v, --verbose : increase verbosity | ||
- | * -P : keep partially transferred files (--partial) and show progress during transfer (--progress) | ||
- | * --delete : delete files on the destination that are no longer on the source. | ||
- | * This option is useful if you are actually trying to keep two locations in sync and not trying to do a regular copy or backup. | ||
- | * -exclude-from=FILE : do not copy files matching the patterns from FILE | ||
- | * This option is easier to show an example of instead of a description. | ||
- | |||
- | === Examples === | ||
- | |||
- | __Local File Copy__ | ||
- | |||
- | Perform a local file system copy from one folder to another. | ||
- | In this case, I would definitely want to use archive mode to preserve all of my file attributes. | ||
- | I would also normally want to see transfers in human readable format, details (verbose), and see the transfer progress. | ||
- | |||
- | < | ||
- | rsync -ahvP / | ||
- | </ | ||
- | |||
- | __Keeping Folders In Sync__ | ||
- | |||
- | Keep a destination in sync with whatever the source has. | ||
- | In this case, the delete option would be desired, so if a file is deleted from the source, it is also removed from the destination on the next sync. (Which is probably run as a cron job) | ||
- | |||
- | < | ||
- | rsync -avhP --delete / | ||
- | </ | ||
- | |||
- | __Excluding Folders/ | ||
- | |||
- | Perform a folder sync, but exclude certain folders matching a pattern in a file. | ||
- | |||
- | < | ||
- | rsync -avhP --delete -exclude-from=/ | ||
- | </ | ||
- | |||
- | The contents of rsync_exceptions could be: | ||
- | |||
- | < | ||
- | -/records/ | ||
- | -projects | ||
- | -*.jpg | ||
- | </ | ||
- | |||
- | Those two patterns mean: | ||
- | * -/ | ||
- | * That means it would exclude / | ||
- | * -projects : exclude any file, directory, or symlink that matches " | ||
- | * If the desire was to exclude any folder named " | ||
- | * -*.jpg : exclude any file that ends in " | ||
- | |||
- | See the rsync man page and search for " | ||
- | |||
- | __Rsync in SSH Tunnel__ | ||
- | |||
- | You can tunnel rsync in a SSH tunnel for over the internet transfers. | ||
- | It is much easier than it sounds, in fact..it is still a one line command. | ||
- | |||
- | < | ||
- | rsync -ahvP -e " | ||
- | </ | ||
- | The above opens a SSH tunnel to " |