Compare commits

...

7 Commits

Author SHA1 Message Date
John Lancaster
e6f5ee38e5 added crond command for reference 2024-06-15 15:11:26 -05:00
John Lancaster
cf63a16f6b readme update 2024-06-15 15:11:26 -05:00
John Lancaster
97757bff44 readme update 2024-06-15 15:11:26 -05:00
John Lancaster
a6c089a191 did away with the inotifyd nonsense 2024-06-15 15:11:26 -05:00
John Lancaster
7123ccada7 added notes for the key 2024-06-15 15:11:26 -05:00
John Lancaster
4c8b57dd16 initial move to resticprofile 2024-06-15 15:11:26 -05:00
John Lancaster
326d2c0910 added to gitignore 2024-06-15 15:08:05 -05:00
5 changed files with 115 additions and 17 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,6 @@
__pycache__
*.egg-info
build/
.env
key

View File

@@ -2,23 +2,52 @@
Purpose:
> [!WARNING]
> This behvior does not work on the `resticprofile` branch
- Wrap `restic` with the ability to start/stop Docker containers
- Send updates to Loki server
## Environment Variables
## Installation
Recommended to put these in the relevant `~/.bashrc` file
### Include in Repo
From a parent repo, add this one as a submodule:
```shell
git submodule add https://gitea.john-stream.com/john/restic-scripts
```
Then add this to the `docker-compose.yml` file of the parent.
```yaml
include:
- restic-scripts/docker-compose.yml
```
### Environment Variables
Put these in `./restic-scripts/.env`, which is on the `.gitignore` list.
| Env Variable | Description |
|---------------------|--------------------------------------------------------------------------------------------|
| `HOSTNAME` | Network hostname of where the backup is running. Used to tag the backups in restic |
| ------------------- | --------------------------------------------------------------------------------------- |
| `BACKUP_DIR` | Directory to back up |
| `RESTIC_REPOSITORY` | Directory for the restic repository. This is usually on a mount point made from Proxmox |
| `RESTIC_PASSWORD` | Password for the restic repository |
| `LOKI_URL` | Push URL for Loki. Should include the port and end with something like `/loki/api/v1/push` |
| `TZ` | Set to modify the timezone shown in the scheduler |
### Key file
The password needs to be stored in `./restic-scripts/key`. Make sure it has the right (secure) permissions.
```shell
sudo chown root:root ./restic-scripts/key && sudo chmod 600 ./restic-scripts/key
```
## Loki Updates
> [!WARNING]
> This doesn't currently work on the `resticprofile` branch
Updates sent to Loki will have the following labels:
| Label | Description |
@@ -28,16 +57,28 @@ Updates sent to Loki will have the following labels:
## Usage
```shell
python -m restic.snapshots
```
To stop docker containers before the backup and start them again afterwards, use the `--project` and `--services` flags.
Check snapshots
```shell
python -m restic.backup --tag manual --project joplin --services app,db
docker compose exec backup resticprofile snapshots
```
Dry-run a backup
```shell
python -m restic.prune
docker compose exec backup resticprofile --dry-run backup
```
Check crontab entry in container
```shell
docker compose exec backup cat /var/spool/cron/crontabs/root
```
### Crond
Crond command when scheduled using `resticprofile schedule --all`
```shell
cd /resticprofile && /usr/bin/resticprofile --no-ansi --config /etc/resticprofile/profiles.yaml --name default backup
```

16
docker-compose.yml Normal file
View File

@@ -0,0 +1,16 @@
services:
backup:
image: creativeprojects/resticprofile
entrypoint: '/bin/sh'
command:
- -c
- 'resticprofile-schedule.sh && crond -f'
env_file:
- .env
hostname: ${HOSTNAME}
volumes:
- ./restic-profile.yaml:/etc/resticprofile/profiles.yaml:ro
- ./resticprofile-schedule.sh:/usr/local/bin/resticprofile-schedule.sh:ro
- ./key:/etc/resticprofile/key:ro
- ${BACKUP_DIR}:${BACKUP_DIR}:ro
- ${RESTIC_REPOSITORY}:${RESTIC_REPOSITORY}:rw

29
restic-profile.yaml Normal file
View File

@@ -0,0 +1,29 @@
global:
scheduler: crond
default:
base-dir: ${BACKUP_DIR}
repository: local:${RESTIC_REPOSITORY}
password-file: key
initialize: true
backup:
source: ./
exclude-caches: true
one-file-system: true
schedule: "*:00"
schedule-permission: system
check-after: true
tag:
- resticprofile
retention:
after-backup: true
before-backup: false
prune: true
tag:
- resticprofile
keep-within: 3h
keep-hourly: 72
keep-daily: 14
keep-weekly: 8
keep-monthly: 6

9
resticprofile-schedule.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
set -e
resticprofile unschedule > /dev/null
resticprofile schedule --all
echo "Scheduled all restic profiles"