Skip to content

Commit

Permalink
Update perform-backup.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhais committed Jul 22, 2024
1 parent d03838d commit 2028882
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions resources/perform-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ backup_name=""
# Loop through all the defined databases, seperating by a ,
for CURRENT_DATABASE in ${TARGET_DATABASE_NAMES//,/ }
do

# Perform the database backup. Put the output to a variable. If successful upload the backup to S3, if unsuccessful print an entry to the console and the log, and set has_failed to true.
if sqloutput=$(mysqldump -u $TARGET_DATABASE_USER -h $TARGET_DATABASE_HOST -p$TARGET_DATABASE_PASSWORD -P $TARGET_DATABASE_PORT $CURRENT_DATABASE 2>&1 > /tmp/$CURRENT_DATABASE.sql)
then

echo -e "Database backup successfully completed for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S')."
backup_name=$CURRENT_DATABASE_$(date +"%Y-%m-%d_%H-%M-%S").sql

echo -e "aws s3 cp /tmp/$CURRENT_DATABASE.sql s3://$AWS_BUCKET_NAME$AWS_BUCKET_BACKUP_PATH/$backup_name --endpoint-url=$AWS_ENDPOINT_URL"

# Perform the upload to R2. Put the output to a variable. If successful, print an entry to the console and the log. If unsuccessful, set has_failed to true and print an entry to the console and the log
if awsoutput=$(aws s3 cp "/tmp/$CURRENT_DATABASE.sql" s3://$AWS_BUCKET_NAME$AWS_BUCKET_BACKUP_PATH/$backup_name --endpoint-url=$AWS_ENDPOINT_URL 2>&1)
# Perform the upload to S3. Put the output to a variable. If successful, print an entry to the console and the log. If unsuccessful, set has_failed to true and print an entry to the console and the log
if awsoutput=$(aws s3 cp /tmp/$CURRENT_DATABASE.sql $AWS_BUCKET_URI$AWS_BUCKET_BACKUP_PATH/$backup_name --endpoint-url=$AWS_ENDPOINT_URL 2>&1)
then
echo -e "Database backup successfully uploaded for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S')."
else
Expand Down

0 comments on commit 2028882

Please sign in to comment.