Skip to content

📦 A simple bash script to automate MySQL database backups with options for compression and upload.

License

Notifications You must be signed in to change notification settings

bartekl1/mysql-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 MySQL Backup Script

A simple bash script to automate MySQL database backups with options for compression and upload.

ℹ️ About

I created this script with ChatGPT because I quickly needed a database backup script for my weather station.
I do not plan to maintain it, but if you find it useful, feel free to use it.

✨ Features

  • 💾 Local MySQL database backups using mysqldump
  • 📦 Optional compression using gzip
  • ☁️ Optional remote upload via rclone
  • 🧹 Optional cleanup of old local backups

🔧 Installation and usage

  1. Install dependencies:
  • mysqldump (part of MySQL client tools)
  • gzip (optional for compression, usually pre-installed on most Linux distributions)
  • rclone (optional for remote uploads, see rclone installation guide)
  1. Clone the repository.
git clone https://github.com/bartekl1/mysql-backup.git
cd mysql-backup
cp backup.example.conf backup.conf

Instead of cloning the repository, you can also download the backup.sh script directly.

wget https://raw.githubusercontent.com/bartekl1/mysql-backup/refs/heads/main/backup.sh
wget https://raw.githubusercontent.com/bartekl1/mysql-backup/refs/heads/main/backup.example.conf -O backup.conf
  1. Edit backup.conf configuration file. See the Configuration section for more details.

  2. Make the script executable.

chmod +x backup.sh
  1. Manually run the script to test it.
./backup.sh
  1. (Optional) Set up a cron job to automatically run the script at the desired time.
crontab -e

Example (backup every day at 2 AM):

0 2 * * * bash /path/to/backup.sh

⚙️ Configuration

The script can be configured via the backup.conf file.
Example configuration file is available in backup.example.conf.
See comments in the file for explanation of each option.

📜 License

This project is licensed under Zero-Clause BSD License.
This means you can freely use, modify, and redistribute the code for commercial and non-commercial purposes without attribution.

About

📦 A simple bash script to automate MySQL database backups with options for compression and upload.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages