🗄️ Automate MySQL Backups to AWS S3 with a Simple Bash Script

Backups are one of those things you don’t think about… until it’s too late.

I wanted a simple, no-dependency solution for MySQL backups that I could run via cron, store safely on AWS S3, and clean up automatically.

So I wrote a Bash script that does exactly that — checks versions, loads environment variables, dumps the DB, compresses it, uploads to S3, and cleans up afterward.

Here’s the full script and a breakdown of how it works. 👇


💾 Script

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

DIRNAME=$(dirname "$0")
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")

echo "Starting database backup for $TIMESTAMP";

check_versions() {
aws --version
mysqldump --version
}

load_env() {
echo "Loading .env file";

ENV_FILE="$DIR...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help