borg backup scripts used on KrautSpace infra
Go to file
2024-02-20 22:18:53 +01:00
borg-backup@.service fix write permissions 2024-02-20 22:14:56 +01:00
borg-backup@.timer init 2023-04-04 23:36:20 +02:00
borg-prune@.service fix write permissions 2024-02-20 22:15:59 +01:00
borg-prune@.timer init 2023-04-04 23:36:20 +02:00 fix write permissions 2024-02-20 22:14:56 +01:00 port changes to 2024-02-20 22:18:53 +01:00 make scripts executable 2023-04-04 23:38:44 +02:00 make scripts executable 2023-04-04 23:38:44 +02:00
LICENSE Initial commit 2023-04-04 23:07:11 +02:00 too much backticks 2024-02-17 15:39:35 +01:00


borg backup scripte used on KrautSpace infra


sudo apt install borg



sudo ./ remote_site_1 --port=23 --login=whatever --directory=/home/borg

What this does:

  • Creates a config directory at /etc/borg/remote_site_1.
  • Creates a passphrase for borg.
  • Creates a ssh keypair for the ssh connection to your remote ssh backup destination host.
  • Deploys the ssk public key to the remote ssh account using ssh-copy-id.
  • Checks if the destination path is usable.
  • Initializes the borg repository.
  • Prints out the borg repository status if initialization was successfull.
  • Attempts to continue the init process if called multiple times.

Service installation

# on productive system: copy systemd-units in /etc/systemd/system
sudo ./

# on development system: link systemd-units from current directory
sudo ./

Service activation

sudo systemctl enable borg-backup@remote_site_1.timer
sudo systemctl enable borg-prune@remote_site_1.timer


Why so much sudo?

Good question!
The borg backup process requires priviledges to read everything you want to backup.
The systemd-units sandbox the borg process to a read-only view of the filesystem.

Can I trust this code?

Never trust anything from the internet.
Download and verify what it does. It should be somewhat readable.

How can I restore lost files?

You can manually connect to your borg repository. You'll need

  • location of your SSH key (SSH_KEY)
  • SSH user name (SSH_USER)
  • SSH host (SSH_HOST)
  • directory where the borg repo lives (BORG_REPO)
  • name of the borg repo (BORG_NAME) ` Use the following command to export a tar archive:

Borg will create a tar file with the name TAR_NAME and outputs all contents from the directory DIR_NAME into it.