Skip to content

Commit

Permalink
Merge pull request #28 from sgibson91/add-logging
Browse files Browse the repository at this point in the history
Add logging capabilities
  • Loading branch information
sgibson91 authored Feb 10, 2025
2 parents dc9e6e7 + f03ea50 commit 63b5f4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions images/gcp-filestore-backups/gcp-filestore-backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime, timedelta

import jmespath
from loguru import logger


def extract_region_from_zone(zone: str):
Expand Down Expand Up @@ -111,7 +112,7 @@ def filter_backups_into_recent_and_old(
if datetime.now() - backup["createTime"] > timedelta(days=retention_days)
]
if len(old_backups) > 0:
print(
logger.info(
f"Filestore backups older than {retention_days} days have been found. They will be deleted." # noqa: E501
)

Expand Down Expand Up @@ -140,7 +141,7 @@ def create_backup_if_necessary(
zone (str): The GCP zone to create the backup in, e.g. us-central1-b
"""
if len(backups) == 0:
print(
logger.info(
f"There have been no recent backups of the filestore for project {project}. Creating a backup now..." # noqa: E501
)

Expand Down Expand Up @@ -168,7 +169,7 @@ def create_backup_if_necessary(
]
)
else:
print("Recent backup found.")
logger.info("Recent backup found.")


def delete_old_backups(backups: list, region: str):
Expand All @@ -192,7 +193,7 @@ def delete_old_backups(backups: list, region: str):
]
)
else:
print("No outdated backups found.")
logger.info("No outdated backups found.")


def main(args):
Expand Down Expand Up @@ -264,6 +265,7 @@ def main(args):
)

args = parser.parse_args()
logger.info(f"Parsed arguments: {vars(args)}")

while True:
main(args)
Expand Down
1 change: 1 addition & 0 deletions images/gcp-filestore-backups/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
jmespath
loguru

0 comments on commit 63b5f4b

Please # to comment.