Add restore script, use it to move the latest lock file to the destinations
This commit is contained in:
parent
0a91afa541
commit
9cb44a8932
3 changed files with 60 additions and 7 deletions
39
restore.sh
Executable file
39
restore.sh
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/zsh
|
||||
|
||||
source ./util_lib.sh
|
||||
|
||||
latest_lock=$(get_latest_lock)
|
||||
has_lock=$(has_lock $latest_lock)
|
||||
|
||||
if [ $has_lock -eq 0 ]; then
|
||||
echo "No lock exists, nothing to restore."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
lock_dir="$LOCK_ROOT"/"$latest_lock"
|
||||
|
||||
# Iterate through the array of key-value pairs
|
||||
for mapping in "${mappings[@]}"; do
|
||||
current_mapping=("${(@s:|:)mapping}")
|
||||
|
||||
src="$lock_dir/$(basename "${current_mapping[1]}")"
|
||||
dest="${current_mapping[2]}"
|
||||
|
||||
# If src exists at all? No matter if it's a file or directory
|
||||
if [ ! -e "$src" ]; then
|
||||
echo "$src does not exist, skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Remove destination if it is a directory
|
||||
if [ -d "$src" ] && [ -d "$dest/${current_mapping[1]}" ]; then
|
||||
echo "Removing $dest/${current_mapping[1]}"
|
||||
rm -rf "$dest/${current_mapping[2]}"
|
||||
fi
|
||||
|
||||
# Create destination directory
|
||||
mkdir -p "$dest"
|
||||
|
||||
# Copy source to destination
|
||||
cp -r "$src" "$dest"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue