DEFINITIONS

Definitions More Info.
Definition ID969
TitlePOSTGRESQL
CategoryNOTES
DefinitionPostgresql shell backup Kariyer BluCollar
Definition Description#!/bin/bash
#This backup process starts by postgres system account cron job.
#Bu backup islemi postgres sistem kullanicisinin cron job tarafindan calistirilmaktadir
#EditDate: 20190527 12:50
#Edited By: Cuneyd Tanriverdi
#[email protected]

# Backup Start Date
Year=$(date +%Y)
Month=$(date +%m)
Day=$(date +%d)
current_time=$(date "+%Y%m%d%H%M%S")
backupPath=/storage/backup/$Year

#yeni yil dosyasi yoksa, olustur
if [ ! -d /storage/backup/$Year ]; then
mkdir /storage/backup/$Year
#dosyay postgres kullanicisi icin izin ver
chown postgres:postgres /storage/backup/$Year
fi

#Yedeklerin tarih uzantili dosyalari olusturulur
echo "`date`: Yedek dosyaları oluşturuluyor" >> /storage/pgscripts/scriptlogs/BlueCollar_$current_time.log
mkdir /storage/backup/$Year/BlueCollar_$current_time
mkdir /storage/backup/$Year/BlueCollarLog_$current_time
mkdir /storage/backup/$Year/BlueCollarPushNotification_$current_time
mkdir /storage/backup/$Year/BlueCollarPushNotificationLog_$current_time
mkdir /storage/backup/$Year/Core_$current_time
mkdir /storage/backup/$Year/CoreLog_$current_time

#7 gunden onceki backuplar silinir
echo "Silinen backup dosyalari" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
find /storage/backup/$Year/* -type d -ctime +7 -exec >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
find /storage/backup/$Year/* -type d -ctime +7 -exec rm -rf {} \; >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "============================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log

#15 gunden onceki log dosyalari silinir
echo "Silinen log dosyalari" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
find /storage/pgscripts/scriptlogs/* -type f -ctime +15 >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
find /storage/pgscripts/scriptlogs/* -type f -ctime +15 -exec rm -rf {} \; >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "============================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log

#BlueCollar backup
echo "`date`: BlueCollar backup işlemi başladı" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
pg_dump -U postgres -d BlueCollar -Fc -v --compress=9 >> /storage/backup/$Year/BlueCollar_$current_time/BlueCollar_$current_time.bck
echo "`date`: BlueCollar backupişlemi bitti" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "===========================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log

#BlueCollarLog backup
echo "`date`: BlueCollarLog backup işlemi başladı" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
pg_dump -U postgres -d BlueCollarLog -Fc -v --compress=9 /storage/backup/$Year/BlueCollarLog_$current_time/BlueCollarLog_$current_time.bck
echo "`date`: BlueCollarLog backupişlemi bitti" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "==========================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log

#BlueCollarPushNotification backup
echo "`date`: BlueCollarPushNotification backup işlemi başladı" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
pg_dump -U postgres -d BlueCollarPushNotification -Fc -v --compress=9 >> /storage/backup/$Year/BlueCollarPushNotification_$current_time/BlueCollarPushNotification_$current_time.bck
echo "`date`: BlueCollarPushNotification backupişlemi bitti" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "============================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log

#BlueCollarPushNotificationLog backup
echo "`date`: BlueCollarPushNotificationLog backup işlemi başladı" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
pg_dump -U postgres -d BlueCollarPushNotificationLog -Fc -v --compress=9 >> /storage/backup/$Year/BlueCollarPushNotificationLog_$current_time/BlueCollarPushNotificationLog_$current_time.bck
echo "`date`: BlueCollarPushNotificationLog backupişlemi bitti" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "===========================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log

#Core backup
echo "`date`: Core backup işlemi başladı" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
pg_dump -U postgres -d Core -Fc -v --compress=9 >> /storage/backup/$Year/Core_$current_time/Core_$current_time.bck
echo "`date`: Core backupişlemi bitti" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "============================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log

#CoreLog backup
echo "`date`: CoreLog backup işlemi başladı" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
pg_dump -U postgres -d CoreLog -Fc -v --compress=9 >> /storage/backup/$Year/CoreLog_$current_time/CoreLog_$current_time.bck
echo "`date`: CoreLog backupişlemi bitti" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
echo "============================================================" >> /storage/pgscripts/scriptlogs/PGBackupLog_$current_time.log
RecordBycunay
Record Date24-08-2019 12:03:14
Düzenle
Kopyala
Sil