From 45b4928d83f161ff7b42513a111ebd79ab5797a8 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Sun, 24 Sep 2023 17:22:08 -0500 Subject: [PATCH] Convert db download script to Python --- local/download_database.py | 18 ++++++++++++++++++ local/download_database.sh | 15 --------------- local/requirements.txt | 1 + 3 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 local/download_database.py delete mode 100755 local/download_database.sh create mode 100644 local/requirements.txt diff --git a/local/download_database.py b/local/download_database.py new file mode 100644 index 0000000..a447f2d --- /dev/null +++ b/local/download_database.py @@ -0,0 +1,18 @@ +import boto3 + +# You must already have configured your "AWS" (DigitalOcean) credentials via the AWS CLI. + +s3 = boto3.resource("s3") +bucket = s3.Bucket("hmn-backup") +for obj in bucket.objects.filter(Prefix="db"): + print(obj.key) + +print() +print("Above is a list of all the available database backups.") +print("Enter the name of the one you would like to download (e.g. \"hmn_pg_dump_live_2023-09-24\"):") +filename = input() + +s3 = boto3.client("s3") +s3.download_file("hmn-backup", f"db/{filename}", f"local/backups/{filename}") + +print(f"Downloaded {filename} to local/backups.") diff --git a/local/download_database.sh b/local/download_database.sh deleted file mode 100755 index ff1731d..0000000 --- a/local/download_database.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -s3cmd ls s3://hmn-backup/db/ - -echo "" -echo "Above is a list of all the available database backups." -echo "Enter the name of the one you would like to download (e.g. \"hmn_pg_dump_live_2021-09-01\"):" -read filename - -s3cmd get --force s3://hmn-backup/db/$filename ./local/backups/$filename - -echo "" -echo "Downloaded $filename to local/backups." diff --git a/local/requirements.txt b/local/requirements.txt new file mode 100644 index 0000000..23d75a2 --- /dev/null +++ b/local/requirements.txt @@ -0,0 +1 @@ +boto3