Skip to content

Commit 92c95c3

Browse files
committed
Chore: Update walg and adminapi pitr scripts
Signed-off-by: Lakshmipathi <[email protected]>
1 parent f3903f4 commit 92c95c3

File tree

7 files changed

+40
-3
lines changed

7 files changed

+40
-3
lines changed

ansible/files/admin_api_scripts/commence_walg_backup.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
set -euo pipefail
44

5-
WALG_SENTINEL_USER_DATA="{ \"project_id\": $1, \"backup_id\": $2 }" nohup wal-g backup-push /var/lib/postgresql/data --config /etc/wal-g/config.json --verify >> /var/log/wal-g/backup-push.log 2>&1 &
6-
7-
echo "WAL-G backup job commenced"
5+
if [ ! -f /usr/bin/admin-mgr ]; then
6+
WALG_SENTINEL_USER_DATA="{ \"project_id\": $1, \"backup_id\": $2 }" nohup wal-g backup-push /var/lib/postgresql/data --config /etc/wal-g/config.json --verify >> /var/log/wal-g/backup-push.log 2>&1 &
7+
echo "WAL-G backup job commenced"
8+
else
9+
/usr/bin/admin-mgr commence-backup "$1" "$2"
10+
echo "WAL-G backup job commenced" | systemd-cat -t commence_walg_backup.sh -p emerg
11+
fi

ansible/files/admin_api_scripts/commence_walg_restore.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,10 @@ function commence_walg_restore {
4545

4646
set -euo pipefail
4747

48+
if [ ! -f /usr/bin/admin-mgr ]; then
4849
commence_walg_restore "$1" "$2" >> /var/log/wal-g/backup-fetch.log 2>&1 &
4950
echo "WAL-G restore job commenced"
51+
else
52+
/usr/bin/admin-mgr commence-restore "$1" "$2"
53+
echo "WAL-G restore job commenced" | systemd-cat -t commence_walg_restore.sh -p emerg
54+
fi

ansible/files/admin_api_scripts/complete_walg_restore.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -euo pipefail
44

5+
if [ ! -f /usr/bin/admin-mgr ]; then
56
# Disable recovery commands in the event of a restart
67
sed -i "s/.*restore_command/#restore_command/" /etc/postgresql-custom/wal-g.conf
78
sed -i "s/.*recovery_target_time/#recovery_target_time/" /etc/postgresql-custom/wal-g.conf
@@ -13,3 +14,7 @@ sed -i "s/.*recovery_target_inclusive/#recovery_target_inclusive/" /etc/postgres
1314
rm -rf /tmp/walg_data/ /tmp/.wal-g/ /tmp/wal_fetch_dir/
1415

1516
echo "Cleanup post WAL-G restoration complete"
17+
else
18+
/usr/bin/admin-mgr complete-restore
19+
echo "Cleanup post WAL-G restoration complete" | systemd-cat -t complete_walg_restore.sh -p emerg
20+
fi

ansible/files/admin_api_scripts/disable_walg.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
set -euo pipefail
44

5+
if [ ! -f /usr/bin/admin-mgr ]; then
56
sed -i "s/.*archive_mode/#archive_mode/" /etc/postgresql-custom/wal-g.conf
67
sed -i "s/.*archive_command/#archive_command/" /etc/postgresql-custom/wal-g.conf
78
sed -i "s/.*archive_timeout/#archive_timeout/" /etc/postgresql-custom/wal-g.conf
89

910
systemctl restart postgresql
1011

1112
echo "WAL-G successfully disabled"
13+
else
14+
/usr/bin/admin-mgr disable-walg
15+
chmod -x /usr/bin/admin-mgr
16+
echo "WAL-G successfully disabled" | systemd-cat -t disable_walg.sh -p emerg
17+
fi

ansible/files/admin_api_scripts/enable_walg.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
set -euo pipefail
44

5+
if [ ! -f /usr/bin/admin-mgr ]; then
56
sed -i "s/.*archive_mode/archive_mode/" /etc/postgresql-custom/wal-g.conf
67
sed -i "s/.*archive_command/archive_command/" /etc/postgresql-custom/wal-g.conf
78
sed -i "s/.*archive_timeout/archive_timeout/" /etc/postgresql-custom/wal-g.conf
89

910
systemctl restart postgresql
1011

1112
echo "WAL-G successfully enabled"
13+
else
14+
/usr/bin/admin-mgr enable-walg
15+
#replace restore_command
16+
sed -i '/restore_command/d' /etc/postgresql-custom/wal-g.conf
17+
echo "#restore_command = '/usr/bin/admin-mgr wal-fetch %f %p >> /var/log/wal-g/wal-fetch.log 2>&1'" >> /etc/postgersql-custom/wal-g.conf
18+
chmod +x /usr/bin/admin-mgr && chmod ug+s /usr/bin/admin-mgr
19+
echo "WAL-G successfully enabled" | systemd-cat -t enable_walg.sh -p emerg
20+
fi

ansible/files/walg_helper_scripts/wal_change_ownership.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -euo pipefail
44

5+
if [ ! -f /usr/bin/admin-mgr ]; then
56
filename=$1
67

78
if [[ -z "$filename" ]]; then
@@ -40,3 +41,6 @@ fi
4041

4142
# once valid, proceed to change ownership
4243
chown postgres:postgres "$full_path"
44+
else
45+
echo "Do nothing, handled via admin-mgr"
46+
fi

ansible/files/walg_helper_scripts/wal_fetch.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -euo pipefail
44

5+
if [ ! -f /usr/bin/admin-mgr ]; then
56
# Fetch the WAL file and temporarily store them in /tmp
67
sudo -u wal-g wal-g wal-fetch "$1" /tmp/wal_fetch_dir/"$1" --config /etc/wal-g/config.json
78

@@ -10,3 +11,6 @@ sudo -u root /root/wal_change_ownership.sh "$1"
1011

1112
# Move file to its final destination
1213
mv /tmp/wal_fetch_dir/"$1" /var/lib/postgresql/data/"$2"
14+
else
15+
echo "Do nothing, handled via wal-g.conf file"
16+
fi

0 commit comments

Comments
 (0)