Compare commits

...

13 Commits
v0.5 ... master

Author SHA1 Message Date
Bel LaPointe 7e8ac6bbd1 rm 2022-03-18 11:49:30 -06:00
Bel LaPointe 3cca493648 up mini 2022-03-18 11:34:17 -06:00
Bel LaPointe 54ab5919e2 hopefully better 2021-02-28 13:26:42 -06:00
Bel LaPointe 3ac73e6d28 miniflux v bump 2021-02-24 09:44:19 -06:00
Bel LaPointe b2cfba373e hopefully fix bad backups 2020-12-06 20:04:35 -07:00
bel 9182e656bf restart on fail, clear old backups 2020-12-05 11:36:36 -07:00
Bel LaPointe 16b974afd1 dont del big backups 2020-09-29 13:35:51 -06:00
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
Bel LaPointe a904244fd2 Delete failed backups 2020-04-15 19:11:51 +00:00
Bel LaPointe 7ccb495a1a Amend backup to clean 2020-04-07 15:43:11 -06:00
4 changed files with 82 additions and 11 deletions

View File

@ -16,7 +16,7 @@ RUN export DEBIAN_FRONTEND=noninteractive; \
cron \
postgresql postgresql-contrib \
&& curl -L \
https://github.com/miniflux/miniflux/releases/download/2.0.19/miniflux_2.0.19_amd64.deb \
https://github.com/miniflux/miniflux/releases/download/2.0.36/miniflux_2.0.36_amd64.deb \
> /miniflux.deb \
&& dpkg -i /miniflux.deb \
&& mkdir -p /mnt/save
@ -39,22 +39,16 @@ ENV RUN_MIGRATIONS=0
ENV CREATE_ADMIN=0
COPY --from=builder /pause/pauser /pauser
COPY backup.sh /
COPY restore.sh /
COPY entrypoint.sh /
USER root
### CRON BACKUPS
RUN true \
&& 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 '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 '' >> /etc/cron.d/backups \
&& chmod 0644 /etc/cron.d/backups \
&& touch /var/log/cronj.log
ENTRYPOINT \
service postgresql start \
&& until psql $DATABASE_URL < /dev/null; do sleep 5; done \
&& bash /restore.sh \
&& miniflux -migrate \
&& miniflux -create-admin \
&& miniflux \
& exec /pauser
ENTRYPOINT bash /entrypoint.sh

16
backup.sh Executable file
View File

@ -0,0 +1,16 @@
b=$(date +%Y%m%d%H%M%S)
mkdir -p /mnt/save/$b
(
set -e
pg_dump $DATABASE_URL --clean > /mnt/save/$b/.pg.dump
mv /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

38
entrypoint.sh Executable file
View File

@ -0,0 +1,38 @@
#! /bin/bash
LOG=/tmp/bel.log
main() {
echo "" > $LOG
ensure start_postgres
until psql $DATABASE_URL < /dev/null; do sleep 5; done
bash /restore.sh
miniflux -migrate
miniflux -create-admin
ensure miniflux
exec /pauser
}
start_postgres() {
service postgresql start
psql $DATABASE_URL
}
ensure() {
_ensure "$@" &>> $LOG & disown
}
_ensure() {
while true; do
echo $(date): ensuring "$@" >&2
"$@"
sleep 3
done
}
main "$@"

23
restore.sh Executable file
View File

@ -0,0 +1,23 @@
all_backups=($(find /mnt/save -not -path '*/\.*' -type f | sort -r))
for ((i=${#all_backups[@]}-1; i>50; i--)); do
echo rm old backpu ${all_backups[i]} >&2
rm -f ${all_backups[i]} || true
done
for b in "${all_backups[@]}"; do
if [ -n "$b" ]; then
du -sh "$b"
if ! du -sh "$b" | grep -Ei "^[ \t]*[0-9][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