Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion runs/atreboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ chmod 666 "$LOGFILE"
echo "load versions..."
"$OPENWBBASEDIR/runs/update_available_versions.sh"
else
echo "no internet connection, skipping version update"
echo "no internet connection, updating versions from local git data"
"$OPENWBBASEDIR/runs/update_available_versions.sh" --no-fetch
fi

# set restore dir permissions to allow file upload for apache
Expand Down
18 changes: 16 additions & 2 deletions runs/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,31 @@ force_mosquitto_write() {

collect_git_info() {
echo "collecting git information"
if git branch --no-color --show-current >"$TEMPDIR/GIT_BRANCH"; then
if git -C "$OPENWBBASEDIR" branch --no-color --show-current >"$TEMPDIR/GIT_BRANCH"; then
echo "current branch: $(<"$TEMPDIR/GIT_BRANCH")"
else
echo "failed to collect git branch info"
return 1
fi
if git log --pretty='format:%H' -n1 >"$TEMPDIR/GIT_HASH"; then
if git -C "$OPENWBBASEDIR" log --pretty='format:%H' -n1 >"$TEMPDIR/GIT_HASH"; then
echo "current commit hash: $(<"$TEMPDIR/GIT_HASH")"
else
echo "failed to collect git commit hash"
return 1
fi
local logicalBranch=""
if [[ -z $(<"$TEMPDIR/GIT_BRANCH") ]]; then
logicalBranch=$(git -C "$OPENWBBASEDIR" config --local --get openwb.updateBranch) || logicalBranch=""
fi
case "$logicalBranch" in
"Release"|"Beta"|"") ;;
*)
echo "invalid logical update branch '$logicalBranch'"
return 1
;;
esac
printf '%s\n' "$logicalBranch" >"$TEMPDIR/GIT_UPDATE_BRANCH"
echo "logical update branch: $logicalBranch"
return 0
}

