Rsync: Difference between revisions
No edit summary |
|||
(One intermediate revision by the same user not shown) | |||
Line 4: | Line 4: | ||
== Common Options == | == Common Options == | ||
<code> -a </code> - Combo flag, same as -rlptgoD (recursive; copies symlinks; preserve: permissions, modification times, group, and owner; device/special) | <code> -a </code> - Combo flag, same as -rlptgoD (recursive; copies symlinks; preserve: permissions, modification times, group, and owner; device/special). | ||
<code> -v </code> - verbose | <code> -v </code> - verbose | ||
<code> -n </code> - do a "dry run". Together with -v, -n shows what rsync will copy, but doesn't actually copy anything | <code> -h </code> - output numbers in a human-readable format | ||
<code> -n </code> - do a "dry run". Together with -v, -n shows what rsync will copy, but doesn't actually copy anything. | |||
<code> -z </code> - Compress the contents for transmission. | |||
<code> -P </code> - Show a progress bar, and resume interrupted transfers. | |||
<code>--delete</code> - By default, rsync doesn't delete anything. To truly sync a directory, add the --delete flag, and rsync will delete files to keep the source and destination directories the same. (Note: Use the -n flag with this command first, to confirm that rsync will delete only what you want it to delete.) | |||
<code>dir</code> vs <code>dir/</code>:<br /> | <code>dir</code> vs <code>dir/</code>:<br /> | ||
<code>dir</code> - Copy the directory<br /> | <code>dir</code> - Copy the directory<br /> | ||
<code>dir/</code> - Copy the contents of the directory | <code>dir/</code> - Copy the contents of the directory | ||
== Sync Directories on the same computer == | == Sync Directories on the same computer == | ||
<code>rsync -a dir1/ dir2</code> - Copies the contents of dir1 into dir2 | <code>rsync -a dir1/ dir2</code> - Copies the contents of dir1 into dir2 | ||
== Copy files to a remote system == | == Copy files to a remote system == | ||
Line 29: | Line 39: | ||
'''Example:'''<br /> | '''Example:'''<br /> | ||
<code>rsync -a bob@example.com:/home/bob/public_html/docs/ /home/bob/web_files/docs</code> - Copies the contents of /home/bob/public_html/docs/ into the local directory /home/bob/web_files/docs | <code>rsync -a bob@example.com:/home/bob/public_html/docs/ /home/bob/web_files/docs</code> - Copies the contents of /home/bob/public_html/docs/ into the local directory /home/bob/web_files/docs | ||
== References == | == References == |
Latest revision as of 02:33, 29 June 2024
rsync copies files and directories. It is often used for backups, or duplicating directory contents on a remote server. rsync can copy only changed files, and can use SSH to securely copy the file.
Common Options
-a
- Combo flag, same as -rlptgoD (recursive; copies symlinks; preserve: permissions, modification times, group, and owner; device/special).
-v
- verbose
-h
- output numbers in a human-readable format
-n
- do a "dry run". Together with -v, -n shows what rsync will copy, but doesn't actually copy anything.
-z
- Compress the contents for transmission.
-P
- Show a progress bar, and resume interrupted transfers.
--delete
- By default, rsync doesn't delete anything. To truly sync a directory, add the --delete flag, and rsync will delete files to keep the source and destination directories the same. (Note: Use the -n flag with this command first, to confirm that rsync will delete only what you want it to delete.)
dir
vs dir/
:
dir
- Copy the directory
dir/
- Copy the contents of the directory
Sync Directories on the same computer
rsync -a dir1/ dir2
- Copies the contents of dir1 into dir2
Copy files to a remote system
Specify the directory you want to copy, then the destination.
rsync -a /dir1 username@remote_host:destination_directory
Example:
rsync -a /docs bob@example.com:/home/bob/public_html
- Copies the entire directory "docs" into directory /home/bob/public_html on the server.
You can reverse this to copy from the remote system to the local computer.
Example:
rsync -a bob@example.com:/home/bob/public_html/docs/ /home/bob/web_files/docs
- Copies the contents of /home/bob/public_html/docs/ into the local directory /home/bob/web_files/docs