项目作者: hangxingliu

项目描述 :
:floppy_disk: A bash script for backup database to Google Drive
高级语言: Shell
项目地址: git://github.com/hangxingliu/database-backup.sh.git
创建时间: 2018-05-23T15:23:03Z
项目社区:https://github.com/hangxingliu/database-backup.sh

开源协议:GNU General Public License v3.0

下载


Backup Database Scripts 数据库备份脚本

Build Status

:floppy_disk: A Bash script for backup database to Google Drive.
一个用于备份数据库到 Google Drive 的 Bash 脚本.

Support 支持

Database supported:

  • MongoDB: mongodump
  • PostgreSQL: pg_dump

You can easily create a new database backup script based on backup-mongodb.sh.
(你可以基于 backup-mongodb.sh 轻松地创建一个新的数据库备份脚本)

Install & Usage 安装 & 使用

0x00. Git clone this repository

  1. git clone https://github.com/hangxingliu/database-backup.sh.git

0x01. Install database command line tools you need

安装你所需要的数据库的命令行工具

What command line tools you need install?
You can read this document: DEPENDENCIES.md
For example, if you need to backup MongoDB, you should install mongodb-org-tools package for mongodump tools.

不知道要装什么? 参考一下这篇文档: DEPENDENCIES.md
比如说, 如果你需要备份 MongoDB 的数据库, 那你需要安装 mongodb-org-tools 这个包, 因为里面包含备份工具 mongodump.

0x02. Get Google OAtuth2 Id and secret

Get Google OAuth2 Id and secret for operate Google Drive by API.
为了能正常地操作 Google Drive, 你需要先创建获得 Google OAuth2 Id 和 secret.

Graphic guidance 图文指导:

Just read section: (查看下面这个章节即可):
“How to get OAuth2 client id and secret for Google Drive API”

GOOGLE-DRIVE-API.md

0x03. Initialize backup environment and dependencies

初始化备份环境和依赖文件:

  1. # init.sh is used for:
  2. # 1. resolve all dependencies scripts need.
  3. # 2. authroize a Google Drive account and storage its access token in the local
  4. ./init.sh
  5. # then input your OAuth2 id and secret
  6. # input code be displayed on screen in https://www.google.com/device
  7. # 然后输入你的 OAuth2 id 和 secret
  8. # 然后去 https://www.google.com/device 输入屏幕上的验证码

screenshots
screenshots

0x04. Backup

Just execute bash scripts ./backup-xxx.sh, for example:
执行 bash 脚本 ./backup-xxx.sh 即可, 例如:

  1. ./backup-mongodb.sh
  2. ./backup-postgresql.sh --database dbTest
  3. # you could find detailed reference of backup script
  4. # in the front of itself.
  5. # 你能在在备份脚本的头部找到详细的参考

screenshots

0x05. (Optional) Add backup into crontab

添加备份到 crontab 定时任务可以参考样例脚本文件:
example-files/crontab.sh

You can reference the example crontab bash script:
example-files/crontab.sh

And modify it for yourself, then add rule into crontab
(crontab -e), for example:

  1. # backup everyday 每天备份一次
  2. 0 0 * * * /path/to/backup-database.sh/crontab.sh

TODO

  • ./init.sh: choose special directory
  • ./init.sh: add error reason display (display temporary response file under /tmp)
    • For example: Failed to list files: googleapi: Error 403: Access Not Configured. Drive API has not been used in project ...
  • more documents about backup-mysql.sh

Third-party libraries

Author

Liu Yue @hangxingliu

License

GPL-3.0