#!/bin/sh
#数据库备份目录
backupdir=/data/pg_back
DB=dbname
# 数据库备份文件名称,以时间作为唯一码
da=$(date +"%Y%m%d%H%M%S")
echo $da
#备份db_demo数据库
/usr/pgsql-13/bin/pg_dump "host=127.0.0.1 port=5432 user=postgres password=**** dbname=dbname" -a > $backupdir/${DB}_$da.sql
echo success!
#删除15天前的备份文件:mmin分钟、mtime天
find $backupdir -mtime +90 -name "*.sql" -exec sudo rm -rf {} \;
04-12
5734
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
06-05
2018
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
11-03
1066
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
10-29
1008
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
10-13
1018
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
11-11
1542
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
09-13
460
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)