发布网友 发布时间:2022-04-07 21:13
共3个回答
懂视网 时间:2022-04-08 01:34
脚本功能:
系统环境:SUSE Linux Server 11.3 X64
1.删除3天前压缩文件(.bak.tar.gz)
2.备份数据库(未压缩文件.bak)
3.压缩昨天数据库备份文件(.bak.tar.gz),删除昨天数据库备份未压缩文件(.bak)
#!/bin/bash
export PATH=$PATH:/usr/local/pgsql/bin
DATE=`date +%Y_%m_%d_%H`
YESDAY=`date -d "yesterday" +%Y_%m_%d_%H`
TWODAGO=`date -d "3 day ago" +%Y_%m_%d_%H`
PGHOME="/home/postgres"
cd $PGHOME
echo "Dir list before delete 3 day ago backup file: "
ls -lrt
#### delete 3 day ago backup file ####
TDAFILE="testdb_"$TWODAGO".bak.tar.gz"
echo "Detele 3 Day ago file: "$TDAFILE
rm "$TDAFILE"
echo "Dir list after delete 3 day ago backup file: "
ls -lrt
#### Backup ape database ####
echo $DATE
echo "Starting backup database: ape ...."
su - postgres -c "pg_dump testdb > /home/postgres/testdb_$DATE.bak"
reval=#?
if reval=0
then
echo "Database testdb backup Successful!"
else
echo "Database testdb backup Failed!"
fi
echo "Dir list After backup database testdb: "
ls -lrt
#### Compress and remove yesterday bak file####
COMFILE="testdb_"$YESDAY".bak.tar.gz"
YDFILE="testdb_"$YESDAY".bak"
echo "tar zcvf $COMFILE $YDFILE"|sh
echo "General yesterday tar file: "$COMFILE
rm "$YDFILE"
echo "delete yesterday file: "$YDFILE
echo "Dir list After tar yesterday backup file: "
ls -lrt
find /home/postgres -mtime +3 -name "*.bak" -exec rm -rf {} ;
find /home/postgres -mtime +3 -name "*.bak.tar.gz" -exec rm -rf {} ;
本文出自 “yiyi” 博客,请务必保留此出处http://heyiyi.blog.51cto.com/205455/1658896
postgreSQL备份脚本删除3天前备份同时压缩昨天备份
标签:postgresql shell
热心网友 时间:2022-04-07 22:42
这样备份恢复:热心网友 时间:2022-04-08 00:00
规划局根据v解决V刹v法规及合同根据