From 093dab93cab41a11db308854fb65971746c68bd6 Mon Sep 17 00:00:00 2001 From: einarf Date: Fri, 5 Jan 2024 03:50:13 +0100 Subject: [PATCH] Make rcb dump env vars to properly escape them --- src/entrypoint.sh | 2 +- src/restic_compose_backup/__init__.py | 2 +- src/restic_compose_backup/cli.py | 12 ++++++++++++ src/setup.py | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index a223b7b..21c31e8 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh # Dump all env vars so we can source them in cron jobs -printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh +rcb dump-env > /env.sh # Write crontab rcb crontab > crontab diff --git a/src/restic_compose_backup/__init__.py b/src/restic_compose_backup/__init__.py index ef7eb44..f0788a8 100644 --- a/src/restic_compose_backup/__init__.py +++ b/src/restic_compose_backup/__init__.py @@ -1 +1 @@ -__version__ = '0.6.0' +__version__ = '0.7.1' diff --git a/src/restic_compose_backup/cli.py b/src/restic_compose_backup/cli.py index fb8cbce..8675a7f 100644 --- a/src/restic_compose_backup/cli.py +++ b/src/restic_compose_backup/cli.py @@ -51,6 +51,9 @@ def main(): elif args.action == "crontab": crontab(config) + elif args.action == "dump-env": + dump_env() + # Random test stuff here elif args.action == "test": nodes = utils.get_swarm_nodes() @@ -290,6 +293,14 @@ def crontab(config): print(cron.generate_crontab(config)) +def dump_env(): + """Dump all environment variables to a script that can be sourced from cron""" + print("#!/bin/bash") + print("# This file was generated by restic-compose-backup") + for key, value in os.environ.items(): + print("export {}='{}'".format(key, value)) + + def parse_args(): parser = argparse.ArgumentParser(prog='restic_compose_backup') parser.add_argument( @@ -303,6 +314,7 @@ def parse_args(): 'cleanup', 'version', 'crontab', + 'dump-env', 'test', ], ) diff --git a/src/setup.py b/src/setup.py index 1375b36..13b7e54 100644 --- a/src/setup.py +++ b/src/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_namespace_packages setup( name="restic-compose-backup", url="https://github.com/ZettaIO/restic-compose-backup", - version="0.7.0", + version="0.7.1", author="Einar Forselv", author_email="eforselv@gmail.com", packages=find_namespace_packages(include=[