MySQL备份Shell例子

#!/bin/bash

timestamp=$(date +%Y-%m-%d-%H-%M-%S)
bak_file="/opt/bigops-dbbak/172_31_173_22_3306-${timestamp}.sql.gz"
bak_path=$(dirname ${bak_file})

if [ ! -d "${bak_path}" ];then
  mkdir -p "${bak_path}"
else
  #删除7天前的备份
  find "${bak_path}" -name "*.sql.gz" -mtime +7 -exec rm -vf {} \;
fi

mysqldump -h 172.31.173.22 -uadmin -pqq666666 --master-data --single-transaction bigops | pv -q -L10m | gzip >${bak_file} 2>&1

if [ $? == 0 ];then echo "bak_status=成功";else echo "bak_status=失败";fi

if [ -f "${bak_file}" ];then echo "bak_file_size=$(du -sh ${bak_file} |awk '{print $1}')";fi

echo "bak_file=${bak_file}"
echo "bak_fs_usage=$(df -h|grep '^/dev/vda1'|awk '{print $5}'|awk -F% '{print $1}')"
#echo "bak_ip=192.168.50.50"

results matching ""

    No results matching ""