backup-bot-two/README.md

129 lines
4.3 KiB
Markdown
Raw Permalink Normal View History

2021-11-21 19:23:23 +00:00
# Backupbot II
2021-10-25 11:56:49 +00:00
Wiki Cafe's configuration for a Backupbot II deployment. Originally slimmed down from an `abra` [recipe](https://git.coopcloud.tech/coop-cloud/backup-bot-two) by [Co-op Cloud](https://coopcloud.tech/).
2021-11-10 22:18:50 +00:00
2021-11-21 19:23:23 +00:00
## Deploying the app with Docker Swarm
2021-10-25 11:56:49 +00:00
Set the environment variables from the .env file during the shell session.
2023-09-07 13:26:29 +00:00
2023-09-07 11:44:38 +00:00
```
set -a && source .env && set +a
2023-09-07 11:44:38 +00:00
```
Set the secrets.
2023-09-07 11:44:38 +00:00
2023-09-07 23:16:44 +00:00
```
printf "SECRET_HERE" | docker secret create SECRET_NAME -
2023-09-07 23:16:44 +00:00
```
2023-09-07 11:44:38 +00:00
Deploy using the `-c` flag to specify one or multiple compose files.
2023-10-03 20:39:06 +00:00
```
docker stack deploy backup-bot-two -c compose.yaml
2023-10-03 20:39:06 +00:00
```
2023-09-07 11:44:38 +00:00
2024-01-16 18:27:58 +00:00
## Push notifications
The following env variables can be used to setup push notifications for backups. `PUSH_URL_START` is requested just before the backups starts, `PUSH_URL_SUCCESS` is only requested if the backup was successful and if the backup fails `PUSH_URL_FAIL` will be requested.
Each variable is optional and independent of the other.
```
PUSH_URL_START=https://status.example.com/api/push/xxxxxxxxxx?status=up&msg=start
PUSH_URL_SUCCESS=https://status.example.com/api/push/xxxxxxxxxx?status=up&msg=OK
PUSH_URL_FAIL=https://status.example.com/api/push/xxxxxxxxxx?status=down&msg=fail
```
## Commands
2024-01-16 18:27:58 +00:00
2023-09-07 11:44:38 +00:00
- Find the ID or name of the backup container:
```
docker ps --filter "name=backup-bot-two_app"
```
2023-09-07 11:44:38 +00:00
2. Run the desired command using `docker exec`:
```
docker exec -it <container_id_or_name> backup <command> [options]
```
Replace `<container_id_or_name>` with the ID or name of the backup container.
2023-09-07 11:44:38 +00:00
Available commands:
- `create`: Initiate the backup process.
- `restore`: Restore a specific snapshot to a target directory.
- `snapshots`: List available snapshots.
- `ls`: List files in a specific snapshot.
- `download`: Download specific files, volumes, or secrets from a snapshot.
2023-09-07 11:44:38 +00:00
Options:
- `--host`, `-h`: Specify the service name (e.g., `app`).
- `--repo`, `-r`: Specify the Restic repository location (e.g., `/run/secrets/restic_repo`).
- `--log`, `-l`: Set the log level (e.g., `debug`, `info`, `warning`, `error`).
- `--machine-logs`, `-m`: Enable machine-readable JSON logging.
2023-09-07 11:44:38 +00:00
## Examples
2023-09-07 11:44:38 +00:00
Create a backup:
2023-09-07 11:44:38 +00:00
```
docker exec -it <container_id_or_name> backup create --host app
```
2023-09-07 11:44:38 +00:00
Restore a snapshot:
2023-09-07 11:44:38 +00:00
```
docker exec -it <container_id_or_name> backup restore --snapshot <snapshot_id> --target /path/to/restore
```
2023-09-07 11:44:38 +00:00
List snapshots:
2023-09-07 11:44:38 +00:00
```
docker exec -it <container_id_or_name> backup snapshots
```
2023-09-07 11:44:38 +00:00
List files in a snapshot:
2023-09-07 11:44:38 +00:00
```
docker exec -it <container_id_or_name> backup ls --snapshot <snapshot_id> --path /path/to/directory
```
2023-09-07 11:44:38 +00:00
Download files, volumes, or secrets from a snapshot:
2023-09-07 11:44:38 +00:00
```
docker exec -it <container_id_or_name> backup download --snapshot <snapshot_id> [--path /path/to/file] [--volumes] [--secrets]
```
2023-09-07 11:44:38 +00:00
Note: Make sure to replace `<container_id_or_name>` and `<snapshot_id>` with the appropriate values for your setup.
2023-09-07 11:44:38 +00:00
Remember to review and adjust the Docker Compose file and environment variables according to your specific requirements before running the backup commands.
2023-09-07 13:32:57 +00:00
When using `docker exec`, you don't need to specify the volume mounts or the Restic repository location as command-line arguments because they are already defined in the Docker Compose file and are available within the running container.
2023-09-07 11:44:38 +00:00
If you need to access the downloaded files, volumes, or secrets from the backup, you can use `docker cp` to copy them from the container to the host machine:
2023-09-07 11:44:38 +00:00
```
docker cp <container_id_or_name>:/path/to/backup/file /path/on/host
2023-09-07 11:44:38 +00:00
```
This allows you to retrieve the backed-up data from the container.
2023-09-07 11:44:38 +00:00
## Recipe Configuration
Backupbot II uses access to the Docker socket to read labels from running Docker Swarm services:
2021-10-25 11:56:49 +00:00
```
services:
db:
2021-10-25 11:56:49 +00:00
deploy:
labels:
backupbot.backup: ${BACKUP:-"true"}
backupbot.backup.pre-hook: 'mysqldump -u root -p"$(cat /run/secrets/db_root_password)" -f /volume_path/dump.db'
backupbot.backup.post-hook: "rm -rf /volume_path/dump.db"
2021-10-25 11:56:49 +00:00
```
2021-11-10 22:18:50 +00:00
- `backupbot.backup` -- set to `true` to back up this service (REQUIRED)
- `backupbot.backup.pre-hook` -- command to run before copying files (optional), save all dumps into the volumes
2021-11-10 22:18:50 +00:00
- `backupbot.backup.post-hook` -- command to run after copying files (optional)
As in the above example, you can reference Docker Secrets, e.g. for looking up database passwords, by reading the files in `/run/secrets` directly.