forked from coop-cloud/backup-bot-two
feat: add retry option
This commit is contained in:
parent
faa7ae3dd1
commit
f730c70bfe
28
backupbot.py
28
backupbot.py
@ -91,12 +91,13 @@ def export_secrets():
|
|||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def create():
|
@click.option('retries', '--retries', '-r', envvar='RETRIES', default=1)
|
||||||
|
def create(retries):
|
||||||
pre_commands, post_commands, backup_paths, apps = get_backup_cmds()
|
pre_commands, post_commands, backup_paths, apps = get_backup_cmds()
|
||||||
copy_secrets(apps)
|
copy_secrets(apps)
|
||||||
backup_paths.append(SECRET_PATH)
|
backup_paths.append(SECRET_PATH)
|
||||||
run_commands(pre_commands)
|
run_commands(pre_commands)
|
||||||
backup_volumes(backup_paths, apps)
|
backup_volumes(backup_paths, apps, int(retries))
|
||||||
run_commands(post_commands)
|
run_commands(post_commands)
|
||||||
|
|
||||||
|
|
||||||
@ -180,15 +181,20 @@ def run_commands(commands):
|
|||||||
logger.info(result.output.decode())
|
logger.info(result.output.decode())
|
||||||
|
|
||||||
|
|
||||||
def backup_volumes(backup_paths, apps, dry_run=False):
|
def backup_volumes(backup_paths, apps, retries, dry_run=False):
|
||||||
try:
|
while True:
|
||||||
result = restic.backup(backup_paths, dry_run=dry_run, tags=apps)
|
try:
|
||||||
logger.summary("backup finished", extra=result)
|
result = restic.backup(backup_paths, dry_run=dry_run, tags=apps)
|
||||||
except ResticFailedError as error:
|
logger.summary("backup finished", extra=result)
|
||||||
logger.error(
|
return
|
||||||
f"Backup failed for {apps}. Could not Backup these paths: {backup_paths}")
|
except ResticFailedError as error:
|
||||||
logger.error(error, exc_info=True)
|
logger.error(
|
||||||
exit(1)
|
f"Backup failed for {apps}. Could not Backup these paths: {backup_paths}")
|
||||||
|
logger.error(error, exc_info=True)
|
||||||
|
if retries > 0:
|
||||||
|
retries -= 1
|
||||||
|
else:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user