Created
March 20, 2015 18:03
-
-
Save chiita/4c3b1af6ddccac1a318d to your computer and use it in GitHub Desktop.
Swap postgres DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
su -l postgres -c "pg_ctl start" | |
status=$0 | |
if [ $status=0 ]; then | |
logger "DBの起動が完了しました。" | |
else | |
logger "DBの停止に失敗しました" | |
fi | |
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
su -l postgres -c "pg_ctl stop" | |
status=$0 | |
if [ $status=0 ]; then | |
logger "DB停止完了しました。" | |
else | |
logger "DBの停止に失敗しました" | |
fi | |
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo | |
export ROLE=`/etc/rc.d/init.d/drbd status | grep Primary | awk '{print $3}'` | |
if [ $ROLE = "Secondary/Primary" ] | |
then | |
export STB=`hostname` | |
if [ $STB = "postgres01" ] | |
then | |
export ACT="postgres02" | |
else | |
export ACT="postgres01" | |
fi | |
echo | |
echo ===================================================== | |
echo " $ACT" | |
echo ===================================================== | |
rsh $ACT /root/stop.sh | |
#unmount mirror device | |
rsh $ACT /bin/umount /dev/drbd0 | |
/bin/logger "successful: unmounting /dev/drbd0" | |
#to secondary primary host | |
rsh $ACT /sbin/drbdadm secondary r0 | |
status=$? | |
#echo logs | |
if [ $status="0" ] | |
then | |
/bin/logger "successful: to standby postgres" | |
fi | |
rsh $ACT /etc/rc.d/init.d/drbd status | |
echo | |
echo | |
echo ===================================================== | |
echo " $STB" | |
echo ===================================================== | |
/sbin/drbdadm primary r0 | |
status=$? | |
if [ $status="0" ] | |
then | |
/bin/logger "successful: to primary postgres" | |
fi | |
/bin/mount /dev/drbd0 /pgdata | |
/bin/logger "successful: moun | |
/etc/rc.d/init.d/drbd status | |
/root/start.sh | |
echo | |
echo "[drbd] swapは正 | |
echo | |
else | |
export ACT=`hostname` | |
if [ $ACT = "postgres0 | |
then | |
export STB="postgr | |
else | |
export STB="postgr | |
fi | |
echo ================= | |
echo " $ACT" | |
echo ================= | |
/root/stop.sh | |
#unmount mirror device | |
/bin/umount /dev/drbd0 | |
/bin/logger "successfu | |
#to secondary primary | |
/sbin/drbdadm secondar | |
status=$? | |
#echo logs | |
if [ $status="0" ] | |
then | |
/bin/logger "succe | |
fi | |
/etc/rc.d/init.d/drbd | |
echo | |
echo | |
echo ================= | |
echo " $STB" | |
echo ================= | |
#to Primary Remote hos | |
rsh $STB /sbin/drbdadm | |
status=$? | |
if [ $status="0" ] | |
then | |
/bin/logger "succe | |
fi | |
rsh $STB /bin/mount /d | |
/bin/logger "successfu | |
rsh $STB /etc/rc.d/ini | |
rsh $STB /root/start.s | |
sleep 2 | |
echo | |
echo "[drbd] swapは正 | |
echo | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment