Skip to content
Snippets Groups Projects
Commit fdca3b52 authored by Alexander Detsch's avatar Alexander Detsch :elephant:
Browse files

fixed path configuration, improved readme

parent 1eade4cb
Branches
No related tags found
No related merge requests found
data/.cache/
data/.config/
data/.ssh/
data/repository/
data/*
.env
# Borgmatic Container
## updates
### install
## install
When you want to backup a server, you just have to follow these simple steps. Good luck! 😘
1. make sure, that you've enabled agent forwarding in your ssh-client (PuTTY: Connection --> SSH --> Auth --> enable "Allow agent forwarding")
2. `sudo mkdir /opt`
3. `cd /opt`
4. `sudo SSH_AUTH_SOCK=$SSH_AUTH_SOCK git clone <URL to this git>`
4. `sudo SSH_AUTH_SOCK=$SSH_AUTH_SOCK git clone https://bitbucket.alex-detsch.de/scm/alex-oe/borgmatic-automated.git`
5. `cd borgmatic-automated/`
6. `sudo cp .env-template .env`
7. edit `.env`-file
1. generate the passphrase for `BORG_PASSPHRASE` with: `cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 50 | head -n 1`
2. enter the correct alert-mail-password
2. if you want to use healthchecks.io-service, add also the URL
3. adapt the other variables in the first block to your needs
8. if you want to use healthchecks.io-service, edit `config.yaml-template` and add ` healthchecks: ` to the hooks-section with the provides URL following
8. edit `crontab.txt-template` for your scheduled backup time. Use the provided template line if you want to add extra lines
9. `sudo chmod +x ./initialSetup.sh && sudo ./initialSetup.sh`
1. agree to let the script to copy over the generated ssh-key or manually copy over the printed key
10. Copy the generated restore-zip-file to a safe place
11. Make sure to test your backups on a regular basis
12. relax, your backup should be fine
### restore
## restore
1. unzip the restore-zip-file
2. `cd keys-*`
3. `sudo chmod +x ./start-restore.sh && sudo ./start-restore.sh`
......@@ -38,46 +35,6 @@ A little container I wrote to automate my [Borgbackup](https://github.com/borgba
It uses cron to run the backups at a time you can configure in `data/borgmatic.d/crontab.txt`.
### Usage
To set your backup timing and configuration, you will need to create [crontab.txt](data/borgmatic.d/crontab.txt) and your borgmatic [config.yaml](data/borgmatic.d/config.yaml) and mount these files into the `/etc/borgmatic.d/` directory. When the container starts it creates the crontab from `crontab.txt` and starts crond. By cloning this repo in `/opt/docker/`, you will have a working setup to get started.
If using remote repositories mount your .ssh to /root/.ssh within the container.
If you want to mail the results from cron:
* Add your mail relay details to the [env file](.env.template) or mount your own [msmtprc](https://wiki.alpinelinux.org/wiki/Relay_email_to_gmail_(msmtp,_mailx,_sendmail) to `/etc/msmtprc`
* Add add your mail address to crontag.txt and uncomment the line, e.g. `MAILTO=log@example.com`
* Please note that logs will no longer end up in Docker logs when MAILTO is set.
### Example run command
```
docker run \
--detach --name borgmatic \
-v /home:/mnt/source:ro \
-v /opt/docker/docker-borgmatic/data/repository:/mnt/borg-repository \
-v /opt/docker/docker-borgmatic/data/borgmatic.d:/etc/borgmatic.d/ \
-v /opt/docker/docker-borgmatic/data/.borgmatic:/root/.borgmatic \
-v /opt/docker/docker-borgmatic/data/.config/borg:/root/.config/borg \
-v /opt/docker/docker-borgmatic/data/.ssh:/root/.ssh \
-v /opt/docker/docker-borgmatic/data/.cache/borg:/root/.cache/borg \
-e TZ=Europe/Berlin \
b3vis/borgmatic
```
While the parameters above are sufficient for regular backups, following additional privileges will be needed to mount an archive as FUSE filesystem:
```
--cap-add SYS_ADMIN \
--device /dev/fuse \
--security-opt label:disable \
--security-opt apparmor:unconfined
```
Depending on your security system, `--security-opt` parameters may not be neccessary. `label:disable` is needed for *SELinux*, while `apparmor:unconfined` is needed for *AppArmor*.
To init the repo with encryption, run:
```
docker exec borgmatic \
sh -c "borgmatic --init --encryption repokey-blake2"
```
### Layout
#### /mnt/source
Your data you wish to backup. For *some* safety you may want to mount read-only. Borgmatic is running as root so all files can be backed up.
......@@ -115,32 +72,3 @@ Where you can map your own `ntfy.yml` config to have Borgmatic send notification
- Username used to log in into your relay service `MAIL_USER=borgmatic_log@example.com`
- Password for relay login `MAIL_PASSWORD=SuperS3cretMailPw`
- From part in your log mail `MAIL_FROM=borgmatic`
### Docker Compose
- Prepare your configuration
1. `cp .env.template .env`
2. Set your environment and adapt volumes as needed
- To start the container for backup: `docker-compose up -d`
- For backup restore:
1. Stop the backup container: `docker-compose down`
2. Run an interactive shell: `docker-compose -f docker-compose.yml -f docker-compose.restore.yml run borgmatic`
3. Fuse-mount the backup: `borg mount /mnt/borg-repository <mount_point>`
4. Restore your files
5. Finally unmount and exit: `borg umount <mount_point> && exit`.
- In case Borg fails to create/acquire a lock: `borg break-lock /mnt/repository`
### ntfy
I've decided to add [ntfy](https://github.com/dschep/ntfy) to this container to be able to recive push notifications regarding backups within Borgmatic.
Mount your own `ntfy.yml` to `/root/.config/ntfy/ntfy.yml` to set your backends for ntfy. Alternatively you can interactively send notifications via a command with API keys in line. I've opted to just map my own `ntfy.yml`
#### Example for your borgmatic config.yml
```
hooks:
before_backup:
- ntfy -b pushover -t Borgmatic send "Borgmatic: Backup Starting"
after_backup:
- ntfy -b pushover -t Borgmatic send "Borgmatic: Backup Finished"
on_error:
- ntfy -b pushover -t Borgmatic send "Borgmatic: Backup Error!"
```
\ No newline at end of file
......@@ -24,8 +24,9 @@ pip3 install --upgrade borgmatic
#pip3 install --upgrade borgbackup==${BORG_VERSION}
#pip3 install --upgrade borgmatic==${BORGMATIC_VERSION}
chmod +x processFile.sh
chmod +x ./processFile.sh
chmod +x ./createConfigZip.sh
chmod +x ./start-restore.sh
mkdir -p ${VOLUME_SOURCE}
if [ $BORG_PASSPHRASE == "ReplaceWithYourSecretPassPhrase" ]
......@@ -59,15 +60,23 @@ ssh-keyscan -t rsa -T 10 -p ${SSH_BACKUP_PORT} ${SSH_BACKUP_HOST} >> ${VOLUME_SS
# make dirs
mkdir -p ${VOLUME_ETC_BORGMATIC}
mkdir -p ${VOLUME_BORG_CONFIG}
mkdir -p ${VOLUME_BORG_CACHE}
# set needed variables
export SSH_KEY_PATH=$(realpath ${VOLUME_SSH}/id_rsa)
export BORGMATIC_CONFIG_FILE=$(realpath ${VOLUME_ETC_BORGMATIC}/config.yaml)
export BORG_CONFIG_DIR=$(realpath ${VOLUME_BORG_CONFIG})
export BORG_KEYS_DIR=$(realpath ${VOLUME_BORG_CONFIG}/keys)
export BORG_SECURITY_DIR=$(realpath ${VOLUME_BORG_CONFIG}/security)
export BORG_KEYS_DIR=$(realpath ${VOLUME_BORG_CONFIG})/keys
export BORG_SECURITY_DIR=$(realpath ${VOLUME_BORG_CONFIG})/security
export BORG_CACHE_DIR=$(realpath ${VOLUME_BORG_CACHE})
mkdir -p ${BORG_CONFIG_DIR}
mkdir -p ${BORG_KEYS_DIR}
mkdir -p ${BORG_SECURITY_DIR}
mkdir -p ${BORG_CACHE_DIR}
# ok, let's fire this up!
./processFile.sh "./.env" "./config.yaml-template" "${VOLUME_ETC_BORGMATIC}/config.yaml"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment