one-off recovery script for getting all copies of a file out of restic - hard-coded for finance.db, but its in variables and can be adapted if needed
This commit is contained in:
35
restore_all_copies_of_file.sh
Executable file
35
restore_all_copies_of_file.sh
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash -x
|
||||||
|
|
||||||
|
# --- Configuration ---
|
||||||
|
TAG="docker"
|
||||||
|
SRC_PATH="/srv/docker/container/finplan/" # Path as it appears inside the backup
|
||||||
|
SRC_FILE="finance.db" # Path as it appears inside the backup
|
||||||
|
TARGET_DIR="/var/tmp/db_history" # Where to save the historical copies
|
||||||
|
RESTIC_ARGS="-r /backup/restic-repo"
|
||||||
|
export RESTIC_PASSWORD=backups-are-important
|
||||||
|
# ---------------------
|
||||||
|
|
||||||
|
mkdir -p "$TARGET_DIR"
|
||||||
|
|
||||||
|
# Get a list of snapshot IDs and timestamps in JSON format
|
||||||
|
# Filtered for the specific file path to speed up the process
|
||||||
|
snapshots=$(restic $RESTIC_ARGS find $SRC_FILE --tag $TAG --json)
|
||||||
|
|
||||||
|
# Loop through each snapshot using jq to parse the JSON
|
||||||
|
echo "$snapshots" | jq -c '.[]' | while read -r snapshot; do
|
||||||
|
snap_id=$(echo "$snapshot" | jq -r '.snapshot')
|
||||||
|
snap_time=$(echo "$snapshot" | jq -r '.matches[0].mtime')
|
||||||
|
|
||||||
|
echo "$snap_id, $snap_time"
|
||||||
|
|
||||||
|
# Format date for the subdirectory (YY-MM-DD)
|
||||||
|
dir_date=$(date -d "$snap_time" +"%y-%m-%d")
|
||||||
|
|
||||||
|
output_path="$TARGET_DIR/$dir_date"
|
||||||
|
mkdir -p "$output_path"
|
||||||
|
|
||||||
|
# Restore the specific file to our dated subdirectory
|
||||||
|
restic $RESTIC_ARGS dump "$snap_id" "$SRC_PATH/$SRC_FILE" > $output_path/$SRC_FILE
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user