Coder Social home page Coder Social logo

funnyzak / mysql-onekey-backup Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 39 KB

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

Home Page: http://dbback.gp.yycc.dev

License: MIT License

Shell 100.00%
mysql mysql-backup pushoo-cli shell backup onekey-mysql-backup

mysql-onekey-backup's Introduction

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

  • Backup all databases or specified databases.
  • Push message with pushoo.
  • Delete expired dump files.
  • Support custom commands before and after the dump.
  • Support custom mysqldump options.
  • Support on CentOS 7+、Ubuntu 18.04+、Debian 9+.

Requirements

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

  • mysqldump
  • pushoo-cli
  • nodejs 14+

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.

  • dump_target_dir - The directory where the dump file will be saved. Default: /path/to/db_backups. Required.
  • db_host - The host of the database. Default: 127.0.0.1. Required.
  • db_user - The user of the database. Default: root. Required.
  • db_password - The password of the database. Default is empty. Required.
  • db_names - The names of the database. If set empty, all databases will be backed up. Required.
  • db_port - The port of the database. Default: 3306. Required.
  • dump_opts - The options of the mysqldump command. Default: --single-transaction --quick --lock-tables=false. Optional.
  • expire_hours - The dump file at the specified directory will be deleted after the specified number of hours. Default: 4320. Optional.
  • before_dump_command - The command to be executed before the dump. Default is empty. Optional.
  • after_dump_command - The command to be executed after the dump. Default is empty. Optional.

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

mysql-onekey-backup's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.