Skip to content

Instantly share code, notes, and snippets.

@ayroblu
Last active February 3, 2017 12:20
Show Gist options
  • Save ayroblu/de86e3041b2294944a0273b905551c6f to your computer and use it in GitHub Desktop.
Save ayroblu/de86e3041b2294944a0273b905551c6f to your computer and use it in GitHub Desktop.
How to rsync so that you get the directories right (such as when I do a deploy)

Rsync Tutorial

How to use it without tossing files everywhere

Important options

  • -a archive, use this if recursive + 'preserves symbolic links, special and device files, modification times, group, owner, and permissions'
  • -n Dry run - don't do anything
  • --delete Delete files that aren't in source
  • -t Preserve modification times (I think?)
  • -v Increase verbosity
  • -q Suppress non-error messages
  • -P Keep partially transfered, and show progress. When I use this, I don't think -v helps?
  • -h Human readable
  • -z Compress - use for text files maybe?
  • --exclude= Exclude based on pattern (comma separated list)
  • --include= Include based on pattern (comma separated list)

Setup

file structure

- a
> - thing.txt
- b

Tests

rsync -a a b

- a
> - thing.txt
- b
  - a
  > - thing.txt

rsync -a a b/

- a
> - thing.txt
- b
  - a
  > - thing.txt

rsync -a a/ b/

- a
> - thing.txt
- b
> - thing.txt

rsync -a a/ b

- a
> - thing.txt
- b
> - thing.txt

rsync -a a/* b

- a
> - thing.txt
- b
> - thing.txt

rsync -a a b

>>>Before
- a
> - thing.txt
- b
  - a
  > - hi.txt
=========
- a
> - thing.txt
- b
  - a
  > - hi.txt
  > - thing.txt
<<<After
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment