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.option('-l', '--log', 'loglevel')
|
||||
@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
|
||||
if service:
|
||||
SERVICE = service.replace('.','_')
|
||||
|
@ -27,12 +28,12 @@ def cli(loglevel, service):
|
|||
if not isinstance(numeric_level, int):
|
||||
raise ValueError('Invalid log level: %s' % loglevel)
|
||||
logging.basicConfig(level=numeric_level)
|
||||
init_repo()
|
||||
|
||||
|
||||
def init_repo():
|
||||
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'
|
||||
try:
|
||||
restic.cat.config()
|
||||
|
@ -94,7 +95,7 @@ def run_commands(commands):
|
|||
logging.info(f"run command in {container.name}")
|
||||
logging.info(command)
|
||||
if result.exit_code:
|
||||
logging.error(result.output.decode())
|
||||
logging.error(f"Failed to run command {command} in {container.name}: {result.output.decode()}")
|
||||
else:
|
||||
logging.info(result.output.decode())
|
||||
|
||||
|
|
Loading…
Reference in New Issue