# Guide: Remote backup of MiaB using an Rsync host

**URL:** <https://discourse.mailinabox.email/t/guide-remote-backup-of-miab-using-an-rsync-host/9180>\
**Category:** Guides\
**Created:** [June 6, 2022, 4:16am UTC](https://discourse.mailinabox.email/t/guide-remote-backup-of-miab-using-an-rsync-host/9180 "2022-06-06T04:16:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![openletter](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/o/f1d935/32.png) [@openletter](https://discourse.mailinabox.email/u/openletter)\
**Post date:** [June 6, 2022, 4:16am UTC](https://discourse.mailinabox.email/t/guide-remote-backup-of-miab-using-an-rsync-host/9180/1 "2022-06-06T04:16:59Z")

</div>

This guide configures MiaB as a source server for synchronization of the encrypted backup files using `rsync` from a remote host that will not have permissions to access anything else on MiaB or delete any of the backup files.

On the MiaB ‘Backup Status’ page in the dashboard, the ‘Backup to:’ setting is selected to `box.example.net`.

The tool used in MiaB is [`rrsync`](https://download.samba.org/pub/rsync/rrsync.1), “a script to setup restricted rsync users via ssh logins” that is included with `rsync`.

In Ubuntu 18.04, `rrsync` is not configured for use. The following commands will add `rrsync` to the available commands in the same way it is implemented in Ubuntu 22.04.

```plaintext
sudo mkdir -p /usr/share/rsync/scripts/
zcat /usr/share/doc/rsync/scripts/rrsync.gz | sudo tee /usr/share/rsync/scripts/rrsync >/dev/null
sudo chmod 755 /usr/share/rsync/scripts/rrsync
sudo ln -rs /usr/share/rsync/scripts/rrsync /usr/bin/rrsync

```

Create a user on MiaB that the remote host server will use to log into MiaB.

```
sudo adduser rsync-user

```

Open `authorized_keys` for editing:

```
sudo nano /home/rsync-user/.ssh/authorized_keys

```

Using a unique user to perform the synchronization allows use of any available SSH keypair from the remote host to be used for authentication of `rsync-user` on MiaB. Add the key with the following options:

```
command="/usr/bin/rrsync -ro /home/user-data/backup/encrypted/",restrict [ssh-rsa,ssh-ed25519,ecdsa-sha2-nistp521,etc] AAAAB0C...

```

From `man ssh`:

> **comand=“command”**
> 
> Specifies that the command is executed whenever this key is used for authentication. The command supplied by the user (if any) is ignored. The command is run on a pty if the client requests a pty; otherwise it is run without a tty. If an 8-bit clean channel is required, one must not request a pty or should specify no-pty. A quote may be included in the command by quoting it with a backslash.

> **restrict**
> 
> Enable all restrictions, i.e. disable port, agent and X11 forwarding, as well as disabling PTY allocation and execution of ~/.ssh/rc. If any future restriction capabilities are added to authorized\_keys files they will be included in this set.

The `-ro` option means that `rrsync` will allow only reading from the directory.

What this means is that the remote host server can only run the configured `rrsync` command, `rrsync` will only allow `rsync` to read, and only the configured directory can be accessed.

This tutorial doesn’t go very far to instruct on how to configure `rsync` on the remote host machine as systems and configurations can vary greatly. Adding this to `cron` job (e.g., `crontab -e` with the remote host user that performs the `rsync`) in Debian-based Linux distributions (check `crontab(5)` if you are on something else) would keep a local version of the files currently on MiaB:

```
30 3 * * * rsync -a --delete rsync-user@box.example.net:/ /backup/directory/

```

Note that `rrsync` will treat `/home/user-data/backup/encrypted/` as the root directory for the remote host server, so the command only includes `/` as the source location.

The `-a` option is archive mode which uses a suitable and common selection of options for this purpose (`-rlptgoD`). The `--delete` option deletes files from the remote host server directory that are not on MiaB.

Feedback, corrections and questions are much appreciated.

---

<div class="post-metadata">

**Author:** ![KiekerJan](https://discourse.mailinabox.email/user_avatar/discourse.mailinabox.email/kiekerjan/32/2339_2.png) [@KiekerJan](https://discourse.mailinabox.email/u/KiekerJan)\
**Post date:** [June 6, 2022, 8:48am UTC](https://discourse.mailinabox.email/t/guide-remote-backup-of-miab-using-an-rsync-host/9180/2 "2022-06-06T08:48:31Z")

</div>

Nice writeup 👍🏻  
To make it more dummy proof I suggest:

- Indicating where you get the key you add to authorized\_keys (I presume the AAAAB0C… is the place where you insert the key)
- Note explicitly that `crontab` is a file under `/etc` on the **host** computer, not the MiaB box (had to read it twice 😉 )

---

<div class="post-metadata">

**Author:** ![openletter](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/o/f1d935/32.png) [@openletter](https://discourse.mailinabox.email/u/openletter)\
**Post date:** [June 6, 2022, 12:14pm UTC](https://discourse.mailinabox.email/t/guide-remote-backup-of-miab-using-an-rsync-host/9180/3 "2022-06-06T12:14:01Z")

</div>

I did a few edits and added the command for `crontab`, as that is the best way to edit that file.
