Skip to content

Commit

Permalink
post-recovery bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jesdynf committed Feb 17, 2024
1 parent 20d4654 commit 2c68aba
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docker/mysql-xtrabackup-final/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openemr/mysql-xtrabackup:1.0.7

RUN rm /root/xbackup-wrapper.sh /root/xrecovery-final.sh
COPY xbackup-wrapper.sh xrecovery-final.sh /root/
RUN chmod a+x /root/*.sh
36 changes: 36 additions & 0 deletions docker/mysql-xtrabackup-final/xbackup-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

exec > /tmp/xtrabackup-launch.log 2>&1

cd /root

# if you recover into a clean system, initial xbackup.sh init was run back then and should not repeat
if [ -f restore-process-complete ]; then
if [ ! -f xtrabackup.database.txt ]; then
echo openemr > xtrabackup.database.txt
chmod 600 xtrabackup.database.txt
fi
touch allsetup.ok
rm restore-process-complete
fi

if [ ! -f allsetup.ok ]; then
./xbackup.sh -u openemr -a && ./xbackup.sh -t full && touch allsetup.ok && exit 0
exit 1
fi

if [ -f force-full-backup ]; then
rm force-full-backup
./xbackup.sh -t full
exit $?
fi

# I don't like forcing it like this, but if the backup fails one day, we need to try it the next
# here's the problem: manual run during an automated run will cause destruction and havoc and woe
if [ $(date +%u) == 7 ]; then
./xbackup.sh -t full -f
else
./xbackup.sh -t incr -f
fi;

exit $?
24 changes: 24 additions & 0 deletions docker/mysql-xtrabackup-final/xrecovery-final.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

WORKDIR=/mnt/backups/recovery

if service mysql status; then
echo xrecovery-final: mysql must not be running, yet it is; aborting
exit 1
fi

# Even though MySQL isn't running, I can't just make off with /var/lib/mysql,
# since the container mounts it.

chown -R mysql:mysql $WORKDIR
rm -rf /mnt/backups/prerecovery-mysql-datadir
echo Copying prerecovery state...
mkdir /mnt/backups/prerecovery-mysql-datadir
mv /var/lib/mysql/* /mnt/backups/prerecovery-mysql-datadir
echo Moving restored database into position...
mv -v $WORKDIR/* /var/lib/mysql
echo Done, continuing...
rm -f /root/pending-restore
touch /root/force-full-backup
touch /root/restore-process-complete
exit 0
10 changes: 10 additions & 0 deletions docker/mysql-xtrabackup/xbackup-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ exec > /tmp/xtrabackup-launch.log 2>&1

cd /root

# if you recover into a clean system, initial xbackup.sh init was run back then and should not repeat
if [ -f restore-process-complete ]; then
if [ ! -f xtrabackup.database.txt ]; then
echo openemr > xtrabackup.database.txt
chmod 600 xtrabackup.database.txt
fi
touch allsetup.ok
rm restore-process-complete
fi

if [ ! -f allsetup.ok ]; then
./xbackup.sh -u openemr -a && ./xbackup.sh -t full && touch allsetup.ok && exit 0
exit 1
Expand Down
1 change: 1 addition & 0 deletions docker/mysql-xtrabackup/xrecovery-final.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ mv -v $WORKDIR/* /var/lib/mysql
echo Done, continuing...
rm -f /root/pending-restore
touch /root/force-full-backup
touch /root/restore-process-complete
exit 0

0 comments on commit 2c68aba

Please sign in to comment.