From d489cb5899c07c9654b1cecfc11785348d7db606 Mon Sep 17 00:00:00 2001 From: agnes Date: Thu, 13 Aug 2026 01:22:46 +0000 Subject: [PATCH] Add bin/backup-to-s3.sh --- bin/backup-to-s3.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 bin/backup-to-s3.sh diff --git a/bin/backup-to-s3.sh b/bin/backup-to-s3.sh new file mode 100644 index 0000000..5a6bf64 --- /dev/null +++ b/bin/backup-to-s3.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +cd /home/otwarchive/otwarchive || exit 1 + +FILE="/tmp/otwarchive_$(date +%Y-%m-%d).sql" + +sudo docker compose exec -T db sh -c \ + 'mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --databases otwarchive_production --skip-comments' \ + | gzip > "/tmp/otwarchive_$(date +%Y-%m-%d).sql" + +if [ ${PIPESTATUS[0]} -ne 0 ]; then + echo "MySQL dump failed" + rm -f "$FILE" + exit 1 +fi + +aws --endpoint-url https://t3.storage.dev \ + s3 cp "$FILE" \ + "s3://BUCKETNAME/mysql/otwarchive/$(basename "$FILE")" + +if [ $? -ne 0 ]; then + echo "S3 upload failed" + rm -f "$FILE" + exit 1 +fi + +rm -f "$FILE" + +echo "Backup completed successfully" \ No newline at end of file