forked from coop-cloud/backup-bot-two
change repo per option
This commit is contained in:
parent
3009159c82
commit
203719c224
15
backupbot.py
15
backupbot.py
@ -18,7 +18,8 @@ SERVICE = None
|
|||||||
@click.group()
|
@click.group()
|
||||||
@click.option('-l', '--log', 'loglevel')
|
@click.option('-l', '--log', 'loglevel')
|
||||||
@click.option('service', '--host', '-h', envvar='SERVICE')
|
@click.option('service', '--host', '-h', envvar='SERVICE')
|
||||||
def cli(loglevel, service):
|
@click.option('repository', '--repo', '-r', envvar='RESTIC_REPO', required=True)
|
||||||
|
def cli(loglevel, service, repository):
|
||||||
global SERVICE
|
global SERVICE
|
||||||
if service:
|
if service:
|
||||||
SERVICE = service.replace('.','_')
|
SERVICE = service.replace('.','_')
|
||||||
@ -27,12 +28,12 @@ def cli(loglevel, service):
|
|||||||
if not isinstance(numeric_level, int):
|
if not isinstance(numeric_level, int):
|
||||||
raise ValueError('Invalid log level: %s' % loglevel)
|
raise ValueError('Invalid log level: %s' % loglevel)
|
||||||
logging.basicConfig(level=numeric_level)
|
logging.basicConfig(level=numeric_level)
|
||||||
init_repo()
|
|
||||||
|
|
||||||
|
|
||||||
def init_repo():
|
|
||||||
export_secrets()
|
export_secrets()
|
||||||
restic.repository = os.environ['RESTIC_REPO']
|
init_repo(repository)
|
||||||
|
|
||||||
|
|
||||||
|
def init_repo(repository):
|
||||||
|
restic.repository = repository
|
||||||
restic.password_file = '/var/run/secrets/restic_password'
|
restic.password_file = '/var/run/secrets/restic_password'
|
||||||
try:
|
try:
|
||||||
restic.cat.config()
|
restic.cat.config()
|
||||||
@ -94,7 +95,7 @@ def run_commands(commands):
|
|||||||
logging.info(f"run command in {container.name}")
|
logging.info(f"run command in {container.name}")
|
||||||
logging.info(command)
|
logging.info(command)
|
||||||
if result.exit_code:
|
if result.exit_code:
|
||||||
logging.error(result.output.decode())
|
logging.error(f"Failed to run command {command} in {container.name}: {result.output.decode()}")
|
||||||
else:
|
else:
|
||||||
logging.info(result.output.decode())
|
logging.info(result.output.decode())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user