Compare commits
2 Commits
84d606fa80
...
8acdb20e5b
Author | SHA1 | Date |
---|---|---|
Moritz | 8acdb20e5b | |
Moritz | 5582744073 |
14
backupbot.py
14
backupbot.py
|
@ -42,7 +42,7 @@ sys.excepthook = handle_exception
|
|||
@click.option('-l', '--log', 'loglevel')
|
||||
@click.option('-m', '--machine-logs', 'machine_logs', is_flag=True)
|
||||
@click.option('service', '--host', '-h', envvar='SERVICE')
|
||||
@click.option('repository', '--repo', '-r', envvar='RESTIC_REPOSITORY', required=True)
|
||||
@click.option('repository', '--repo', '-r', envvar='RESTIC_REPOSITORY')
|
||||
def cli(loglevel, service, repository, machine_logs):
|
||||
global SERVICE
|
||||
if service:
|
||||
|
@ -54,21 +54,25 @@ def cli(loglevel, service, repository, machine_logs):
|
|||
if not isinstance(numeric_level, int):
|
||||
raise ValueError('Invalid log level: %s' % loglevel)
|
||||
logger.setLevel(numeric_level)
|
||||
logHandler = logging.StreamHandler()
|
||||
if machine_logs:
|
||||
logHandler = logging.StreamHandler()
|
||||
formatter = jsonlogger.JsonFormatter(
|
||||
"%(levelname)s %(filename)s %(lineno)s %(process)d %(message)s", rename_fields={"levelname": "message_type"})
|
||||
logHandler.setFormatter(formatter)
|
||||
logger.addHandler(logHandler)
|
||||
logger.addHandler(logHandler)
|
||||
|
||||
export_secrets()
|
||||
init_repo()
|
||||
|
||||
|
||||
def init_repo():
|
||||
repo = os.environ['RESTIC_REPOSITORY']
|
||||
if repo:= os.environ['RESTIC_REPOSITORY_FILE']:
|
||||
# RESTIC_REPOSITORY_FILE and RESTIC_REPOSITORY are mutually exclusive
|
||||
del os.environ['RESTIC_REPOSITORY']
|
||||
else:
|
||||
repo = os.environ['RESTIC_REPOSITORY']
|
||||
restic.repository = repo
|
||||
logger.debug(f"set restic repository location: {repo}")
|
||||
restic.repository = repo
|
||||
restic.password_file = '/var/run/secrets/restic_password'
|
||||
try:
|
||||
restic.cat.config()
|
||||
|
|
Loading…
Reference in New Issue