dump_yapi_db.sh
#!/bin/bash
#autors: chunk
#date:2021-04-21
#version 0.1
set -e
#yapi 本地服务器-备份存放地址
LocalBackDir=/backup/xxxxxxx/yapi
#以当前时间戳创建备份目录
bakname=$(date -d "today" +"%Y%m%d_%H%M%S")
BakDir=$LocalBackDir/$bakname
mkdir $BakDir
#备份日志文件
LogFile=$LocalBackDir/yapi_backup.log
#记录db备份日志
echo "Yapi db auto backup at local server, start at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
echo "--------------------------------------------------------------------------" >> $LogFile
#执行Yapi本地备份,压缩备份数据
docker exec yapi-mongo mongodump -d yapi --gzip -o /data/db/backup/ #yapi搭建在容器testyapi里
cp -r /opt/docker-YApi/data/db/backup/yapi/ $BakDir
# $?符号显示上一条命令的返回值,如果为0则代表执行成功,其他表示失败
if [ $? -eq 0 ];then
#追加日志到日志文件
echo "--------------------------------Success!-------------------------------" >> $LogFile
echo "Yapi auto backup at local server, end at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
else
#追加日志到日志文件
echo "--------------------------------Failed!----------------------------------" >> $LogFile
echo "Yapi auto backup at local server failed at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
fi
网友评论