Rsync: Difference between revisions
From Leo's Notes
This page was last edited on 17 April 2020, at 02:26.
mNo edit summary |
|||
| Line 1: | Line 1: | ||
== Quick Usage Guide == | == Quick Usage Guide == | ||
=== Copying Files via SSH === | === Copying Files via SSH === | ||
To copy files from {{code|/export/backup}} to a remote location (on server 'backup'): | To copy files from {{code|/export/backup}} to a remote location (on server 'backup'): | ||
{{highlight|lang=terminal|code= | {{highlight|lang=terminal|code= | ||
$ rsync -avz /export/backup/ -e ssh backup:/export/backup/ | |||
## Or with a non-standard SSH port | ## Or with a non-standard SSH port | ||
$ rsync -avz /export/backup/ -e "ssh -p 2222" backup:/export/backup/ | |||
}} | }} | ||
=== Copying files with Progress Information === | === Copying files with Progress Information === | ||
{{highlight|lang=terminal|code= | {{highlight|lang=terminal|code= | ||
$ rsync -avh --progress /src/ /dst/ | |||
}} | |||
=== Limiting Bandwidth === | |||
The transfer rate can be limited with the {{code|--bwlimit=kbps}} option. Bytes per second is the default if no unit is given. | |||
{{highlight|lang=terminal|code= | |||
## Limit transfer speed to 1MB/s | |||
$ rsync --bwlimit=1024 /source/ /destination/ | |||
$ rsync --bwlimit=1m /source/ /destination/ | |||
}} | }} | ||
== Copying Directories == | == Copying Directories == | ||
Because I've been bitten by this issue way too many times in the past couple of days, to avoid copying a directory into another directory, '''always have a trailing slash from the source'''. | |||
In more depth, suppose I have a {{code|src}} directory and I want its contents to be replicated in {{code|dst}}. | |||
In more depth, suppose I have a | |||
{{highlight|lang=terminal|code= | {{highlight|lang=terminal|code= | ||
## This copies 'src' into 'dst/src' | ## This copies 'src' into 'dst/src' | ||
$ rsync -avh src dst | |||
## This too copies 'src' into 'dst/src' | ## This too copies 'src' into 'dst/src' | ||
$ rsync -avh src dst/ | |||
## Works as expected. Contents in src is now in dst | ## Works as expected. Contents in src is now in dst | ||
$ rsync -avh src/ dst | |||
## Works as expected as well | ## Works as expected as well | ||
$ rsync -avh src/ dst/ | |||
}} | }} | ||
== See Also == | == See Also == | ||
* https://calomel.org/rsync_tips.html | * https://calomel.org/rsync_tips.html | ||
{{Navbox Linux}}[[Category:Linux]] | {{Navbox Linux}}[[Category:Linux]] | ||
[[Category:LinuxUtilities]] | [[Category:LinuxUtilities]] | ||
Revision as of 02:26, 17 April 2020
Quick Usage Guide
Copying Files via SSH
To copy files from /export/backup to a remote location (on server 'backup'):
$ rsync -avz /export/backup/ -e ssh backup:/export/backup/
## Or with a non-standard SSH port
$ rsync -avz /export/backup/ -e "ssh -p 2222" backup:/export/backup/
Copying files with Progress Information
$ rsync -avh --progress /src/ /dst/
Limiting Bandwidth
The transfer rate can be limited with the {{{1}}} option. Bytes per second is the default if no unit is given.
## Limit transfer speed to 1MB/s
$ rsync --bwlimit=1024 /source/ /destination/
$ rsync --bwlimit=1m /source/ /destination/
Copying Directories
Because I've been bitten by this issue way too many times in the past couple of days, to avoid copying a directory into another directory, always have a trailing slash from the source.
In more depth, suppose I have a src directory and I want its contents to be replicated in dst.
## This copies 'src' into 'dst/src'
$ rsync -avh src dst
## This too copies 'src' into 'dst/src'
$ rsync -avh src dst/
## Works as expected. Contents in src is now in dst
$ rsync -avh src/ dst
## Works as expected as well
$ rsync -avh src/ dst/