Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
604b803f74 | ||
|
|
ab0944cbff | ||
|
|
cf008cd284 | ||
|
|
0421c8b8d9 | ||
|
|
a904244fd2 | ||
|
|
7ccb495a1a | ||
|
|
06e5ac98d1 | ||
|
|
2cffb2c2cb |
25
Dockerfile
25
Dockerfile
@@ -1,13 +1,16 @@
|
||||
FROM ubuntu:18.10 as builder
|
||||
RUN apt -y update \
|
||||
&& apt -y install gcc
|
||||
FROM ubuntu:18.04 as builder
|
||||
RUN apt -y update || true; apt -y install gcc
|
||||
COPY ./pause /pause
|
||||
RUN cd /pause && gcc ./main.c -o pauser
|
||||
|
||||
FROM ubuntu:18.10
|
||||
FROM ubuntu:18.04
|
||||
RUN groupadd postgres && useradd -d /home/postgres -ms /bin/bash -g postgres -G sudo postgres
|
||||
RUN apt -y update \
|
||||
&& apt -y install \
|
||||
RUN export DEBIAN_FRONTEND=noninteractive; \
|
||||
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 \
|
||||
rsync \
|
||||
cron \
|
||||
@@ -36,21 +39,21 @@ ENV RUN_MIGRATIONS=0
|
||||
ENV CREATE_ADMIN=0
|
||||
|
||||
COPY --from=builder /pause/pauser /pauser
|
||||
COPY backup.sh /
|
||||
COPY restore.sh /
|
||||
|
||||
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 \
|
||||
service postgresql start \
|
||||
&& until psql $DATABASE_URL < /dev/null; do sleep 5; done \
|
||||
&& bash /restore.sh \
|
||||
&& miniflux -migrate \
|
||||
&& miniflux -create-admin \
|
||||
&& miniflux \
|
||||
|
||||
12
backup.sh
Executable file
12
backup.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
b=$(date +%Y%m%d%H%M%S)
|
||||
mkdir -p /mnt/save/$b
|
||||
pg_dump $DATABASE_URL --clean > /mnt/save/$b/pg.dump \
|
||||
|| (
|
||||
rm -rf /mnt/save/$b
|
||||
echo "backup failed; deleting $b"
|
||||
exit 1
|
||||
)
|
||||
if du -sh /mnt/save/$b | grep -Ei "^[ ]*(4|2.).0K"; then
|
||||
rm -rf /mnt/save/$b
|
||||
echo rm empty backup $b
|
||||
fi
|
||||
@@ -14,7 +14,7 @@ int main() {
|
||||
printf("Waiting...\n");
|
||||
stat = sigwait(&set, &sig);
|
||||
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("Bye-bye!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
17
restore.sh
Executable file
17
restore.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
for b in $(find /mnt/save -not -path '*/\.*' -type f | sort -r); do
|
||||
if [ -n "$b" ]; then
|
||||
du -sh "$b"
|
||||
if ! du -sh "$b" | grep -Ei "^[ \t]*[0-9][0-9]?(.0)?[mg]"; then
|
||||
echo would rm empty backup $b >&2
|
||||
set -x
|
||||
mv "$b" "${b%/*}/.${b##*/}"
|
||||
set +x
|
||||
continue
|
||||
fi
|
||||
echo restoring $b >&2
|
||||
if psql $DATABASE_URL < "$b"; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
service postgresql start
|
||||
1088
tmp/save/20200415125736/pg.dump
Executable file
1088
tmp/save/20200415125736/pg.dump
Executable file
File diff suppressed because one or more lines are too long
1088
tmp/save/20200415125802/pg.dump
Executable file
1088
tmp/save/20200415125802/pg.dump
Executable file
File diff suppressed because one or more lines are too long
1088
tmp/save/20200415125811/pg.dump
Executable file
1088
tmp/save/20200415125811/pg.dump
Executable file
File diff suppressed because one or more lines are too long
1088
tmp/save/20200515111245/pg.dump
Normal file
1088
tmp/save/20200515111245/pg.dump
Normal file
File diff suppressed because one or more lines are too long
1088
tmp/save/20200515111531/pg.dump
Normal file
1088
tmp/save/20200515111531/pg.dump
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user