Add bin/backup-to-s3.sh
This commit is contained in:
parent
e45f47ce6d
commit
d489cb5899
1 changed files with 29 additions and 0 deletions
29
bin/backup-to-s3.sh
Normal file
29
bin/backup-to-s3.sh
Normal file
|
|
@ -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"
|
||||
Loading…
Reference in a new issue