Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sleep option #6

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion fixbackup/__main__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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():
Expand Down
7 changes: 7 additions & 0 deletions fixbackup/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fixbackup/backup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
Loading