-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lutz Bender
committed
Aug 30, 2022
1 parent
3758236
commit 77ae5e2
Showing
3 changed files
with
26 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |