Skip to content

Commit

Permalink
implement suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lutz Bender committed Aug 30, 2022
1 parent 3758236 commit 77ae5e2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 2 additions & 4 deletions runs/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ backup() {
BACKUPFILE="$BACKUPDIR/$FILENAME"

# tell mosquitto to store all retained topics in db now
for pid in $(pidof "mosquitto"); do
openwbDebugLog MAIN 1 "sending 'SIGUSR1' to mosquitto on pid '$pid'"
sudo kill -s SIGUSR1 "$pid"
done
openwbDebugLog MAIN 1 "sending 'SIGUSR1' to mosquitto"
sudo pkill -SIGUSR1 mosquitto
# give mosquitto some time to finish
sleep 0.2

Expand Down
3 changes: 1 addition & 2 deletions runs/reboot.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash

sudo rm /var/log/openWB.log
sudo touch /var/log/openWB.log
sudo chmod 777 /var/log/openWB.log
$(sleep 5 && sudo reboot now)&
$(sleep 5 && sudo reboot now) &
32 changes: 23 additions & 9 deletions runs/restore.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
#!/bin/bash
OPENWBBASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
RAMDISKDIR="$OPENWBBASEDIR/ramdisk"
SOURCEFILE="$OPENWBBASEDIR/web/tools/upload/backup.tar.gz"
WORKINGDIR="/home/pi/openwb_restore"
MOSQUITTODIR="/var/lib/mosquitto"
LOGFILE="$OPENWBBASEDIR/web/tools/upload/restore.log"

{
echo "$(date +"%Y-%m-%d %H:%M:%S") Restore of backup started..."
echo "****************************************"
echo "Step 1: creating working directory \"$WORKINGDIR\""
echo "Step 1: setting flag 'update in progress' and wait for control loop to finish"
echo 1 > "$OPENWBBASEDIR/ramdisk/updateinprogress"
# Wait for regulation loop(s) and cron jobs to end, but with timeout in case a script hangs
pgrep -f "$OPENWBBASEDIR/(regel\\.sh|runs/cron5min\\.sh|runs/cronnightly\\.sh)$" | \
timeout 15 xargs -n1 -I'{}' tail -f --pid="{}" /dev/null
echo "****************************************"
echo "Step 2: creating working directory \"$WORKINGDIR\""
mkdir -p "$WORKINGDIR"
echo "****************************************"
echo "Step 2: extracting archive to working dir \"$WORKINGDIR\"..."
sudo tar -vxf "$SOURCEFILE" -C "$WORKINGDIR"
echo "Step 3: extracting archive to working dir \"$WORKINGDIR\"..."
if ! sudo tar -vxf "$SOURCEFILE" -C "$WORKINGDIR"; then
echo "something went wrong! aborting restore"
echo "Wiederherstellung fehlgeschlagen! Bitte Protokolldateien prüfen." >"$RAMDISKDIR/lastregelungaktiv"
echo 0 > "$OPENWBBASEDIR/ramdisk/updateinprogress"
exit 1
fi
echo "****************************************"
echo "Step 3: replacing old files..."
cp -v -R -p "${WORKINGDIR}${OPENWBBASEDIR}/." "${OPENWBBASEDIR}R/"
echo "Step 4: replacing old files..."
mv -v -f "${WORKINGDIR}${OPENWBBASEDIR}/." "${OPENWBBASEDIR}/"
echo "****************************************"
echo "Step 4: restoring mosquitto db..."
echo "Step 5: restoring mosquitto db..."
sudo systemctl stop mosquitto.service
sleep 2
sudo cp -v -p "$WORKINGDIR/var/lib/mosquitto/mosquitto.db" "/var/lib/mosquitto/mosquitto.db"
sudo systemctl start mosquitto.service
sudo mv -v -f "${WORKINGDIR}${MOSQUITTODIR}/mosquitto.db" "$MOSQUITTODIR/mosquitto.db"
echo "****************************************"
echo "Step 5: cleanup after restore..."
echo "Step 6: cleanup after restore..."
sudo rm "$SOURCEFILE"
sudo rm -R "$WORKINGDIR"
echo "****************************************"
echo "$(date +"%Y-%m-%d %H:%M:%S") End: Restore finished."
echo "rebooting"
"$OPENWBBASEDIR/runs/reboot.sh"
echo "****************************************"
} >"$LOGFILE" 2>&1

0 comments on commit 77ae5e2

Please sign in to comment.