:floppy_disk: A bash script for backup database to Google Drive
A Bash script for backup database to Google Drive.
一个用于备份数据库到 Google Drive 的 Bash 脚本.
Database supported:
mongodump
pg_dump
You can easily create a new database backup script based on backup-mongodb.sh
.
(你可以基于 backup-mongodb.sh
轻松地创建一个新的数据库备份脚本)
git clone https://github.com/hangxingliu/database-backup.sh.git
安装你所需要的数据库的命令行工具
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
.
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”
初始化备份环境和依赖文件:
# init.sh is used for:
# 1. resolve all dependencies scripts need.
# 2. authroize a Google Drive account and storage its access token in the local
./init.sh
# then input your OAuth2 id and secret
# input code be displayed on screen in https://www.google.com/device
# 然后输入你的 OAuth2 id 和 secret
# 然后去 https://www.google.com/device 输入屏幕上的验证码
Just execute bash scripts ./backup-xxx.sh
, for example:
执行 bash 脚本 ./backup-xxx.sh
即可, 例如:
./backup-mongodb.sh
./backup-postgresql.sh --database dbTest
# you could find detailed reference of backup script
# in the front of itself.
# 你能在在备份脚本的头部找到详细的参考
添加备份到 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:
# backup everyday 每天备份一次
0 0 * * * /path/to/backup-database.sh/crontab.sh
./init.sh
: choose special directory./init.sh
: add error reason display (display temporary response file under /tmp
)Failed to list files: googleapi: Error 403: Access Not Configured. Drive API has not been used in project ...
backup-mysql.sh