43 lines
1.7 KiB
Docker
Executable File
43 lines
1.7 KiB
Docker
Executable File
FROM ubuntu:18.10 as builder
|
|
RUN apt -y update \
|
|
&& apt -y install gcc
|
|
COPY ./pause /pause
|
|
RUN cd /pause && gcc ./main.c -o pauser
|
|
|
|
FROM ubuntu:18.10
|
|
RUN groupadd postgres && useradd -d /home/postgres -ms /bin/bash -g postgres -G sudo postgres
|
|
RUN apt -y update \
|
|
&& apt -y install \
|
|
curl \
|
|
rsync \
|
|
cron \
|
|
postgresql postgresql-contrib \
|
|
&& mkdir -p /mnt/save
|
|
USER postgres
|
|
RUN service postgresql start && sleep 10 \
|
|
&& psql --command "CREATE USER bel WITH SUPERUSER PASSWORD 'letme123in';" \
|
|
&& createdb -O bel letme123in \
|
|
&& psql --command "CREATE DATABASE db;" \
|
|
&& psql --command "GRANT ALL PRIVILEGES ON DATABASE db TO bel;" \
|
|
&& service postgresql stop && sleep 10
|
|
|
|
ENV DATABASE_URL=postgres://bel:letme123in@localhost/db?sslmode=disable
|
|
|
|
COPY --from=builder /pause/pauser /pauser
|
|
|
|
USER root
|
|
### CRON BACKUPS
|
|
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 '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 '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \
|
|
&& echo '' >> /etc/cron.d/backups \
|
|
&& chmod 0644 /etc/cron.d/backups \
|
|
&& touch /var/log/cronj.log
|
|
|
|
ENTRYPOINT \
|
|
bash /restore.sh \
|
|
&& service postgresql start \
|
|
&& sleep 10 \
|
|
&& miniflux & exec /pauser
|