Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Production-Ready MySQL Backup Script (with Compression and AWS Upload)

🗄️ 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 …

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




🗄️ 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="$DIRNAME/../.env"
[[ ! -f $ENV_FILE ]] && printf "%s: file not found" "$ENV_FILE" && exit 1
source "$ENV_FILE"

echo "Database name is: $DB_DATABASE"
}

check_variables() {
if [[ ! -v AWS_DB_BACKUP_BUCKET ]]; then
echo "Error: AWS_DB_BACKUP_BUCKET environment variable is not set!"
exit 1;
fi
}

create_dump() {
echo "Creating database dump...";
OUTPUT_FILE="$PWD/$TIMESTAMP-$DB_DATABASE.sql"

mysqldump "$DB_DATABASE" \
--column-statistics=0 \
--no-tablespaces \
--set-gtid-purged=OFF \
--host="$DB_HOST" \
--user="$DB_USERNAME" \
--password="$DB_PASSWORD" > "$OUTPUT_FILE"

echo "$OUTPUT_FILE file created."
du -sh "$OUTPUT_FILE"
}

zip_output_file() {
echo "Compressing target file...";

zip -j -T "$OUTPUT_FILE.zip" "$OUTPUT_FILE"
du -sh "$OUTPUT_FILE.zip"
}

upload_to_s3() {
echo "Uploading zip file to S3 bucket...";

CURRENT_YEAR=$(date +"%Y")
S3_DESTINATION_PATH="s3://$AWS_DB_BACKUP_BUCKET/$CURRENT_YEAR/"
aws s3 cp "$OUTPUT_FILE.zip" "$S3_DESTINATION_PATH"
}

cleanup() {
echo "Removing temp files from local disk";

rm -f "$OUTPUT_FILE.zip"
rm -f "$OUTPUT_FILE"
}

check_versions
load_env
check_variables
create_dump
zip_output_file
upload_to_s3
cleanup

echo "Database backup script finished!"









⚙️ Common Pitfalls / Troubleshooting



Here are a few common issues you might encounter and how to fix them:







🧾 Missing .env file



The script will exit with “file not found.”



✅ Make sure your .env file exists and contains:




DB_HOST=localhost
DB_DATABASE=my_database
DB_USERNAME=root
DB_PASSWORD=secret
AWS_DB_BACKUP_BUCKET=my-s3-bucket









🧰 mysqldump: command not found






Install and configure  mysql-client









☁️ aws: command not found






Install and configure AWS CLI






That’s it! You now have a simple, reliable, and automated MySQL backup solution using nothing more than Bash and AWS CLI.



If you found this helpful,give a ❤️






Happy automating! 🚀

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Production-Ready MySQL Backup Script (with Compression and AWS Upload)

Thematisch verwandte Begriffe: ProductionReady, MySQL, Backup, Script · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-49449 | Joplin is an open source note-taking and to-do application that organise…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick