postgresql 库备份

#!/bin/sh
#数据库备份目录
WORKDIR=$(cd $(dirname $0); pwd)
backupdir="$WORKDIR/db_backup/"

[[ -d ${backupdir} ]] || mkdir ${backupdir}

# 数据库备份文件名称,以时间作为唯一码
today=$(date +%Y-%m-%d)
echo $today

#备份所有数据库
/data/pgsql/postgresql/bin/pg_dumpall -h you-remote-ip -p 5432 -U postgres  >  $backupdir/oa_$today.pgsql
echo success!

#删除15天前的备份文件:mmin分钟、mtime天
# find $backupdir -mtime +15 -name "*.sql" -exec sudo rm -rf {} \;

Last updated