2023-04-04 23:07:11 +02:00
|
|
|
# borg-backup-scripts
|
|
|
|
|
2023-04-05 20:17:06 +02:00
|
|
|
borg backup scripte used on KrautSpace infra
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
```
|
|
|
|
sudo apt install borg
|
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
### Initialization
|
|
|
|
|
|
|
|
```
|
|
|
|
sudo ./init.sh remote_site_1 --host=whatever.your-storagebox.de --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 ./install.sh
|
|
|
|
|
|
|
|
# on development system: link systemd-units from current directory
|
|
|
|
sudo ./install_as_link.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
### Service activation
|
|
|
|
|
|
|
|
```
|
|
|
|
sudo systemctl enable borg-backup@remote_site_1.timer
|
|
|
|
sudo systemctl enable borg-prune@remote_site_1.timer
|
|
|
|
```
|
|
|
|
|
|
|
|
## FAQ
|
|
|
|
|
|
|
|
### 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.
|
2024-02-17 15:38:05 +01:00
|
|
|
|
|
|
|
### 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:
|
|
|
|
|
2024-02-17 15:39:35 +01:00
|
|
|
```
|
2024-02-17 15:38:05 +01:00
|
|
|
BORG_RSH="ssh -i SSH_KEY" borg export-tar ssh://SSH_USER@SSH_HOST/BORG_REPO::BORG_NAME TAR_NAME DIR_NAME
|
|
|
|
```
|
2024-02-17 15:39:35 +01:00
|
|
|
|
2024-02-17 15:38:05 +01:00
|
|
|
Borg will create a tar file with the name `TAR_NAME` and outputs all contents from the directory `DIR_NAME` into it.
|