📞 🇺🇸 +1 361 304 4309 📞 🇮🇳 +91 76769 02281 ✉️ [email protected]
Server Management

How to Back Up MySQL Databases Automatically on Linux

How to Back Up MySQL Databases Automatically on Linux

Automated MySQL backups are essential for any production server. This guide covers a complete backup script with rotation and offsite storage.

Backup Script

#!/bin/bash
BACKUP_DIR="/backups/mysql"
DATE=$(date +%Y-%m-%d_%H-%M)
MYSQL_USER="root"
MYSQL_PASS="your-password"

mkdir -p $BACKUP_DIR

DATABASES=$(mysql -u$MYSQL_USER -p$MYSQL_PASS -e "SHOW DATABASES;" | grep -v -E "^(Database|information_schema|performance_schema|sys)$")

for DB in $DATABASES; do
    mysqldump -u$MYSQL_USER -p$MYSQL_PASS         --single-transaction --routines --triggers         $DB | gzip > $BACKUP_DIR/${DB}_${DATE}.sql.gz
done

find $BACKUP_DIR -name "*.sql.gz" -mtime +7 -delete
echo "MySQL backup completed"

Schedule

0 2 * * * /usr/local/bin/mysql-backup.sh >> /var/log/mysql-backup.log 2>&1

Upload to S3

s3cmd sync $BACKUP_DIR/ s3://your-bucket/mysql-backups/

Conclusion

Automated MySQL backups protect your most valuable data. Our team configures comprehensive database backup solutions.

#mysql #backup #mysqldump #automation
Share:
🛠️ Need Expert Help?

Don't want to do this yourself?

Our certified engineers implement this for you — correctly, securely, and within hours. Available 24/7 with 15-minute emergency response.

  • ✅ 19+ years experience
  • ✅ 60+ certified engineers
  • ✅ 1,600+ servers managed
  • ✅ 40+ countries served
  • ✅ Plans from $49/mo

Get Expert Help — Free Consultation

We respond within 4 hours · No commitment required

Please enter your name and a valid email.

No spam. Privacy Policy

Comments