Update for pg_dump backups
parent
89333e35c6
commit
2cffb2c2cb
25
Dockerfile
25
Dockerfile
|
|
@ -1,13 +1,16 @@
|
||||||
FROM ubuntu:18.10 as builder
|
FROM ubuntu:20.04 as builder
|
||||||
RUN apt -y update \
|
RUN apt -y update || true; apt -y install gcc
|
||||||
&& apt -y install gcc
|
|
||||||
COPY ./pause /pause
|
COPY ./pause /pause
|
||||||
RUN cd /pause && gcc ./main.c -o pauser
|
RUN cd /pause && gcc ./main.c -o pauser
|
||||||
|
|
||||||
FROM ubuntu:18.10
|
FROM ubuntu:20.04
|
||||||
RUN groupadd postgres && useradd -d /home/postgres -ms /bin/bash -g postgres -G sudo postgres
|
RUN groupadd postgres && useradd -d /home/postgres -ms /bin/bash -g postgres -G sudo postgres
|
||||||
RUN apt -y update \
|
RUN export DEBIAN_FRONTEND=noninteractive; \
|
||||||
&& apt -y install \
|
apt -y update || true; \
|
||||||
|
apt -y install tzdata; \
|
||||||
|
ln -fs /usr/share/zoneinfo/America/Denver /etc/localtime; \
|
||||||
|
dpkg-reconfigure --frontend noninteractive tzdata; \
|
||||||
|
apt -y install \
|
||||||
curl \
|
curl \
|
||||||
rsync \
|
rsync \
|
||||||
cron \
|
cron \
|
||||||
|
|
@ -40,17 +43,17 @@ COPY --from=builder /pause/pauser /pauser
|
||||||
USER root
|
USER root
|
||||||
### CRON BACKUPS
|
### CRON BACKUPS
|
||||||
RUN true \
|
RUN true \
|
||||||
&& echo 'service postgresql stop && sleep 5 && b=$(date +%Y%m%d%H) && mkdir -p /mnt/save/$b && rsync -avzP --delete /var/lib/postgresql/10/main/ /mnt/save/$b/ && service postgresql start' > /backup.sh \
|
&& echo 'b=$(date +%Y%m%d%H%M%S) && mkdir -p /mnt/save/$b && pg_dump $DATABASE_URL > /mnt/save/$b/pg.dump' > /backup.sh \
|
||||||
&& echo 'service postgresql stop && sleep 5 && b=$(find /mnt/save -mindepth 1 -maxdepth 1 | sort | tail -n 1); if [ -n "$b" ]; then rsync -avzP --delete "${b%/}/" /var/lib/postgresql/10/main/; fi && chown -R postgres /var/lib/postgresql && chmod -R 0700 /var/lib/postgresql && service postgresql start;' > /restore.sh \
|
&& echo 'b=$(find /mnt/save -type f | sort | tail -n 1); if [ -n "$b" ]; then echo restoring $b; psql $DATABASE_URL < "$b"; fi && service postgresql start;' > /restore.sh \
|
||||||
&& echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \
|
&& echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \
|
||||||
&& echo '' >> /etc/cron.d/backups \
|
&& echo '' >> /etc/cron.d/backups \
|
||||||
&& chmod 0644 /etc/cron.d/backups \
|
&& chmod 0644 /etc/cron.d/backups \
|
||||||
&& touch /var/log/cronj.log
|
&& touch /var/log/cronj.log
|
||||||
|
|
||||||
ENTRYPOINT \
|
ENTRYPOINT \
|
||||||
bash /restore.sh \
|
service postgresql start \
|
||||||
&& service postgresql start \
|
&& until psql $DATABASE_URL < /dev/null; do sleep 5; done \
|
||||||
&& sleep 10 \
|
&& bash /restore.sh \
|
||||||
&& miniflux -migrate \
|
&& miniflux -migrate \
|
||||||
&& miniflux -create-admin \
|
&& miniflux -create-admin \
|
||||||
&& miniflux \
|
&& miniflux \
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ int main() {
|
||||||
printf("Waiting...\n");
|
printf("Waiting...\n");
|
||||||
stat = sigwait(&set, &sig);
|
stat = sigwait(&set, &sig);
|
||||||
printf("Wait complete: %i (%i)\n", sig, stat);
|
printf("Wait complete: %i (%i)\n", sig, stat);
|
||||||
printf("Stopped postgres: %i\n", system("service postgresql stop && sleep 5"));
|
|
||||||
printf("Saved postgres: %i\n", system("bash /backup.sh"));
|
printf("Saved postgres: %i\n", system("bash /backup.sh"));
|
||||||
|
printf("Bye-bye!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue