11 Commits

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
7 changed files with 82 additions and 3275 deletions

View File

@@ -16,7 +16,7 @@ RUN export DEBIAN_FRONTEND=noninteractive; \
cron \ cron \
postgresql postgresql-contrib \ postgresql postgresql-contrib \
&& curl -L \ && 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 \ > /miniflux.deb \
&& dpkg -i /miniflux.deb \ && dpkg -i /miniflux.deb \
&& mkdir -p /mnt/save && mkdir -p /mnt/save
@@ -39,22 +39,16 @@ 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 /
COPY entrypoint.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 \
&& touch /var/log/cronj.log && touch /var/log/cronj.log
ENTRYPOINT \ ENTRYPOINT bash /entrypoint.sh
service postgresql start \
&& until psql $DATABASE_URL < /dev/null; do sleep 5; done \
&& bash /restore.sh \
&& miniflux -migrate \
&& miniflux -create-admin \
&& miniflux \
& exec /pauser

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long