Skip to the content.

MySQL OneKey Backup

GitHub license GitHub stars GitHub issues GitHub forks Github Release

A shell script to backup mysql database and send message with pushoo.

Features

Requirements

You need to install the following software before using the script.

You can install them with the following command.

# install mysqldump
bash /path/to/mysql_backup.sh do_install_mysql_client

# install pushoo-cli
bash /path/to/mysql_backup.sh do_install_pushoo_cli

# install nodejs 16
bash /path/to/mysql_backup.sh do_install_nodejs

Attention: You need config pushoo-cli before use it.

Arguments

The script has 10 variables, you can set them in the script or pass them as arguments. following is the description of each variable.

for example:

bash mysql_backup.sh "dump_target_dir" "db_host" "db_user" "db_password" "db_names" db_port "dump_opts" expire_hours "before_dump_command" "after_dump_command"

Usage

# backup "db1" and "db2" to "/path/to/db_backups" and the dump file will be deleted after 4320 hours.
bash /path/to/mysql_backup.sh "/path/to/db_backups" "127.0.0.1" "root" "examplepassword" "db1 db2" 3306 "--single-transaction --quick --lock-tables=false" 4320
# or
bash /path/to/mysql_backup.sh "/path/to/db_backups" "127.0.0.1" "root" "examplepassword" "db1 db2"

# backup "db1" and "db2" to "/path/to/db_backups" and the dump file will be deleted after 4320 hours. and log to /var/log/db_backup.log
bash /path/to/mysql_backup.sh "/path/to/db_backups" "127.0.0.1" "root" "examplepassword" "db1 db2" >> /var/log/db_backup.log 2>&1

CronTab

You can use crontab to schedule the script to run periodically. For example, you can run the script every day at 3:00 AM.

0 3 * * * /path/to/mysql_backup.sh "/path/to/db_backups" "127.0.0.1" "root" "examplepassword" "db1 db2" >> /var/log/db_backup.log 2>&1

Docker

You can use docker image, funnyzak/apline-cron to schedule the script to run periodically.

Reference

Contribution

If you have any questions or suggestions, please feel free to submit an issue or pull request.

License

MIT License © 2023 funnyzak