#+SETUPFILE: ../../../template/level-2.org
#+OPTIONS: ^:nil _:nil toc:auto
#+TITLE: How to use rsync
#+DATE: <2021-02-05 Fri 22:15>
#+AUTHOR: vaeringjar
#+EMAIL: vaeringjar@land
#+DESCRIPTION: How to use rsync
#+KEYWORDS: howto rsync


* Most common use cases

The following use cases sum up what I do the most with rsync. I
personally use it mostly for pushing content.


** Update a remote

The following shows how to update the remote content, for example, for
a blog. It removes the old, adds the new, and leaves things only on
the remote. Just replace the path for remote with the host and path
for the blog.

#+BEGIN_SRC bash
me@here:~/$ ./demo 
#!/usr/bin/env bash
set -e
set -u
set -o pipefail


cat demo

echo "Run the demo..."

mkdir temp \
    && cd temp \
    && mkdir local \
    && mkdir remote \
    && touch local/foo \
    && touch local/bar \
    && touch remote/old \
    && mkdir remote/.well-known \
    && tree -a \
    && rsync -avh --delete --exclude=".well-known" local/ remote/ \
    && tree -a \
    && cd .. \
    && rm -r temp \
        || echo "failed"

# end of demo
Run the demo...
.
├── local
│   ├── bar
│   └── foo
└── remote
    ├── old
    └── .well-known

3 directories, 3 files
sending incremental file list
deleting old
bar
foo

sent 178 bytes  received 61 bytes  478.00 bytes/sec
total size is 0  speedup is 0.00
.
├── local
│   ├── bar
│   └── foo
└── remote
    ├── bar
    ├── foo
    └── .well-known

3 directories, 4 files
#+END_SRC


** Use a specific ID

Sometimes I have an ssh key that I use. The following sums up how I
specify that key and specify a port. I'll hope someone knows a better
way and lets me know some day.

#+BEGIN_SRC bash
rsync -avh -e "ssh -i $HOME/.ssh/id_file_here -p 4321" --delete local/ username@0.0.0.0:/path/
#+END_SRC
