Skip to content
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

restic: Make explicit sync only happen after restore #796

Merged
merged 1 commit into from
Jul 12, 2023
Merged
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
24 changes: 12 additions & 12 deletions mover-restic/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ function reverse_array() {
}

################################################################
# Selects the first restic snapshot available for the
# given constraints. If RESTORE_AS_OF is defined, then
# Selects the first restic snapshot available for the
# given constraints. If RESTORE_AS_OF is defined, then
# only snapshots that were created prior to it are considered.
# If SELECT_PREVIOUS is defined, then the n-th snapshot
# is selected under the matching criteria.
# If a snapshot satisfying the conditions is found, then its ID
# If SELECT_PREVIOUS is defined, then the n-th snapshot
# is selected under the matching criteria.
# If a snapshot satisfying the conditions is found, then its ID
# is returned.
#
#
# Globals:
# SELECT_PREVIOUS
# RESTORE_AS_OF
Expand All @@ -186,7 +186,7 @@ function select_restic_snapshot_to_restore() {
local snapshot_id
local snapshot_ts
local trimmed_timestamp
local snapshot_epoch
local snapshot_epoch

# go through the timestamps received from restic
IFS=$'\n'
Expand All @@ -200,15 +200,15 @@ function select_restic_snapshot_to_restore() {
epochs_to_snapshots[${snapshot_epoch}]="${snapshot_id}"
done

# reverse sorted epochs so the most recent epoch is first
# reverse sorted epochs so the most recent epoch is first
reverse_array epochs

local -i offset=0
local target_epoch
if [[ -n ${RESTORE_AS_OF} ]]; then
# move to the position of the satisfying epoch
target_epoch=$(get_epoch_from_timestamp "${RESTORE_AS_OF}")
while ((offset < ${#epochs[@]})); do
while ((offset < ${#epochs[@]})); do
if ((${epochs[${offset}]} <= target_epoch)); then
break
fi
Expand All @@ -230,7 +230,7 @@ function select_restic_snapshot_to_restore() {


#######################################
# Restores from a selected snapshot if
# Restores from a selected snapshot if
# RESTORE_AS_OF is provided, otherwise
# restores from the latest restic snapshot
# Globals:
Expand All @@ -245,7 +245,7 @@ function do_restore {
# restore from specific snapshot specified by timestamp, or latest
local snapshot_id
snapshot_id=$(select_restic_snapshot_to_restore)
if [[ -z ${snapshot_id} ]]; then
if [[ -z ${snapshot_id} ]]; then
echo "No eligible snapshots found"
else
pushd "${DATA_DIR}"
Expand Down Expand Up @@ -282,14 +282,14 @@ for op in "$@"; do
;;
"restore")
do_restore
sync
;;
*)
error 2 "unknown operation: $op"
;;
esac
done
echo "Restic completed in $(( SECONDS - START_TIME ))s"
sync
echo "=== Done ==="
# sleep forever so that the containers logs can be inspected
# sleep 9999999