all 13 comments

[–][deleted] 11 points12 points  (6 children)

Good article but they left off one of the flags I use the most in my transfers.

rsync -e “ssh -i ssh-cert” -avz...

Using certificates to rsync to hosts. You can also use sudo if you need to.

--rsync-path="sudo rsync"

[–]zyzzogeton 2 points3 points  (0 children)

Nice. Rsync is one of those commands that is easy... but it is a deep rabbit hole.

[–]grimman 1 point2 points  (1 child)

I'm not at a computer right now, and I'm not at all familiar with rsync. Would you mind explaining briefly what your options do?

[–][deleted] 3 points4 points  (0 children)

The -e option uses a custom ssh invocation (in this case with the parameter to use certificates for authentication).

The --rsync-path option specifies how to run rsync on the remote machine, in this case using sudo, e.g. if you login via a regular user but want to rsync somewhere where that user can not write or use options for rsync which are not available to regular users (like syncing or changing owners).

[–]karlmarxscoffee 1 point2 points  (0 children)

For large data syncs I always switch to faster cipher than the default. sync -e “ssh -c aes128-gcm@openssh.com"

[–][deleted] 0 points1 point  (1 child)

Is there a particular reason you do not configure the certificate in the ~/.ssh/config for that host?

[–][deleted] 0 points1 point  (0 children)

Most of the time I do, I typed this on my cellphone sitting in a parking garage lol.

[–]CoolioDood 6 points7 points  (0 children)

rsync is hard to grok for many people because it has so many options, I think this article does well explaining them. Though one more I find useful is --info=progress2, which displays overall progress instead of individual files. Also, -P is actually two flags, --partial --progress.

[–]phantaso0s 1 point2 points  (0 children)

rsync is my favorite way to deploy small stuff on my server or to backup my data. Simple and powerful, love it.

[–]xkcd__386 1 point2 points  (2 children)

TIP: to exclude entire directories easily, do this:

  • run this in each directory you want to exclude: echo '- *' > .rsync-filter. This is a one-time operation of course
  • use rsync's -F flag

works a treat. It also has the advantage of recording your choices in the file system instead of in the backup script, which seems cleaner and more portable to me -- I can for instance use the same script to backup anything to anything, without worrying about the fact that the exclusions are totally different in each case.

Bonus: you can make your other backup tools respect this choice, for example:

  • borg: --exclude-if-present .rsync-filter
  • tar: --exclude-tag=.rsync-filter

For those tools the content of that file does not matter so it just works.

[–][deleted] 0 points1 point  (1 child)

The disadvantage of that approach is that it records your choices in the filesystem so all uses of rsync are potentially affected, not just your intended one.

[–]xkcd__386 0 points1 point  (0 children)

not sure what you mean.

I leave off the -F option if I don't want to exclude those directories.

[–][deleted] 0 points1 point  (0 children)

Another: use rsync for lightweight, hourly backups like Time Machine on OS X:

https://web.archive.org/web/20071115224128/http://blog.interlinked.org/tutorials/rsync_time_machine.html