-
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 24, 2022
1 parent
4dd7a23
commit c8dbae0
Showing
4 changed files
with
89 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
OPENWBBASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | ||
BACKUPDIR="$OPENWBBASEDIR/web/backup" | ||
. "$OPENWBBASEDIR/helperFunctions.sh" | ||
|
||
backup() { | ||
openwbDebugLog MAIN 0 "creating new backup: $FILENAME" | ||
# remove old backup files | ||
openwbDebugLog MAIN 1 "deleting old backup files if present" | ||
rm "$BACKUPDIR/"* | ||
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 | ||
# give mosquitto some time to finish | ||
sleep 0.2 | ||
|
||
# create backup file | ||
openwbDebugLog MAIN 1 "creating new backup file: $BACKUPFILE" | ||
sudo tar --exclude="$OPENWBBASEDIR/web/backup" --exclude="$OPENWBBASEDIR/.git" -czf "$BACKUPFILE" "$OPENWBBASEDIR/" "/var/lib/mosquitto/" | ||
openwbDebugLog MAIN 1 "setting permissions of new backup file" | ||
sudo chown pi:www-data "$BACKUPFILE" | ||
sudo chmod 664 "$BACKUPFILE" | ||
|
||
openwbDebugLog MAIN 0 "backup finished" | ||
} | ||
|
||
useExtendedFilename=$1 | ||
if ((useExtendedFilename == 1)); then | ||
FILENAME="openWB_backup_$(date +"%Y-%m-%d_%H:%M:%S").tar.gz" | ||
else | ||
FILENAME="backup.tar.gz" | ||
fi | ||
|
||
openwbRunLoggingOutput backup "$FILENAME" | ||
# return our filename for further processing | ||
echo "$FILENAME" |
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,20 +1,31 @@ | ||
#!/bin/bash | ||
echo "****************************************" | ||
echo "Step 1: moving file to home directory..." | ||
sudo cp /var/www/html/openWB/web/tools/upload/backup.tar.gz /home/pi/backup.tar.gz | ||
cd /home/pi/ | ||
echo "****************************************" | ||
echo "Step 2: extracting archive..." | ||
sudo tar -vxf backup.tar.gz | ||
echo "****************************************" | ||
echo "Step 3: replacing old files..." | ||
sudo cp -v -R /home/pi/var/www/html/openWB/* /var/www/html/openWB/ | ||
sudo chmod 777 /var/www/html/openWB/openwb.conf | ||
echo "****************************************" | ||
echo "Step 4: cleanup after restore..." | ||
sudo rm /var/www/html/openWB/web/tools/upload/backup.tar.gz | ||
sudo rm /home/pi/backup.tar.gz | ||
sudo rm -R /home/pi/var | ||
echo "****************************************" | ||
echo "End: Restore finished." | ||
echo "****************************************" | ||
OPENWBBASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | ||
SOURCEFILE="$OPENWBBASEDIR/web/tools/upload/backup.tar.gz" | ||
WORKINGDIR="/home/pi/openwb_restore" | ||
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\"" | ||
mkdir -p "$WORKINGDIR" | ||
echo "****************************************" | ||
echo "Step 2: extracting archive to working dir \"$WORKINGDIR\"..." | ||
sudo tar -vxf "$SOURCEFILE" -C "$WORKINGDIR" | ||
echo "****************************************" | ||
echo "Step 3: replacing old files..." | ||
cp -v -R -p "${WORKINGDIR}${OPENWBBASEDIR}/." "${OPENWBBASEDIR}R/" | ||
echo "****************************************" | ||
echo "Step 4: 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 | ||
echo "****************************************" | ||
echo "Step 5: cleanup after restore..." | ||
sudo rm "$SOURCEFILE" | ||
sudo rm -R "$WORKINGDIR" | ||
echo "****************************************" | ||
echo "$(date +"%Y-%m-%d %H:%M:%S") End: Restore finished." | ||
echo "****************************************" | ||
} >"$LOGFILE" 2>&1 |
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