Expand All @@ -216,6 +229,7 @@ create_archive() {
"${DB_FILES[@]}" \
"GIT_BRANCH" \
"GIT_HASH" \
"GIT_UPDATE_BRANCH" \
--directory="/etc/mosquitto/" \
"conf_local.d/" \
--directory="$TARBASEDIR/" \
Expand Down
36 changes: 30 additions & 6 deletions runs/prepare_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ RESTORE_DIR="$OPENWB_BASE_DIR/data/restore"
SOURCE_FILE="$RESTORE_DIR/restore.tar.gz"
WORKING_DIR="/home/openwb/openwb_restore"
LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log"
GIT_REMOTE="origin"

source "$OPENWB_BASE_DIR/runs/update_version_helpers.sh" || exit 1

declare resultMessage
declare resultStatus
Expand All @@ -12,6 +15,11 @@ declare resultStatus
echo "$(date +"%Y-%m-%d %H:%M:%S") Preparation of restore started..."
echo "****************************************"
echo "Step 1: creating working directory \"$WORKING_DIR\""
echo "Step 1.1: ensure working directory is empty"
if [[ -d "$WORKING_DIR" ]]; then
echo "Removing existing working directory"
sudo rm -rf "$WORKING_DIR"
fi
mkdir -p "$WORKING_DIR"
echo "****************************************"
echo "Step 2: extract archive to working directory"
Expand Down Expand Up @@ -54,17 +62,33 @@ declare resultStatus
else
echo "****************************************"
echo "Step 4: sync with git"
GIT_REMOTE="origin"
BRANCH=$(<"$WORKING_DIR/GIT_BRANCH")
# TAG=$(<"$WORKING_DIR/GIT_HASH")
HASH=$(<"$WORKING_DIR/GIT_HASH")
UPDATE_BRANCH=""
if [[ -f "$WORKING_DIR/GIT_UPDATE_BRANCH" ]]; then
UPDATE_BRANCH=$(<"$WORKING_DIR/GIT_UPDATE_BRANCH")
fi
metadataStatus=0
validateRestoreGitMetadata "$BRANCH" "$UPDATE_BRANCH" || metadataStatus=$?
echo "Step 4.1: fetch info from git"
if ! git -C "$OPENWB_BASE_DIR" fetch -v "$GIT_REMOTE"; then
if [[ $metadataStatus -eq 1 ]]; then
echo "invalid logical update branch '$UPDATE_BRANCH'"
resultMessage="Der logische Update-Zweig des Archivs ist ungültig."
resultStatus=1
elif [[ $metadataStatus -eq 2 ]]; then
echo "logical update branch requires detached HEAD"
resultMessage="Das Archiv enthält widersprüchliche Git-Zweige."
resultStatus=1
elif ! fetchVersionRefs "$OPENWB_BASE_DIR" "$GIT_REMOTE"; then
resultMessage="Beim Abgleich mit dem openWB Git ist ein Fehler aufgetreten!"
resultStatus=1
else
echo "Step 4.2: verify branch \"$BRANCH\" from archive"
if ! git -C "$OPENWB_BASE_DIR" branch | grep "$BRANCH"; then
resultMessage="Der Entwicklungszweig \"$BRANCH\" des Archivs ist ungültig."
echo "Step 4.2: verify git state from archive"
if ! git -C "$OPENWB_BASE_DIR" rev-parse --verify --quiet "$HASH^{commit}" >/dev/null; then
resultMessage="Der Git-Stand \"$HASH\" des Archivs ist ungültig."
resultStatus=1
elif [[ -n $BRANCH ]] && ! remoteBranchExists "$OPENWB_BASE_DIR" "$GIT_REMOTE" "$BRANCH"; then
resultMessage="Der Entwicklungszweig \"$GIT_REMOTE/$BRANCH\" des Archivs ist ungültig."
resultStatus=1
Comment thread
benderl marked this conversation as resolved.
else
echo "Step 4.3: clean mosquitto configuration, will be recreated on next boot"
Expand Down
37 changes: 28 additions & 9 deletions runs/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ MOSQUITTO_DB_DIR="/var/lib/mosquitto"
MOSQUITTO_LOCAL_DB_DIR="/var/lib/mosquitto_local"
MOSQUITTO_CONF_DIR="/etc/mosquitto"
LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log"
GIT_REMOTE="origin"

source "$OPENWB_BASE_DIR/runs/update_version_helpers.sh" || exit 1

{
echo "$(date +"%Y-%m-%d %H:%M:%S") Restore of backup started..."
Expand All @@ -22,23 +25,39 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log"
# give systemctl some time to finish, may be unnecessary?
sleep 2
echo "****************************************"
echo "Step 6: checkout matching git branch and tag"
echo "Step 6: checkout matching git branch and hash"
BRANCH=$(<"$WORKING_DIR/GIT_BRANCH")
TAG=$(<"$WORKING_DIR/GIT_HASH")
echo "Step 6.1: checkout branch: $BRANCH"
if ! git -C "$OPENWB_BASE_DIR" checkout --force "$BRANCH"; then
echo "checkout of branch \"$BRANCH\" failed! aborting restore"
HASH=$(<"$WORKING_DIR/GIT_HASH")
UPDATE_BRANCH=""
if [[ -f "$WORKING_DIR/GIT_UPDATE_BRANCH" ]]; then
UPDATE_BRANCH=$(<"$WORKING_DIR/GIT_UPDATE_BRANCH")
fi
metadataStatus=0
validateRestoreGitMetadata "$BRANCH" "$UPDATE_BRANCH" || metadataStatus=$?
if [[ $metadataStatus -eq 1 ]]; then
echo "invalid logical update branch '$UPDATE_BRANCH'! aborting restore"
exit 1
elif [[ $metadataStatus -eq 2 ]]; then
echo "logical update branch requires detached HEAD! aborting restore"
exit 1
fi
echo "Step 6.2: reset to matching version: [$TAG]"
if ! git -C "$OPENWB_BASE_DIR" reset --hard "$TAG"; then
echo "reset to version [$TAG] failed! aborting restore"
if [[ -z $BRANCH ]]; then
echo "checkout detached commit: $HASH"
else
echo "checkout branch from remote: $GIT_REMOTE/$BRANCH"
fi
echo "apply saved version: [$HASH]"
if ! applyVersion "$OPENWB_BASE_DIR" "$GIT_REMOTE" "$BRANCH" "$HASH" "$UPDATE_BRANCH"; then
echo "applying version [$HASH] failed! aborting restore"
exit 1
fi
echo "****************************************"
echo "Step 7: 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 ! sudo cp -v -p -r "${WORKING_DIR}/openWB/." "${OPENWB_BASE_DIR}/"; then
echo "restoring openWB files failed! aborting restore"
exit 1
fi
if [[ -f "$WORKING_DIR/configuration.json" ]]; then
sudo mv -v -f "${WORKING_DIR}/configuration.json" "/home/openwb/"
else
Expand Down
Loading
Loading