安装qshell
cd /root wget http://devtools.qiniu.com/qshell-v2.1.8.zip unzip qshell-v.2.1.8.zip mkdir tool mv qshell_linux_x64 ./tool/qshell
2.添加全局访问
vim ~/.bashrc 插入 export PATH=$PATH:/root/tool
3. 编写压缩备份脚本
vim folderback.sh #!/bin/sh BACK_DIR="/home/repository/programbackup/" #压缩目录 BACK_TARGET="/home/repository/nongwanyun/" #目标目录 DATE=`date +%F` zip -rP 密码 $BACK_DIR"nongwanyun_back_"$DATE.zip $BACK_TARGET chmod +x folderback.sh
4. 编写七牛云配置文件
cd /root/tool/ mkdir conf cd conf touch qshell.conf vim qshell.conf #输入 { "src_dir" : "/home/repository/programbackup", #要备份的目录 "bucket" : "backup", "key_prefix" : "nongwanyun/", "access_key" : "七牛ak", "secret_key" : "七牛sk", "up_host" : "", "ignore_dir" : false, "overwrite" : false, "check_exists" : false, "check_hash" : false, "check_size" : false, "rescan_local" : true, "skip_file_prefixes" : "test,demo,", "skip_path_prefixes" : "hello/,temp/", "skip_fixed_strings" : ".svn,.git", "skip_suffixes" : ".DS_Store,.exe", "log_file" : "upload.log", "log_level" : "info", "log_rotate" : 1, "log_stdout" : false }
5.编写qshell上传脚本
cd /root touch folderupload.sh vim folderupload.sh #插入 #!/bin/sh qshell qupload 10 /root/tool/conf/qshell.conf #权限分配 chmod +x folderupload.sh
6.crontab 定时执行备份程序和上传程序
crontab -e #每月最后一天备份 4 4 * * * if [`date +%d -d tomorrow`=01];then; /bin/sh /root/folderback.sh #每月最后一天上传 4 5 * * * if [`date +%d -d tomorrow`=01];then; /bin/sh /root/folderupload.sh
7. Todo :实现本地备份文件2月之前的自动删除和七牛云两月之前自动删除
本文为Adamin90原创文章,转载无需和我联系,但请注明来自http://www.lixiaopeng.top