!/bin/bash
使用环境变量设置pg密码
export PGUSER=xxxx
export PGPASSWORD=xxxx
pghost="xxxxx"
logfile="/db/log/dump/pg_dump_backup_$(date '+%d').log"
touch $logfile
echo "" > $logfile
backup_dir="/db/dump_files"
timeslot=date '+%Y%m%d'
dateinfo=date '+%Y-%m-%d %H:%M:%S'
echo "$dateinfo Starting backup of databases " &>> $logfile
/usr/bin/pg_dump -h $pghost -U $PGUSER -w -F c -b -v -f $backup_dir/$timeslot.dmp databasename &>> $logfile
dateinfo=date '+%Y-%m-%d %H:%M:%S'
echo "$dateinfo done backup of databases " >> $logfile
dateinfo=date '+%Y-%m-%d %H:%M:%S'
echo "$dateinfo Starting delete expired backup " >> $logfile
find $backup_dir -type f -mtime +2 -exec rm -f {} ;
dateinfo=date '+%Y-%m-%d %H:%M:%S'
echo "$dateinfo done delete expired backup " >> $logfile
find /db/log/dump -type f -mtime +2 -exec rm -f {} ;
echo " " >> $logfile
标签:dateinfo,-%,备份,echo,pg,date,logfile,backup,数据库 From: https://www.cnblogs.com/issac-9608/p/17879348.html