@@ -30,10 +30,6 @@ if [ "$BACKUP_THREADS" = "" ]; then
3030 BACKUP_THREADS=4
3131fi
3232
33- if [ " $BACKUP_MODE " = " " ]; then
34- BACKUP_MODE=page
35- fi
36-
3733if [ " $BACKUP_STREAM " = " " ]; then
3834 BACKUP_STREAM=" stream"
3935fi
5147
5248if [ " $DOW " = " 6" ] ; then
5349 # make a full backup once a week (Saturday)
54- BACKUP_MODE =full
50+ BACKUPMODE =full
5551else
5652 # make an incremental backup on other days of the week
57- BACKUP_MODE =page
53+ BACKUPMODE =page
5854fi
59-
60- if [ " $1 " != " " ]; then
55+ if [ " $BACKUP_MODE " != " " ]; then
6156 # The backup creation mode is given forcibly
62- BACKUP_MODE= $1
57+ BACKUPMODE= $BACKUP_MODE
6358fi
6459
6560BACKUP_STREAM=" --stream"
@@ -75,7 +70,6 @@ if [ "$3" != "" ]; then
7570 BACKUP_THREADS=$3
7671fi
7772
78-
7973cd $BACKUP_PATH
8074
8175COUNT_DIR=` ls -l $BACKUP_PATH | grep " ^d" | wc -l`
@@ -98,21 +92,33 @@ if ! [ -f $PGDATA/archive_active.trigger ] ; then
9892 su - postgres -c " touch $PGDATA /archive_active.trigger"
9993fi
10094
101- if [[ " $IS_FULL " = " " || $BACKUP_MODE = " full" ]] ; then
95+ if [[ " $IS_FULL " = " " || $BACKUPMODE = " full" ]] ; then
10296 # Full backup needs to be forcibly
103- su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR backup --backup-path=$BACKUP_PATH -b full $BACKUP_STREAM --instance=$PG_MAJOR -w --threads=$BACKUP_THREADS --delete-expired --delete-wal "
97+ su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR backup --backup-path=$BACKUP_PATH -b full $BACKUP_STREAM --instance=$PG_MAJOR -w --threads=$BACKUP_THREADS "
10498else
10599 # Backup type depends on day or input parameter
106- su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR backup --backup-path=$BACKUP_PATH -b $BACKUP_MODE $BACKUP_STREAM --instance=$PG_MAJOR -w --threads=$BACKUP_THREADS --delete-expired --delete-wal"
100+ if [[ $BACKUPMODE = " merge" ]]; then
101+ # в этом режиме здесь всегда PAGE
102+ su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR backup --backup-path=$BACKUP_PATH -b page $BACKUP_STREAM --instance=$PG_MAJOR -w --threads=$BACKUP_THREADS "
103+ else
104+ su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR --backup-path=$BACKUP_PATH -b $BACKUPMODE $BACKUP_STREAM --instance=$PG_MAJOR -w --threads=$BACKUP_THREADS "
105+ fi
107106 STATUS=` su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR show --backup-path=$BACKUP_PATH --instance=$PG_MAJOR --format=json | jq -c '.[].backups[0].status'" `
108107 LAST_STATE=${STATUS// ' "' / ' ' }
109108 if [[ " $LAST_STATE " = " CORRUPT" || " $LAST_STATE " = " ERROR" || " $LAST_STATE " = " ORPHAN" ]] ; then
110109 # You need to run a full backup, as an error occurred with incremental
111110 # Perhaps the loss of the segment at Failover ...
112- su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR backup --backup-path=$BACKUP_PATH -b full $BACKUP_STREAM --instance=$PG_MAJOR -w --threads=$BACKUP_THREADS --delete-expired --delete-wal "
111+ su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR backup --backup-path=$BACKUP_PATH -b full $BACKUP_STREAM --instance=$PG_MAJOR -w --threads=$BACKUP_THREADS "
113112 fi
114113fi
115114
115+ if [[ $BACKUPMODE = " merge" ]] ; then
116+ # объединяем старые бэкапы в соответствии с настройками
117+ su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR delete --backup-path=$BACKUP_PATH --instance=$PG_MAJOR --delete-expired --delete-wal --merge-expired --no-validate --threads=$BACKUP_THREADS "
118+ else
119+ # чистим старые бэкапы в соответствии с настройками
120+ su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR delete --backup-path=$BACKUP_PATH --instance=$PG_MAJOR --delete-expired --delete-wal --threads=$BACKUP_THREADS "
121+ fi
116122
117123# collecting statistics on backups
118124su - postgres -c " /usr/bin/pg_probackup-$PG_MAJOR show --backup-path=$BACKUP_PATH > ~postgres/backups.txt"
0 commit comments