Skip to content

Commit

Permalink
Merge pull request #897 from alphagov/1884-stale
Browse files Browse the repository at this point in the history
1884: Download latest live snapshot for local development
  • Loading branch information
ahernp authored Feb 10, 2025
2 parents a38024f + 207db86 commit 69cfc8c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions prepare_local_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Prepare Local DB - Downloads the latest db backup and uploads to local postgres instance """
"""Prepare Local DB - Downloads the latest db backup and uploads to local postgres instance"""

import subprocess
from datetime import date
from pathlib import Path

import boto3
Expand All @@ -11,8 +12,11 @@
if __name__ == "__main__":
s3_client = boto3.client("s3")
db_backups: list = []
for key in s3_client.list_objects(Bucket=S3_BUCKET)["Contents"]:
if "aws_aurora_backup/" in key["Key"] and "prodenv" in key["Key"]:
backup_key_prefix: str = f"aws_aurora_backup/{date.today().year}"
for key in s3_client.list_objects(Bucket=S3_BUCKET, Prefix=backup_key_prefix)[
"Contents"
]:
if "prodenv" in key["Key"]:
db_backups.append(key)
db_backups.sort(key=lambda x: x["LastModified"])
file_name: str = db_backups[-1]["Key"].split("/")[-1]
Expand Down

0 comments on commit 69cfc8c

Please sign in to comment.