Skip to content

Commit

Permalink
Make rcb dump env vars to properly escape them
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf committed Jan 5, 2024
1 parent 405bd4a commit 093dab9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/restic_compose_backup/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.6.0'
__version__ = '0.7.1'
12 changes: 12 additions & 0 deletions src/restic_compose_backup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -303,6 +314,7 @@ def parse_args():
'cleanup',
'version',
'crontab',
'dump-env',
'test',
],
)
Expand Down
2 changes: 1 addition & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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=[
Expand Down

0 comments on commit 093dab9

Please sign in to comment.