fix
This commit is contained in:
parent
3e99025879
commit
18e973b6a9
@ -1,14 +1,17 @@
|
|||||||
FROM alpine:3.16
|
FROM docker.io/debian:latest
|
||||||
RUN apk update;apk add bash sudo postgresql postgresql-contrib dos2unix
|
RUN apt update;apt install -y bash sudo postgresql postgresql-contrib cron
|
||||||
|
|
||||||
WORKDIR /tmp
|
WORKDIR /tmp
|
||||||
ENV SHELL="/bin/bash"
|
ENV SHELL="/bin/bash"
|
||||||
|
ENV PG_VERSION=13
|
||||||
|
ENV PG_BIN=/usr/lib/postgresql/$PG_VERSION/bin
|
||||||
|
ENV PG_DIR=/var/lib/postgresql/$PG_VERSION/main
|
||||||
|
|
||||||
ADD start.sh /
|
COPY start.sh /
|
||||||
ADD setup.sh /
|
COPY setup.sh /
|
||||||
ADD backup.sh /
|
COPY backup.sh /
|
||||||
|
|
||||||
ADD crontab /
|
COPY crontab /
|
||||||
RUN crontab /crontab
|
RUN crontab /crontab
|
||||||
|
|
||||||
#POSTGRES Tweaks
|
#POSTGRES Tweaks
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
su postgres -s /bin/bash -lc "pg_dump -d pleroma --format=custom > /saves/pleroma-`date +%Y-%m-%d-%H-%M`.pgdump"
|
su postgres -s /bin/bash -lc "$PG_BIN/pg_dump -d pleroma --format=custom > /saves/pleroma-`date +%Y-%m-%d-%H-%M`.pgdump"
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
00 01 * * * bash /backup.sh
|
00 01 * * * bash /backup.sh
|
||||||
00 02 * * * find /saves/ -type f -mtime +3 -exec rm -f {} \;
|
00 02 * * * find /saves/ -type f -mtime +3 -exec rm -f {} \;
|
||||||
00 04 * * 7 su postgres -s $SHELL -lc "psql -d pleroma -c 'vacuum(full,analyse,verbose);'"
|
00 04 * * 7 su postgres -s $SHELL -lc "psql -d pleroma -c 'vacuum(full,analyse,verbose);'"
|
||||||
|
|
||||||
|
126
postgresql/postgres.sh
Normal file
126
postgresql/postgres.sh
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
databases+=( raygungothic nextcloud gitea prosody poster synapse minetest pooper )
|
||||||
|
VERSION="14"
|
||||||
|
NEW_VERSION="15"
|
||||||
|
export PATH=$PATH:/usr/lib/postgresql/$VERSION/bin
|
||||||
|
PG_BIN=/usr/lib/postgresql/$VERSION/bin
|
||||||
|
LOCATION='/raid/server/saves'
|
||||||
|
PG_DIR="/var/lib/postgresql/$VERSION/main"
|
||||||
|
NEW_PG_DIR="/var/lib/postgresql/$NEW_VERSION/main"
|
||||||
|
PRIMARY='192.168.0.153'
|
||||||
|
NEW_PG_BIN=/usr/lib/postgresql/$NEW_VERSION/bin
|
||||||
|
|
||||||
|
|
||||||
|
upgrade(){
|
||||||
|
mkdir -p $NEW_PG_DIR
|
||||||
|
chown -R postgres:postgres $NEW_PG_DIR
|
||||||
|
su postgres -s /bin/bash -lc "$NEW_PG_BIN/initdb $NEW_PG_DIR"
|
||||||
|
systemctl disable --now postgresql@$VERSION-main
|
||||||
|
su postgres -s /bin/bash -lc "$NEW_PG_BIN/pg_upgrade -d $PG_DIR -b $PG_BIN -B $NEW_PG_BIN -D $NEW_PG_DIR"
|
||||||
|
su postgres -s /bin/bash -lc "cp -f $PG_DIR/postgresql.conf $NEW_PG_DIR/"
|
||||||
|
su postgres -s /bin/bash -lc "cp -f $PG_DIR/pg_hba.conf $NEW_PG_DIR/"
|
||||||
|
systemctl enable --now postgresql@$NEW_VERSION-main
|
||||||
|
}
|
||||||
|
|
||||||
|
replication-status(){
|
||||||
|
echo "select * from pg_stat_replication;" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
echo "select * from pg_stat_wal_receiver;" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
echo "select pg_is_wal_replay_paused();" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
}
|
||||||
|
|
||||||
|
configure-secondary-replication () {
|
||||||
|
#echo "pg_ctl stop -D $PG_DIR" | su postgres -s /bin/bash
|
||||||
|
systemctl disable --now postgresql@$VERSION-main
|
||||||
|
cd $PG_DIR
|
||||||
|
rm -rf $PG_DIR/*
|
||||||
|
echo "$PG_BIN/pg_basebackup -R -P -h $PRIMARY -X stream -c fast -U root -W -D $PG_DIR/" | su postgres -s /bin/bash
|
||||||
|
chmod 0700 $PG_DIR
|
||||||
|
#echo "pg_ctl start -D $PG_DIR" | su postgres -s /bin/bash
|
||||||
|
systemctl enable --now postgresql@$VERSION-main
|
||||||
|
echo "select pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
grep primary_conninfo postgresql.auto.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
configure-primary-replication (){
|
||||||
|
#echo "SELECT * FROM pg_drop_replication_slot('db02_repl_slot');" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
#echo "select * from pg_create_physical_replication_slot('db02_repl_slot');" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
echo "select pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
echo "select slot_name, slot_type, active, wal_status from pg_replication_slots;" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
echo "$PG_BIN/pg_ctl restart -D $PG_DIR" | su postgres -s /bin/bash
|
||||||
|
}
|
||||||
|
|
||||||
|
replication-failover () {
|
||||||
|
echo "select pg_promote();" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
echo "SELECT pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
}
|
||||||
|
|
||||||
|
backup (){
|
||||||
|
vacuum_off
|
||||||
|
for i in "${databases[@]}"
|
||||||
|
do
|
||||||
|
echo;echo "Backing Up: "$i;echo
|
||||||
|
su postgres -s /bin/bash -lc "$PG_BIN/pg_dump -d $i --format=custom -f $LOCATION/$i-`cat /etc/hostname`-`date +%Y-%m-%d-%H-%M`.pgdump"
|
||||||
|
done
|
||||||
|
vacuum_on
|
||||||
|
}
|
||||||
|
|
||||||
|
vacuum_off (){
|
||||||
|
sed -i 's/autovacuum = on/autovacuum = off/i' $PG_DIR/postgresql.conf
|
||||||
|
echo "SELECT pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
}
|
||||||
|
|
||||||
|
vacuum_on (){
|
||||||
|
sed -i 's/autovacuum = off/autovacuum = on/i' $PG_DIR/postgresql.conf
|
||||||
|
echo "SELECT pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
|
||||||
|
}
|
||||||
|
|
||||||
|
vacuum (){
|
||||||
|
for i in "${databases[@]}"
|
||||||
|
do
|
||||||
|
echo "vacuum(full,analyse,verbose);" | su postgres $i -s /bin/bash -lc "psql "
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
help_menu (){
|
||||||
|
clear
|
||||||
|
echo "./postgres.sh backup"
|
||||||
|
echo "./postgres.sh replication-status"
|
||||||
|
echo "./postgres.sh configure-primary-replication"
|
||||||
|
echo "./postgres.sh configure-secondary-replication"
|
||||||
|
echo "./postgres.sh base"
|
||||||
|
echo "./postgres.sh replication-failover"
|
||||||
|
echo "./postgres.sh vacuum"
|
||||||
|
echo "./postgres.sh setup"
|
||||||
|
echo "./postgres.sh vacuum-on"
|
||||||
|
echo "./postgres.sh vacuum-off"
|
||||||
|
echo "./postgres.sh upgrade"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [ "$1" = "vacuum-on" ];
|
||||||
|
then vacuum_on;
|
||||||
|
elif [ "$1" = "vacuum-off" ];
|
||||||
|
then vacuum_off;
|
||||||
|
elif [ "$1" = "configure-primary-replication" ];
|
||||||
|
then configure-primary-replication;
|
||||||
|
elif [ "$1" = "replication-failover" ];
|
||||||
|
then replication-failover;
|
||||||
|
elif [ "$1" = "backup" ];
|
||||||
|
then backup "$2";
|
||||||
|
elif [ "$1" = "configure-secondary-replication" ];
|
||||||
|
then configure-secondary-replication;
|
||||||
|
elif [ "$1" = "replication-status" ];
|
||||||
|
then replication-status;
|
||||||
|
elif [ "$1" = "upgrade" ];
|
||||||
|
then upgrade;
|
||||||
|
elif [ "$1" = "restore" ];
|
||||||
|
then restore;
|
||||||
|
elif [ "$1" = "vacuum" ];
|
||||||
|
then vacuum;
|
||||||
|
elif [ "$1" = "vacfull" ];
|
||||||
|
then vacuum_full "$2";
|
||||||
|
else
|
||||||
|
help_menu
|
||||||
|
fi
|
||||||
|
|
@ -1,6 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export SHELL="/bin/bash"
|
export SHELL="/bin/bash"
|
||||||
|
|
||||||
#Database Setup
|
#Database Setup
|
||||||
mkdir /run/postgresql
|
mkdir /run/postgresql
|
||||||
#mkdir -p /var/lib/postgresql/13/main
|
#mkdir -p /var/lib/postgresql/13/main
|
||||||
@ -8,11 +7,12 @@ chown -R postgres:postgres /run/postgresql/
|
|||||||
chown -R postgres:postgres /var/lib/postgresql
|
chown -R postgres:postgres /var/lib/postgresql
|
||||||
chown -R postgres:postgres /var/log/postgresql
|
chown -R postgres:postgres /var/log/postgresql
|
||||||
#su postgres -s $SHELL -lc "mkdir /var/lib/postgresql/data;chmod 0700 /var/lib/postgresql/13/main"
|
#su postgres -s $SHELL -lc "mkdir /var/lib/postgresql/data;chmod 0700 /var/lib/postgresql/13/main"
|
||||||
su postgres -s $SHELL -lc "initdb --auth-host=trust -D /var/lib/postgresql/data"
|
su postgres -s $SHELL -lc "initdb --auth-host=trust -D $PG_DIR"
|
||||||
cp -f /etc/postgresql.conf /var/lib/postgresql/data/
|
cp -f /etc/postgresql.conf $PG_DIR/
|
||||||
echo "host all all 0.0.0.0/0 md5" >> /var/lib//postgresql/data/pg_hba.conf
|
echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/$PG_VERSION/main/pg_hba.conf
|
||||||
chown -R postgres:postgres /var/lib/postgresql
|
cp -f /etc/postgresql/$PG_VERSION/main/pg_hba.conf $PG_DIR/
|
||||||
su postgres -s $SHELL -lc "pg_ctl start -D /var/lib/postgresql/data"
|
chown -R postgres:postgres $PG_DIR
|
||||||
|
su postgres -s $SHELL -lc "$PG_BIN/pg_ctl start -D $PG_DIR"
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
echo "create user root with encrypted password 'sql';"| su postgres -s $SHELL -lc psql
|
echo "create user root with encrypted password 'sql';"| su postgres -s $SHELL -lc psql
|
||||||
|
@ -8,12 +8,8 @@ chmod -R 777 /saves
|
|||||||
#Configure Local Time
|
#Configure Local Time
|
||||||
cp -f /usr/share/zoneinfo/US/Mountain /etc/localtime
|
cp -f /usr/share/zoneinfo/US/Mountain /etc/localtime
|
||||||
|
|
||||||
#Windows Hack
|
|
||||||
dos2unix /postgres.sh
|
|
||||||
|
|
||||||
#Start Cron and Postgresql
|
#Start Cron and Postgresql
|
||||||
crond
|
cron
|
||||||
su postgres -s $SHELL -lc "pg_ctl start -D /var/lib/postgresql/data"
|
|
||||||
|
|
||||||
#Restore latest Database if container is new
|
#Restore latest Database if container is new
|
||||||
if [ ! -f "$FILE" ]
|
if [ ! -f "$FILE" ]
|
||||||
@ -23,4 +19,6 @@ bash /setup.sh
|
|||||||
touch /configured.txt
|
touch /configured.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
su postgres -s $SHELL -lc "$PG_BIN/pg_ctl start -D $PG_DIR"
|
||||||
|
|
||||||
tail -f /dev/null
|
tail -f /dev/null
|
||||||
|
Loading…
Reference in New Issue
Block a user