diff --git a/src/restic_compose_backup/cli.py b/src/restic_compose_backup/cli.py index 78892d6..d2a4ad8 100644 --- a/src/restic_compose_backup/cli.py +++ b/src/restic_compose_backup/cli.py @@ -24,13 +24,9 @@ def main(): command.run() return - config = Config() - log.setup(level=args.log_level or config.log_level) - containers = RunningContainers() - # Ensure log level is propagated to parent container if overridden - if args.log_level: - containers.this_container.set_config_env('LOG_LEVEL', args.log_level) + # if args.log_level: + # containers.this_container.set_config_env('LOG_LEVEL', args.log_level) if args.action == 'status': status(config, containers) @@ -60,64 +56,6 @@ def main(): print(' - {} {} {}'.format(node.id, addr, state)) -def status(config, containers): - """Outputs the backup config for the compose setup""" - logger.info("Status for compose project '%s'", containers.project_name) - logger.info("Repository: '%s'", config.repository) - logger.info("Backup currently running?: %s", containers.backup_process_running) - logger.info("Include project name in backup path?: %s", utils.is_true(config.include_project_name)) - logger.debug("Exclude bind mounts from backups?: %s", utils.is_true(config.exclude_bind_mounts)) - logger.info("Checking docker availability") - - utils.list_containers() - - if containers.stale_backup_process_containers: - utils.remove_containers(containers.stale_backup_process_containers) - - # Check if repository is initialized with restic snapshots - if not restic.is_initialized(config.repository): - logger.info("Could not get repository info. Attempting to initialize it.") - result = restic.init_repo(config.repository) - if result == 0: - logger.info("Successfully initialized repository: %s", config.repository) - else: - logger.error("Failed to initialize repository") - - logger.info("%s Detected Config %s", "-" * 25, "-" * 25) - - # Start making snapshots - backup_containers = containers.containers_for_backup() - for container in backup_containers: - logger.info('service: %s', container.service_name) - - if container.volume_backup_enabled: - for mount in container.filter_mounts(): - logger.info( - ' - volume: %s -> %s', - mount.source, - container.get_volume_backup_destination(mount, '/volumes'), - ) - - if container.database_backup_enabled: - instance = container.instance - # ping = instance.ping() - ping = 0 - logger.info( - ' - %s (is_ready=%s) -> %s', - instance.container_type, - ping == 0, - instance.backup_destination_path(), - ) - if ping != 0: - logger.error("Database '%s' in service %s cannot be reached", - instance.container_type, container.service_name) - - if len(backup_containers) == 0: - logger.info("No containers in the project has 'restic-compose-backup.*' label") - - logger.info("-" * 67) - - def backup(config, containers): """Request a backup to start""" # Make sure we don't spawn multiple backup processes diff --git a/src/restic_compose_backup/commands/status.py b/src/restic_compose_backup/commands/status.py index ea8eefc..cbce6a8 100644 --- a/src/restic_compose_backup/commands/status.py +++ b/src/restic_compose_backup/commands/status.py @@ -1,4 +1,5 @@ from .base import BaseCommand +from restic_compose_backup import utils, restic class Command(BaseCommand): @@ -6,4 +7,60 @@ class Command(BaseCommand): name = "status" def run(self): - print("Status!") + """Outputs the backup config for the compose setup""" + containers = self.get_containers() + + self.logger.info("Status for compose project '%s'", containers.project_name) + self.logger.info("Repository: '%s'", self.config.repository) + self.logger.info("Backup currently running?: %s", containers.backup_process_running) + self.logger.info("Include project name in backup path?: %s", utils.is_true(self.config.include_project_name)) + self.logger.debug("Exclude bind mounts from backups?: %s", utils.is_true(self.config.exclude_bind_mounts)) + self.logger.info("Checking docker availability") + + utils.list_containers() + + if containers.stale_backup_process_containers: + utils.remove_containers(containers.stale_backup_process_containers) + + # Check if repository is initialized with restic snapshots + if not restic.is_initialized(self.config.repository): + self.logger.info("Could not get repository info. Attempting to initialize it.") + result = restic.init_repo(self.config.repository) + if result == 0: + self.logger.info("Successfully initialized repository: %s", self.config.repository) + else: + self.logger.error("Failed to initialize repository") + + self.logger.info("%s Detected Config %s", "-" * 25, "-" * 25) + + # Start making snapshots + backup_containers = containers.containers_for_backup() + for container in backup_containers: + self.logger.info('service: %s', container.service_name) + + if container.volume_backup_enabled: + for mount in container.filter_mounts(): + self.logger.info( + ' - volume: %s -> %s', + mount.source, + container.get_volume_backup_destination(mount, '/volumes'), + ) + + if container.database_backup_enabled: + instance = container.instance + # ping = instance.ping() + ping = 0 + self.logger.info( + ' - %s (is_ready=%s) -> %s', + instance.container_type, + ping == 0, + instance.backup_destination_path(), + ) + if ping != 0: + self.logger.error("Database '%s' in service %s cannot be reached", + instance.container_type, container.service_name) + + if len(backup_containers) == 0: + self.logger.info("No containers in the project has 'restic-compose-backup.*' label") + + self.logger.info("-" * 67)