From 5fa8f821c156b1701d61003a0f96c707a5b9a0cb Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 7 Sep 2023 13:10:10 +0200 Subject: [PATCH] choos specific restore target --- backupbot.py | 13 +++++++++---- compose.yml | 2 +- entrypoint.sh | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/backupbot.py b/backupbot.py index e131e54..9932dde 100755 --- a/backupbot.py +++ b/backupbot.py @@ -4,7 +4,6 @@ import os import click import json import subprocess -# todo json logging import logging import docker import restic @@ -106,9 +105,15 @@ def backup_volumes(backup_paths, apps, dry_run=False): @cli.command() @click.option('snapshot', '--snapshot', '-s', envvar='SNAPSHOT', default='latest') -def restore(snapshot): - service_paths = f'/var/lib/docker/volumes/{SERVICE}_*' - result = restic.restore(snapshot_id=snapshot, include=service_paths, target_dir='/') +@click.option('target', '--target', '-t', envvar='TARGET', default='/') +def restore(snapshot, target): + # Todo: recommend to shutdown the container + service_paths = VOLUME_PATH + if SERVICE: + service_paths = service_paths + f'{SERVICE}_*' + print(f"restoring Snapshot {snapshot} of {service_paths} at {target}") + result = restic.restore(snapshot_id=snapshot, include=service_paths, target_dir=target) + logging.debug(result) @cli.command() diff --git a/compose.yml b/compose.yml index a25b3f3..2f1c682 100644 --- a/compose.yml +++ b/compose.yml @@ -21,7 +21,7 @@ services: target: /entrypoint.sh mode: 0555 - source: backupbot - target: /backup + target: /usr/bin/backup mode: 0555 entrypoint: ['/entrypoint.sh'] diff --git a/entrypoint.sh b/entrypoint.sh index 94ba3c3..3ed47d0 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,14 +2,14 @@ set -eu -apk add --upgrade --no-cache bash curl jq restic python3 py3-pip +apk add --upgrade --no-cache bash restic python3 py3-pip -# Todo use requirements file +# Todo use requirements file with specific versions pip install click docker resticpy cron_schedule="${CRON_SCHEDULE:?CRON_SCHEDULE not set}" -#echo "$cron_schedule /backupbot.py" | crontab - +echo "$cron_schedule backup create" | crontab - crontab -l crond -f -d8 -L /dev/stdout