前言
云服务器跑着各种项目,包括这个博客,所以数据文件相当重要,尤其运行那么多年,早期编写shell脚本定时备份到服务器指定地方,现在担心什么时候服务器也挂,于是想到自动备份到百度云盘.
准备
centos服务器,python环境
步骤
安装bypy
pip install bypy
国内网速有点慢,如果失败多重试几次
如提示 You should consider upgrading via the 'pip install --upgrade pip' command.
则更新pip即可
pip install --upgrade pip
执行
bypy info
如果提示
-bash: bypy: command not found,则需要卸载重装
pip uninstall bypy
正常输出
Please visit:
https://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&client_id=q8WE4EpCsau1oS0MplgMKNBn&redirect_uri=oob&response_type=code
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done
复制网址到浏览器打开登录百度帐号绑定验证
登录后会得到百度授权码,复制到命令行确认
Authorizing, please be patient, it may take upto 300 seconds...
Authorizing/refreshing with the OpenShift server ...
OpenShift server failed, authorizing/refreshing with the Heroku server ...
Successfully authorized
Quota: 5.020TB
Used: 755.269GB
常用指令
bypy list # 显示文档
bypy upload filename -v # 上传某文件,显示进度
bypy -c # 取消令牌文件。一段时间后要重新授权
bypy downdir filename # 下载
bypy compare # 比较本地目录和网盘目录
示例
bypy upload tale20200515.tar -v
以下结果表示成功
Loading Hash Cache File '/root/.bypy/bypy.hashcache.json'... Hash Cache File '/root/.bypy/bypy.hashcache.json' not found, no caching RapidUpload: 'tale20200515.tar' =R=> '/apps/bypy/tale20200515.tar' OK.
上传成功的文件在百度云盘路径
我的网盘/我的应用数据/bypy
自动备份shell脚本
#!/bin/sh bypy upload /usr/share/san/xx.db -v
保存文件为bakDB.sh
定时备份
利用linux自带crontab定时功能,编辑定时任务
crontab -e
这里每月一日自动备份
0 0 1 * * sh /usr/share/san/shell/bakDB.sh
参考资料
https://www.jianshu.com/p/11f071e1f7fe
本文由 SAn 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2020/05/15 21:30