Rsync: Difference between revisions

No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Lowercase title}}
See [[Archwiki:rsync]] and [https://linux.die.net/man/1/rsync rsync(1) - Linux man page]
See [[Archwiki:rsync]] and [https://linux.die.net/man/1/rsync rsync(1) - Linux man page]
==Getting Started==
<pre>
rsync -ah <src> <dst> --info=progress2
</pre>
;Flags
* <code>-a</code> archive mode (recursive, preserves symlinks, permissions, times, group, owner, devices)
** Excludes hard links (<code>-H</code>), ACLs (<code>-A</code>), and extended attributes (<code>-X</code>)
* <code>--no-i-r</code> or <code>--no-inc-recursive</code> scans all files at the beginning rather than during the transfer
* <code>--progress</code> shows per-file progress
* <code>--info=progress2</code> shows overall progress during the transfer


==System Backups==
==System Backups==
Line 11: Line 24:
EXCLUSIONS='--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}'
EXCLUSIONS='--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}'


sudo rsync -aAXq /  ${EXCLUSIONS} \ "${TARGET_FOLDER}"
sudo rsync -aAXh ${EXCLUSIONS} / "${TARGET_FOLDER}" --info=progress2
</pre>
</pre>


Line 19: Line 32:
* <code>-X</code> preserve extended attributes
* <code>-X</code> preserve extended attributes
* <code>-q</code> quiet
* <code>-q</code> quiet
==Exclude==
Add <code>--exclude</code> to your call.
;Notes
* Exclude typically uses a pattern. If you want to exclude from the root of the transfer, prepend <code>/</code>.
*: E.g <pre>rclone --exclude "/project/node_modules" project /some/other/dir/</pre>
* Add <code>--exclude</code> before <code>--stats</code> and <code>--delete</code> if you want it to work.
You can also use <code>--exclude-from</code> and point to a text file list of exclusions.
==Delete==
[https://superuser.com/questions/156664/what-are-the-differences-between-the-rsync-delete-options StackOverflow Differences between rsync delete]
Be very careful with deleting.
By default rsync only deletes files on the target which have the same name as files on the source.
Below are the relevent flags for deleting files on the target and the source.
The following two options deletes extraneous files on the target.
* <code>--delete</code> Delete files on the target directory which are not in the source.
* <code>--delete-excluded</code> Delete files on the target directory which are excluded in the transfer.
The following options concern replacing files on the target with the same name.
* <code>--delete-before</code> Deletes files on the target before new replacement is copied over. (default)
* <code>--delete-during</code> Deletes files on the target as replacement files with the same name are being copied over.
* <code>--del</code> Alias for <code>--delete-during</code>
* <code>--delete-delay</code> Marks files for deletion during transfer. Waits until the transfer is complete to delete files.
* <code>--delete-after</code> Checks for files and deletes files after transfer after the transfer.
The following option deletes files from the source directory.
* <code>--remove-source-files</code> Deletes files which have been synced.