Skip to content

Commit

Permalink
Merge pull request #1175 from benderl/backup
Browse files Browse the repository at this point in the history
Backup
  • Loading branch information
benderl committed Oct 23, 2023
2 parents 7a62cc1 + c564525 commit 1b003f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions runs/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ LOGFILE="$OPENWBBASEDIR/data/log/backup.log"

useExtendedFilename=$1
if ((useExtendedFilename == 1)); then
FILENAME="openWB_backup_$(date +"%Y-%m-%d_%H:%M:%S").tar"
# only use characters supported in most OS!
# for Win see https://learn.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-shares--directories--files--and-metadata
FILENAME="openWB_backup_$(date +"%Y-%m-%d_%H-%M-%S").tar"
else
FILENAME="backup.tar"
fi
Expand Down Expand Up @@ -38,6 +40,11 @@ fi
--exclude "__pycache__" \
--exclude "$OPENWBDIRNAME/.pytest_cache" \
"$OPENWBDIRNAME"
echo "adding configuration file"
sudo tar --verbose --append \
--file="$BACKUPFILE" \
--directory="/home/openwb/" \
"configuration.json"
echo "adding mosquitto files"
sudo tar --verbose --append \
--file="$BACKUPFILE" \
Expand All @@ -51,6 +58,7 @@ fi
--file="$BACKUPFILE" \
--directory="$OPENWBBASEDIR/ramdisk/" \
"GIT_BRANCH" "GIT_HASH"

echo "calculating checksums"
# openwb directory
find "$OPENWBBASEDIR" \( \
Expand All @@ -63,6 +71,8 @@ fi
-name "backup.log" \
\) -prune -o \
-type f -print0 | xargs -0 sha256sum | sed -n "s|$TARBASEDIR/||p" >"$OPENWBBASEDIR/ramdisk/SHA256SUM"
# configuration file
echo -n "/home/openwb/configuration.json" | xargs -0 sha256sum | sed -n "s|/home/openwb/||p" >>"$OPENWBBASEDIR/ramdisk/SHA256SUM"
# git info files
find "$OPENWBBASEDIR/ramdisk/GIT_"* \
-type f -print0 | xargs -0 sha256sum | sed -n "s|$OPENWBBASEDIR/ramdisk/||p" >>"$OPENWBBASEDIR/ramdisk/SHA256SUM"
Expand All @@ -73,10 +83,11 @@ fi
--file="$BACKUPFILE" \
--directory="$OPENWBBASEDIR/ramdisk/" \
"SHA256SUM"

# cleanup
echo "removing temporary files"
rm -v "$OPENWBBASEDIR/ramdisk/GIT_BRANCH" "$OPENWBBASEDIR/ramdisk/GIT_HASH" "$OPENWBBASEDIR/ramdisk/SHA256SUM"
tar --verbose --append \
tar --append \
--file="$BACKUPFILE" \
--directory="$OPENWBBASEDIR/data/log/" \
"backup.log"
Expand Down
3 changes: 3 additions & 0 deletions runs/prepare_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ declare resultStatus
resultMessage="Das Archiv ist nicht vollständig!"
resultStatus=1
else
if [[ ! -f "$WORKING_DIR/configuration.json" ]]; then
echo "configuration missing; continue anyway"
fi
if ! (cd "$WORKING_DIR" && sudo sha256sum --quiet --check "SHA256SUM"); then
resultMessage="Einige Dateien wurden gelöscht oder bearbeitet!"
resultStatus=1
Expand Down
5 changes: 5 additions & 0 deletions runs/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log"
echo "Step 4: restore contents of backup"
# we use cp not mv because of not empty directories in destination
sudo cp -v -p -r "${WORKING_DIR}/openWB/." "${OPENWB_BASE_DIR}/"
if [[ -f "$WORKING_DIR/configuration.json" ]]; then
sudo mv -v -f "${WORKING_DIR}/configuration.json" "/home/openwb/"
else
echo "Backup does not contain configuration. Skipping restore."
fi
echo "****************************************"
echo "Step 5: restore mosquitto db"
if [[ -f "${WORKING_DIR}/mosquitto/mosquitto.db" ]]; then
Expand Down

0 comments on commit 1b003f2

Please sign in to comment.