Skip to content

A bash script to automatically dump, compress and store your MySQL/MariaDB database backups.

License

Notifications You must be signed in to change notification settings

RealTriassic/MySQL-Backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MySQL-Backup

A bash script to automatically dump, compress and store your MySQL/MariaDB database backups.

Configuration

  • BACKUP_DIR - The directory to be used for storing the database backups.
  • MYSQL_USER - MySQL username, typically you'd use the root user.
  • MYSQL_PASSWORD Password for your MySQL user, if user has no password, keep as empty string.
  • BACKUPS_TO_KEEP - Amount of backups to store before deleting the oldest one.

Once configured, I recommend running the script at least once manually and see if backups are created successfully.

Making it run automatically

You can use a simple cronjob to make it execute the script automatically.

⚠️ This is an example, you may have to edit the cronjob if you have renamed/relocated the script.

  1. Run crontab -e to open the cronjob editor.
  2. Press i to enable insert mode in the editor.
  3. Paste this into a new line: 0 0 * * * bash /root/backup.sh >> /dev/null 2>&1
  4. Press ESC (Escape) on your keyboard.
  5. Type :wq to save and exit.

This is going to create a new backup of all databases every 24 hours at midnight, but you can adjust the cronjob as you wish to have it run whenever you want.

License

This project is licensed under the Unlicense License, you may view the LICENSE here.

About

A bash script to automatically dump, compress and store your MySQL/MariaDB database backups.

Topics

Resources

License

Stars

Watchers

Forks

Languages