pg 全备脚本

切换到普通用户下
su - postgres
定时任务是每周六晚上23点执行一次

source /etc/profile
. ~/.bash_profile
#!/bin/bash


BDATE=`date +%Y%m%d%H%M%S`
BPATH=/backup
pg_dumpall> ${BPATH}/PICC_${BDATE}.sql

    if [[ $? == 0 ]];then
        cd $BPATH
        tar zcvf PICC_$BDATE.tar.gz  PICC_${BDATE}.sql
        size=$(du PICC_$BDATE.tar.gz -sh | awk '{print $1}')
        rm -rf PICC_${BDATE}.sql
        echo "$BDATE 备份 $size 成功 "|mail -s "backup" [email protected]
    else
        cd $backup_path
        rm -rf PICC_${BDATE}.sql
        echo "$date 备份 $dbname 失败 "|mail -s "backup" [email protected]
    fi
for tfile in $(find $BPATH/ -mtime +15)
do
if [ -d $tfile ];then
rm -rf $tfile
elif [ -f $tfile ];then
rm -rf $tfile
fi
done

你可能感兴趣的:(pg 全备脚本)