linux下bypy自动备份脚本

发表于 2020-03-15  2.4k 次阅读


安装bypy

pip install bypy

登陆账号进行授权

bypy info
将链接在浏览器打开登陆账号
将授权码输入至终端
回车等待完成,完成后回显网盘容量
网盘上传文件位置在"我的应用数据>bypy"目录下

自动备份脚本

#!/bin/bash
#默认备份至"我的数据>bypy>ali_day-bak-data"目录
DATE=`date +%F`
DATA1=`date +%F--%T`
fwq="Day-backup"
mkdir -p /opt/ajocsjdncadsdf12df09adsf/bak/
#创建压缩包临时存放文件夹

PASSWd=YOURPASSWD 
#压缩包密码

MyEmail=Scanz@izhuhn.cn
#收信地址##需要提前配置mail.rc接入发信地址

tar -czvf - /var/www/html/blog /etc /etc/shell   |  openssl des3 -salt -k $PASSWd -out /opt/ajocsjdncadsdf12df09adsf/bak/$DATE-daybak-log.tar.gz
#备份文件可自行更换

AA=`md5sum /opt/ajocsjdncadsdf12df09adsf/bak/$DATE-daybak-log.tar.gz`
echo "MD5:${AA}" > /opt/ajocsjdncadsdf12df09adsf/bak/$DATE-daybak-log.md5
#生成md5校验码
touch /tmp/ceshi/${DATE}-daybak-log.tar.gz 
/usr/local/bin/bypy upload /tmp/ceshi/${DATE}-daybak-log.tar.gz ali_day-bak-data
#bypy存在压缩包上传失败问题,需要先上传空文件绕过报错。
sleep 1
/usr/local/bin/bypy upload /opt/ajocsjdncadsdf12df09adsf/bak/$DATE-daybak-log.tar.gz ali_day-bak-data &>/tmp/${DATA1}-tar.log &

sleep 5

while :
do
	ps aux | grep -v grep | grep "bypy upload" > /dev/null
	if [ $? -ne 0 ]
	then
		/usr/local/bin/bypy ls  ali_day-bak-data${DATE}-daybak-log.tar.gz &>/tmp/${DATA1}-log 
                sleep 2
		/usr/local/bin/bypy ls  ali_day-bak-data | grep "$DATE-daybak-log.tar.gz" 
		if [ $? -eq 0 ]
		then
			break
		else
                        DATA2=`date +%F--%T`
			#/weixin --corpid=$ID    --corpsecret=$PASSWDNumber  --msg "${fwq}======${DATA1}======TarFile Upload ERROR======${DATA2}======${fwq}" --user=$Username --agentid=$Youridnumber
                        #微信推送
                        echo "${fwq}======${DATA1}======TarFile Upload ERROR======${DATA2}======${fwq}" | mail -s "TarFile Upload ERROR" ${MyEmail}
                        #邮件推送
			exit	
		fi
	else
		sleep 3
	fi
done

/usr/local/bin/bypy upload /opt/ajocsjdncadsdf12df09adsf/bak/$DATE-daybak-log.md5 ali_day-bak-data &>/tmp/${DATA1}-md5.log &

sleep 3

while :
do
	ps aux | grep -v grep | grep "bypy upload" > /dev/null
	if [ $? -ne 0 ]
	then
		/usr/local/bin/bypy ls ali_day-bak-data${DATE}-daybak-log.md5 &>/tmp/${DATA1}-log
                sleep 2
		/usr/local/bin/bypy ls ali_day-bak-data  | grep "$DATE-daybak-log.md5"
		if [ $? -eq 0 ]
		then
			break
		else
			DATA2=`date +%F--%T`
			#/weixin --corpid=$ID    --corpsecret=$PASSWDNumber  --msg "${fwq}======${DATA1}======Md5File Upload ERROR======${DATA2}======${fwq}" --user=$Username --agentid=$Youridnumber
                        #微信推送,需要接口信息,可以将邮件推送放到这里
                        echo "${fwq}======${DATA1}======Md5File Upload ERROR======${DATA2}======${fwq}" | mail -s "Md5File Upload ERROR" ${MyEmail}
                        #邮件推送
			exit
		fi
	else
		sleep 3
	fi
done

DATA2=`date +%F--%T`
echo "${DATA1}======Start======Md5:${AA}:Md5======End======${DATA2}" | mail -s "${fwq}" ${MyEmail} 
#邮件推送


#/weixin --corpid=$ID   --corpsecret=$PASSWDNumber  --msg "${fwq}======${DATA1}======Start======Md5:${AA}:Md5======End======${DATA2}======${fwq}" --user=$Username --agentid=$Youridnumber
#微信推送,需要接口信息

rm /opt/ajocsjdncadsdf12df09adsf/bak/* -rf
#压缩包解密
openssl des3 -d -k $PASSWd -salt -in /opt/ajocsjdncadsdf12df09adsf/bak/$DATE-daybak-log.tar.gz| tar xzf -
本站文章基于国际协议BY-NA-SA 4.0协议共享;
如未特殊说明,本站文章皆为原创文章,请规范转载。

3

scanz个人博客