Select Page

Linux 数据库定时备份至七牛云 脚本

Linux 数据库定时备份至七牛云 脚本

做站离不开备份,这个定时数据库备份脚本我个人也一直在,遇到突发情况也好有应对的措施恢复数据。

本脚本Github项目地址:https://github.com/ccbikai/backuptoqiniu

七牛云的注册和认证环境这里就不再赘述,官网都有详细的流程。

安装及配置脚本

首先确认自己的python版本在2.7及以上

python -V

安装zip和unzip

#CentOS系统:
yum update && yum install -y zip unzip

#Debian/Ubuntu系统:
apt-get update && apt-get install -y zip unzip

安装脚本

wget --no-check-certificate -O backuptoqiniu.zip https://softs.fun/Website/backuptoqiniu.zip
unzip backuptoqiniu.zip && cd backuptoqiniu
python setup.py install

配置脚本 backuptoqiniu.sh

## 备份配置信息 ##

# 备份名称,用于标记
BACKUP_NAME="qiniu-backup"
# 备份目录,多个请空格分隔
BACKUP_SRC="/home/wwwroot/"
# Mysql主机地址
MYSQL_SERVER="localhost"
# Mysql用户名
MYSQL_USER="root"
# Mysql密码
MYSQL_PASS="mysqlpassword"
# Mysql备份数据库,多个请空格分隔
MYSQL_DBS="dbname"
# 备份文件临时存放目录,一般不需要更改
BACKUP_DIR="/tmp/backuptoqiniu"
# 备份文件压缩密码确保压缩包的安全
BACKUP_FILE_PASSWD="doub.io"

## 备份配置信息 End ##

## 七牛配置信息 ##

#存放空间对应我们在七牛上创建的文件夹
QINIU_BUCKET="doubi"
QINIU_ACCESS_KEY="ACCESS_KEY"
QINIU_SECRET_KEY="SECRET_KEY"

## 七牛配置信息 End ##

赋予脚本权限并执行

chmod +x backuptoqiniu.sh

bash backuptoqiniu.sh

一般情况会出现以下界面

# bash backuptoqiniu.sh
start dump mysql
dump ok
start tar
tar ok
start upload
upload ok
backup clean done

设置crontab定时任务

crontab -e

0 2 * * 1 /bin/bash /root/backuptoqiniu/backuptoqiniu.sh

#每周一的凌晨2点 自动定时执行命令

重启crontab

service crond restart

参考链接

About The Author

Jackie Sung

Jackie Sung, also known by his nick-name KK, always strives for the best and learn from the best. Influenced by the age of Internet, for the last few years, in his spare time, he's been working and living as a Freelance Web Engineer/ Web Developer & Designer/ Amateur Photographer/ Husky Lover. The work he provides is of highest quality, fully-customized responsive, and tested in a wide range of devices, which typically covers both front-end (HTML5/ CSS3/ JavaScript) and back-end (WordPress as the CMS) responsibilities.

Leave a reply

电子邮件地址不会被公开。 必填项已用*标注

12 + 20 =

关于本站

主要用于记录和分享我所折腾过的东西
因为业务关系,本站采用双语
我是菜鸡 各位大佬多包含 别DDCC我 谢谢
工作联系 hello#jackiesung.com 将#换成@

订阅本站

Pin It on Pinterest

Share This