From 57645987245b4a138abe0e8e8fb0464c920bc2d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20L=C3=B6sche?= Date: Wed, 17 Jul 2024 12:12:05 +0200 Subject: [PATCH] Add sleep option --- fixbackup/__main__.py | 16 +++++++++++++++- fixbackup/args.py | 7 +++++++ fixbackup/backup/__init__.py | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fixbackup/__main__.py b/fixbackup/__main__.py index 8b8e472..bf16414 100644 --- a/fixbackup/__main__.py +++ b/fixbackup/__main__.py @@ -1,5 +1,6 @@ import sys import os +import time from pathlib import Path from typing import List from .logger import add_args as logging_add_args, log @@ -12,11 +13,24 @@ def main() -> None: args = parse_args([logging_add_args, s3_add_args, *backup_add_args]) exit_code = 0 - log.info("Starting FIX Databases Backup System") + log.info("Starting Fix Databases Backup System") if not verify_binaries(): sys.exit(1) + if args.sleep: + # This option is used to keep the container running for debugging purposes. + # It allows you to connect to it inside of e.g. a K8s environment + # and manually test the backup process. Alternatively, you could + # override the entrypoint of the container and sleep indefinitely. + log.info("Sleeping forever") + try: + while True: + time.sleep(300) + finally: + log.info("Shutdown complete") + sys.exit(0) + backup_directory = Path(args.backup_directory) rmdir_backup_directory = True if backup_directory.exists() and not backup_directory.is_dir(): diff --git a/fixbackup/args.py b/fixbackup/args.py index 87028ef..420b65e 100644 --- a/fixbackup/args.py +++ b/fixbackup/args.py @@ -19,6 +19,13 @@ def parse_args(add_args: List[Callable[[ArgumentParser], None]]) -> Namespace: help="Name of the environment", default=os.getenv("FIX_ENVIRONMENT", "dev"), ) + arg_parser.add_argument( + "--sleep", + help="Don't do anything, just sleep forever", + dest="sleep", + action="store_true", + default=False, + ) for add_arg in add_args: add_arg(arg_parser) diff --git a/fixbackup/backup/__init__.py b/fixbackup/backup/__init__.py index 0be2ba5..3d107fc 100644 --- a/fixbackup/backup/__init__.py +++ b/fixbackup/backup/__init__.py @@ -8,7 +8,7 @@ from .arangodb import backup as arangodb_backup, add_args as arangodb_add_args from ..utils import valid_hostname, valid_ip, valid_dbname -add_args = [redis_add_args, mysql_add_args, arangodb_add_args, postgresql_add_args] +add_args = [redis_add_args, mysql_add_args, postgresql_add_args, arangodb_add_args] def backup(args: Namespace, backup_directory: Path) -> Tuple[List[Path], bool]: