by Leonn
Leonn的博客 / 2017-11-12 19:13
全文转载自Max的小站
简介
- 数据库是网站最重要的东西,定时备份是肯定要做的。手动备份又浪费时间又容易忘记,干脆搞个自动备份脚本好了。
使用 Google Drive 备份
安装 GDrive
- Ubuntu 14.04 64bit 版可用以下脚本直接安装 GDrive
wget http://box.maxfox.me/install-gdrive.sh && chmod +x install-gdrive.sh && ./install-gdrive.sh
- 其他系统移步 Github 下载安装,开源项目地址:https://github.com/prasmussen/gdrive
下载并配置脚本
- 下载脚本:
wget http://box.maxfox.me/auto-backup-sql-gdrive.sh
- 然后编辑脚本,填上你需要备份的数据库名、数据库 root 用户密码、zip 压缩包密码等。
- 别忘了用
chmod +x auto-backup-sql-gdrive.sh
给脚本执行权限。
使用百度云备份
安装 bypy
- bypy 是国人用 python 开发的百度云客户端,开源项目地址:https://github.com/houtianze/bypy
- 在安装 bypy 之前请确保你的服务器安装了以下依赖包:
apt install python-pip pip install requests
- 安装 bypy 主程序:
pip install bypy
- 授权登陆百度云账号:
bypy info
下载并配置脚本
- 下载脚本:
wget http://box.maxfox.me/auto-backup-sql-baiduyun.sh
- 然后依然需要编辑脚本,填上你需要备份的数据库名、数据库 root 用户密码、zip 压缩包密码等。
- 同样别忘了用
chmod +x auto-backup-sql-baiduyun.sh
给脚本执行权限。
备份的数据存储在“百度云盘 > 我的应用数据 >bypy”目录下
使用 cron 定时自动备份
- 执行 crontab -e 编辑 cron 的配置文件,在最底部加入
0 4 * * * /root/backups/auto-backup-sql-gdrive.sh
我的脚本文件放在 /root/backups/ 目录下,定时每天 4 点 0 分执行脚本
- cron 的任务格式是:
minute hour day month week command
—
Shared via Inoreader