Step-by-step instructions on how to backup to Hetzner Storage Boxes using autorestic.
Installing autorestic Link to heading
The autorestic developers provide a simple one-liner to install autorestic and restic.
wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash
Create a dedicated SSH key for Hetzner Link to heading
Now we need to set up access to our storage box. We will use sftp/scp to do this. To automate the backup, we will create a dedicated ssh key for this:
ssh-keygen -t ed25519 -f ~/.ssh/storagebox
Then we need to lookup the server, username and password for our storagebox. With this information we can copy the key to the box:
export user=u123456
$ cat .ssh/storagebox.pub | ssh -p23 $user@$user.your-storagebox.de install-ssh-key
u123456@u123456.your-storagebox.de's password:
Key No. 1 (ssh-ed25519 root@v22021044222150411) was installed in RFC4716 format
Key No. 1 (ssh-ed25519 root@v22021044222150411) was installed in OpenSSH format
The above command will ask for the account password and then install the key.
Now we can ssh into the storagebox without having to enter a password:
export user=u123456
ssh -p23 -i .ssh/storagebox $user@$user.your-storagebox.de
Setting up the restic repository Link to heading
Since we are using a custom name for our ssh key, we need to make restic aware of it. The easiest way is to add the following snippet to .ssh/config
:
Host storagebox
Hostname $user.your-storagebox.de
Port 23
User $user
IdentityFile ~/.ssh/storagebox
Then we can run the following command to initialise our repository:
restic -r sftp://storagebox/restic init
Keep the repository password in a safe place.
Create the autorestic configuration Link to heading
version: 2
locations:
home:
from: /root
to: storagebox
backends:
storagebox:
type: sftp
path: storagebox:restic
key: your-key
Once the above is saved as .autorestic.yml
and the your-key
bit is replaced with your actual password, you can run your first backup using autorestic -av backup
.
Check if everything works Link to heading
Once the backup is complete, you can view your snapshot using:
restic -r sftp://storagebox/restic snapshots