#!/bin/bash
#自动备份grafana数据库并上传到云盘
NOWDATE=`date +%Y-%m-%d`
YUNPAN_USER=xxxx
YUNPAN_PASSWD=XXXXXXXXXX
YUNPAN_SERVER=https://yunpan.x.com/remote.php/webdav
YUNPAN_DIR=x/backup/grafana
#建立备份基本目录环境
BACKUPDIR=/x/data/backup/grafana
[ -d ${BACKUPDIR} ] || mkdir -p ${BACKUPDIR}
#mysqldump备份
MYSQLDUMP=/usr/bin/mysqldump
SOCKET=/x/data/mysql/mysql.sock
DATABASE=grafana
${MYSQLDUMP} --defaults-extra-file=/home/x/sh/.my.cnf -S${SOCKET} ${DATABASE} | gzip -c -9 > ${BACKUPDIR}/${DATABASE}-backup-${NOWDATE}.sql.gz
sleep 2s
#上传到云盘
cd $BACKUPDIR
curl -X PUT -u $YUNPAN_USER:$YUNPAN_PASSWD --data-binary @"${DATABASE}-backup-${NOWDATE}.sql.gz" "$YUNPAN_SERVER/$YUNPAN_DIR/${DATABASE}-backup-${NOWDATE}.sql.gz"
#删除旧备份文件
find ${BACKUPDIR}/ -type f -mtime +7 -exec rm {} ;
认证文件
[mysqldump]
user=admin
password=xxxxx