postgreSQL进程检测与数据库备份脚本

postgreSQL进程检测与数据库备份脚本,第1张

概述脚本功能: 系统环境:SUSE Linux Server 11.3 X64 数据库进程检测重启。 数据库备份压缩脚本。 #### Check DB Process Script #### #!/bin/sh YEAR=`date +%Y` MON=`date +%m` DAY=`date +%d` HOUR=`date +%H` MIN=`date +%M` echo "$YEAR-$MON-$D

脚本功能:

系统环境:SUSE linux Server 11.3 X64

数据库进程检测重启。

数据库备份压缩脚本。



#### Check DB Process Script ####


#!/bin/sh

YEAR=`date +%Y`

MON=`date +%m`

DAY=`date +%d`

HOUR=`date +%H`

MIN=`date +%M`

echo "$YEAR-$MON-$DAY $HOUR:$MIN" > /opt/pgdb/cron/dbstatus.log

servname="postmaster"

DBSTAT=`ps -ef|grep $servname|grep -v 'grep'`

if [ "$DBSTAT" == "" ];

then

echo "testdb DB is down" >> /opt/pgdb/cron/dbstatus.log

echo "testdb database is down"|mailx -s "testdb DB down" user01@baIDu.com

DBstus=`ps -ef|grep $servname|grep -v 'grep'`

while [ "$DBstus" == "" ];

do

if ["$DBstus" == ""];

then

echo "DB starting ..." >> /opt/pgdb/cron/dbstatus.log

/etc/init.d/postgresql start

DBstus=`ps -ef|grep $servname|grep -v 'grep'`

else

echo "testdb DB already running."

fi

done

else

echo "testdb DB is running." >> /opt/pgdb/cron/dbstatus.log

fi





#### Backup DB Script ####


#!/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`


del_file_3ago() {

#### delete 3 day ago backup file ####

PGHOME="/home/postgres"

cd $PGHOME

echo "Dir List before delete 3 day ago backup file: "

ls -lrt

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

}


process_yesterday_bak() {

#### Compress and remove yesterday bak file####

PGHOME="/home/postgres"

cd $PGHOME

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

}


#### Backup testdb database ####


echo $DATE

echo "Starting backup database: testdb ...."

echo "">/home/postgres/pgbk_fail.txt

su - postgres -c "pg_dump testdb > /home/postgres/testdb_$DATE.bak 2>/home/postgres/pgbk_fail.txt"

grep Failed /home/postgres/pgbk_fail.txt

if [ $? -eq 0 ]

then

echo "Database testdb backup Failed!"

else

echo "Database testdb backup Successful!"

del_file_3ago

process_yesterday_bak

fi

echo "Dir List After backup database testdb: "

ls -lrt

总结

以上是内存溢出为你收集整理的postgreSQL进程检测与数据库备份脚本全部内容,希望文章能够帮你解决postgreSQL进程检测与数据库备份脚本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1175742.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存