diff --git a/.gitignore b/.gitignore index 9e58681..4ffb437 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ __pycache__ *.egg-info -build/ \ No newline at end of file +build/ + +.env +key \ No newline at end of file diff --git a/README.md b/README.md index 377ed09..355abbc 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,32 @@ Purpose: - 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 +### Environment Variables -| 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` | +Put these in `./restic-scripts/.env`, which is on the `.gitignore` list. + +| Env Variable | Description | +| ------------------- | --------------------------------------------------------------------------------------- | +| `BACKUP_DIR` | Directory to back up | +| `RESTIC_REPOSITORY` | Directory for the restic repository. This is usually on a mount point made from Proxmox | +| `TZ` | Set to modify the timezone shown in the scheduler | + +### 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 +``` ## Loki Updates @@ -28,16 +43,14 @@ 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 ``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3aeaa43 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + backup: + image: creativeprojects/resticprofile + entrypoint: '/bin/sh' + command: + - -c + - 'crond && resticprofile-schedule.sh && inotifyd resticprofile-schedule.sh /etc/resticprofile:w' + 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 diff --git a/restic-profile.yaml b/restic-profile.yaml new file mode 100644 index 0000000..a1543e1 --- /dev/null +++ b/restic-profile.yaml @@ -0,0 +1,30 @@ + +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-before: 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 diff --git a/resticprofile-schedule.sh b/resticprofile-schedule.sh new file mode 100755 index 0000000..4ff1cfd --- /dev/null +++ b/resticprofile-schedule.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +resticprofile unschedule + +resticprofile schedule --all + +echo "Scheduled all restic profiles"