Skip to content

Bash script(s) for backing up MySQL / MariaDB databases

License

Notifications You must be signed in to change notification settings

jantomicky/database-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

database-backup

Bash script(s) for backing up MySQL / MariaDB databases with mysqldump, backups are timestamped, archived and optionally pruned based on age. Bash is required as the scripts use Bash specific features.

Setup

  • (Recommended) Create a dedicated read only database user for the backup purposes. MySQL <=5.7
GRANT SHOW DATABASES, SELECT, LOCK TABLES, SHOW VIEW ON *.* TO 'your-user'@'localhost' IDENTIFIED BY 'your-password';

MySQL >= 8.0

CREATE USER 'your-user'@'%' IDENTIFIED BY 'your-password'; GRANT SHOW DATABASES, SELECT, LOCK TABLES, SHOW VIEW ON *.* TO 'your-user'@'%'; FLUSH PRIVILEGES;
  • Clone the repo git clone https://github.com/jantomicky/database-backup.git
  • cd database-backup/
  • Run ./init to generate a configuration file and pass your database credentials (which are saved in $HOME/my.cnf)
    • You can set ENV variables for "no interaction" setup:
      • DATABASE_BACKUPS_PATH
      • DATABASE_BACKUPS_KEEP_FOR_DAYS
      • DATABASE_BACKUPS_USERNAME
      • DATABASE_BACKUPS_PASSWORD
  • (Optional) Set host= in your $HOME/my.cnf if the target host is not localhost
  • Create a backup by running ./database-backup
  • (Recommended) Setup automatic backups with cron (crontab -e):
0 22 * * * /path/to/database-backup

About

Bash script(s) for backing up MySQL / MariaDB databases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages