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

better logging in run_backup, add thread name to logging #90

Merged
merged 1 commit into from
Aug 7, 2023
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
10 changes: 5 additions & 5 deletions backuper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def logging_config(log_level: str) -> None:
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "{asctime} [{levelname}] {name}: {message}",
"format": "{asctime} {threadName} [{levelname}] {name}: {message}",
"style": "{",
},
},
Expand All @@ -69,31 +69,31 @@ def logging_config(log_level: str) -> None:
"class": "logging.handlers.RotatingFileHandler",
"filename": LOG_FOLDER_PATH / "backuper_error.log",
"formatter": "verbose",
"maxBytes": 10**5,
"maxBytes": 5 * 10**6,
"backupCount": 1,
"level": "ERROR",
},
"warning": {
"class": "logging.handlers.RotatingFileHandler",
"filename": LOG_FOLDER_PATH / "backuper_warning.log",
"formatter": "verbose",
"maxBytes": 10**5,
"maxBytes": 5 * 10**6,
"backupCount": 1,
"level": "WARNING",
},
"info": {
"class": "logging.handlers.RotatingFileHandler",
"filename": LOG_FOLDER_PATH / "backuper_info.log",
"formatter": "verbose",
"maxBytes": 10**5,
"maxBytes": 5 * 10**6,
"backupCount": 1,
"level": "INFO",
},
"debug": {
"class": "logging.handlers.RotatingFileHandler",
"filename": LOG_FOLDER_PATH / "backuper_debug.log",
"formatter": "verbose",
"maxBytes": 10**5,
"maxBytes": 5 * 10**7,
"backupCount": 1,
"level": "DEBUG",
},
Expand Down
2 changes: 1 addition & 1 deletion backuper/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def create_provider_model() -> ProviderModel:
target_model.__name__.lower().removesuffix("providermodel")
)
target_map[name] = target_model
log.info("start validating BACKUP_PROVIDER")
log.info("start validating BACKUP_PROVIDER environment variable")

base_provider = _validate_model(
"backup_provider",
Expand Down
19 changes: 13 additions & 6 deletions backuper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def backup_provider() -> BaseBackupProvider:
log.debug("initializing %s with %s", provider_target_cls, provider_model)
res_backup_provider = provider_target_cls(**provider_model.model_dump())
log.info(
"success initializing target: `%s`",
"success initializing provider: `%s`",
provider_model.name,
)
return res_backup_provider
Expand Down Expand Up @@ -78,7 +78,7 @@ def shutdown() -> NoReturn:
deadline = start + timeout_secs
log.info(
"start backuper shutdown, force exit after SIGTERM_TIMEOUT_SECS=%ss, "
"use this environment to control it.",
"use this environment to control it, see https://backuper.rafsaf.pl/configuration/.",
timeout_secs,
)
for thread in threading.enumerate():
Expand Down Expand Up @@ -121,6 +121,11 @@ def run_backup(target: BaseBackupTarget, provider: BaseBackupProvider) -> None:
step_name=PROGRAM_STEP.BACKUP_CREATE, env_name=target.env_name
):
backup_file = target.make_backup()
log.info(
"backup file created: %s, starting post save upload to provider %s",
backup_file,
provider.NAME,
)
with NotificationsContext(
step_name=PROGRAM_STEP.UPLOAD,
env_name=target.env_name,
Expand All @@ -129,7 +134,7 @@ def run_backup(target: BaseBackupTarget, provider: BaseBackupProvider) -> None:
provider.post_save(backup_file=backup_file)

log.info(
"backup finished, next backup of target `%s` is: %s",
"backup and upload finished, next backup of target `%s` is: %s",
target.env_name,
target.next_backup_time,
)
Expand All @@ -146,6 +151,7 @@ def setup_runtime_arguments() -> bool:


def main() -> NoReturn:
log.info("start backuper configuration...")
signal.signal(signalnum=signal.SIGINT, handler=quit)
signal.signal(signalnum=signal.SIGTERM, handler=quit)

Expand All @@ -154,16 +160,17 @@ def main() -> NoReturn:
provider = backup_provider()
targets = backup_targets()

i = 0
log.info("backuper configuration finished")

while not exit_event.is_set():
for target in targets:
if target.next_backup() or single_run:
i += 1
pretty_env_name = target.env_name.replace("_", "-")
backup_thread = Thread(
target=run_backup,
args=(target, provider),
daemon=True,
name=f"{target.env_name}-{i}",
name=f"Thread-{pretty_env_name}",
)
backup_thread.start()
exit_event.wait(0.5)
Expand Down