4 Commits
v0.7 ... v1.0.1

Author SHA1 Message Date
Bel LaPointe
604b803f74 hopefully fix restore again 2020-05-29 08:02:26 -06:00
Bel LaPointe
ab0944cbff restore doesnt need decimals 2020-05-29 07:32:26 -06:00
bel
cf008cd284 Try restoring many 2020-05-24 03:16:02 -06:00
bel
0421c8b8d9 hopefully fix bad backup 2020-05-15 11:16:40 -06:00
8 changed files with 2207 additions and 2 deletions

View File

@@ -39,12 +39,12 @@ ENV RUN_MIGRATIONS=0
ENV CREATE_ADMIN=0 ENV CREATE_ADMIN=0
COPY --from=builder /pause/pauser /pauser COPY --from=builder /pause/pauser /pauser
COPY backup.sh /
COPY restore.sh /
USER root USER root
### CRON BACKUPS ### CRON BACKUPS
RUN true \ RUN true \
&& echo '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); exit $?' > /backup.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 \

12
backup.sh Executable file
View 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

17
restore.sh Executable file
View 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

0
tmp/save/20200415125736/pg.dump Normal file → Executable file
View File

0
tmp/save/20200415125802/pg.dump Normal file → Executable file
View File

0
tmp/save/20200415125811/pg.dump Normal file → Executable file
View File

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long