Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ you first need to create an SSH key,
and add the public key to the backup server's
`/home/tech/.ssh/authorized_keys` file.
To do this, run the following commands
(replace `{host}` with the name of your host):
(replace `host.name.tld` with the name of your host):

```
export HOST={host} # enter the name of the host you want to backup here
export HOST=host.name.tld # enter the name of the host you want to backup here
ssh-keygen -q -t ed25519 -f /tmp/$HOST-backup -C $HOST-backup -N ""
scp hetzner-backup:.ssh/authorized_keys /tmp/hetzner-backup_authorized_keys
echo 'command="borg serve --restrict-to-path /home/backups/'$HOST'/",restrict' $(cat /tmp/$HOST-backup.pub) >> /tmp/hetzner-backup_authorized_keys
scp /tmp/hetzner-backup_authorized_keys hetzner-backup:.ssh/authorized_keys
```

Then upload the SSH key to your server (assuming we're logging in as root)
```
scp /tmp/$HOST-backup $HOST/.ssh/backupkey
scp /tmp/$HOST-backup.pub $HOST/.ssh/backupkey.pub
```

Now you need to generate a passphrase for the borg repository
with `pass generate -n delta/{host}/borg-passphrase`.
with ```
pass generate -n delta/${HOST}/borg-passphrase
```
This creates an alphanumeric passphrase for the repository.

Then you can add this module to your pyinfra deploy.py script like this:
Expand All @@ -36,18 +44,21 @@ from pyinfra import host
from pyinfra.facts.files import File
from pyinfra_borgbackup import deploy_borgbackup

host_name = "host"
borg_repo = f"hetzner-backup:backups/{host_name}"
host_name = "host.name.tld"
borg_repo = f"hetzner-backup:backups/host.name.tld"
borg_passphrase = "s3cr3t"
borg_initialized = host.get_fact(File, "/root/.ssh/backupkey")
deploy_borgbackup(host_name, borg_passphrase, borg_repo, borg_initialized)
```

After it has been deployed,
you should login to your host via SSH
and run `/root/backup.sh` manually at least once,
to create an initial backup
and directly spot possible mistakes.
After it has been deployed, you should login to your host via SSH.
Then, create the repository and create an initial backup and to directly spot possible mistakes.
```
sudo -i
set -o allexport; source backup.env; set +o allexport
borg init --encryption=repokey
./backup.sh
```

### Use Your Own Backup Server

Expand Down Expand Up @@ -118,7 +129,7 @@ If you pass a prometheus path to `deploy_borgbackup` like this:
```
deploy_borgbackup(
[...]
prometheus_file="/var/lib/node_exporter/textfile_collector/borgbackup_finished.prom",
prometheus_file="/var/lib/prometheus/node-exporter/borgbackup_finished.prom",
)
```

Expand Down
2 changes: 1 addition & 1 deletion pyinfra_borgbackup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def deploy_borgbackup(
:param borg_args: CLI arguments passed to borg create
:param skip_check: whether to skip `borg check` during ./backup.sh runs
:param prometheus_file: file to write prometheus success indicators to, e.g.
/var/lib/node_exporter/textfile_collector/borgbackup_finished.prom
/var/lib/prometheus/node-exporter/borgbackup_finished.prom
"""

secrets = [
Expand Down