#!/bin/bash
bakdir=/data/pg_bak
logdir=/tools/backup/pgbaklog/`date +%w`pgbak.log
receive=xxx@163.com
get_ip() {
)
cmd_get_ip=$(/sbin/ifconfig |grep "192.168.1\." |awk -F ' ' '{print $2}'|tr -d "地址:"|tr -d "addr:")
echo $cmd_get_ip
}
ip=$(get_ip)
bak() {
cd $bakdir
find ./ -name \*.sql.gz -mtime +6 -delete
/usr/local/postgsql/bin/pg_dump -U User -F c dbname| gzip > erp$(date +%Y%m%d%H%M%S).sql.gz
echo $? >> /tools/lxj-bakpg.log
a=`cat /tools/lxj-bakpg.log`
if [ 0 != $a ];then
echo $ip"---erp数据库备份失败" | mail -s $ip'--erp数据库备份失败' $receive
fi
}
dubakdir() {
echo -e "备份存储路径:$bakdir\\n`ls -lh $bakdir/`" | mail -s $ip'数据库备份情况成功' $receive
}
if [ -d $bakdir ];then
bak
dubakdir
else
echo $ip'备份存储路径被删除,即将重新建立,继续备份'| mail -s $ip'备份路径异常' $receive
mkdir -p $bakdir
bak
dubakdir
fi