-
Notifications
You must be signed in to change notification settings - Fork 195
rework backup and restore #2372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benderl
wants to merge
9
commits into
snaptec:master
Choose a base branch
from
benderl:backup-broker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
78727c7
rework backup and restore
85d8501
implement suggested changes
1b8f901
use backupdir variable in tar command
cb9720f
add reboot info to restore page
b22075f
log pkill signal
81f1a16
make restore of mosquitto.db optional
149941e
fix copying files and folders
89c2374
fix file permissions
8c48c32
suggested changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,41 @@ | ||
| #!/bin/bash | ||
| OPENWBBASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | ||
| BACKUPDIR="$OPENWBBASEDIR/web/backup" | ||
| . "$OPENWBBASEDIR/helperFunctions.sh" | ||
|
|
||
| backup() { | ||
| # $1: name for new backup file | ||
| # remove old backup files | ||
| openwbDebugLog MAIN 1 "deleting old backup files if present" | ||
| rm "$BACKUPDIR/"* | ||
|
|
||
| # tell mosquitto to store all retained topics in db now | ||
| openwbDebugLog MAIN 1 "sending 'SIGUSR1' to mosquitto" | ||
| sudo pkill --echo -SIGUSR1 mosquitto | ||
| # give mosquitto some time to finish | ||
| sleep 0.2 | ||
|
|
||
| # create backup file | ||
| BACKUPFILE="$BACKUPDIR/$1" | ||
| openwbDebugLog MAIN 0 "creating new backup file: $BACKUPFILE" | ||
| sudo tar --verbose --create --gzip --file="$BACKUPFILE" \ | ||
| --exclude="$BACKUPDIR" \ | ||
| --exclude="$OPENWBBASEDIR/.git" \ | ||
| "$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 hidden or 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 hidden or 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,50 @@ | ||
| #!/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) | ||
| 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: 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 3: extracting archive to working dir \"$WORKINGDIR\"..." | ||
| if ! sudo tar --verbose --extract --file="$SOURCEFILE" --directory="$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 4: replacing old files..." | ||
| # we use cp not mv because of not empty directories in destination | ||
| sudo cp -v -p -r "${WORKINGDIR}${OPENWBBASEDIR}/." "${OPENWBBASEDIR}/" | ||
| echo "****************************************" | ||
| echo "Step 5: restoring mosquitto db..." | ||
| if [[ -f "${WORKINGDIR}${MOSQUITTODIR}/mosquitto.db" ]]; then | ||
| sudo systemctl stop mosquitto.service | ||
| sleep 2 | ||
| sudo mv -v -f "${WORKINGDIR}${MOSQUITTODIR}/mosquitto.db" "$MOSQUITTODIR/mosquitto.db" | ||
| else | ||
| echo "Backup does not contain mosquitto.db. Skipping restore." | ||
| fi | ||
| echo "****************************************" | ||
| 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 | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.