Skip to content

Instantly share code, notes, and snippets.

@georghildebrand
Last active October 30, 2022 14:59
Show Gist options
  • Save georghildebrand/8be39cf2898926c72c5c3a6e528bf88f to your computer and use it in GitHub Desktop.
Save georghildebrand/8be39cf2898926c72c5c3a6e528bf88f to your computer and use it in GitHub Desktop.
A simple script to do a bulk restore of certain paths from all selected backups in a borg archive
#!/bin/sh
set -euo pipefail
# Very simple script to extract all files from a list of archives
# The inlcude files is used to recursively only extract from paths specified in this file
# The include.txt has the following format
# R /path/to/include
# Note: this script might run very long depending on the number of archives and the number of data you have to restore.
log ()
{
for i in "$@"; do
echo "$i";
done
echo "----"
}
extract ()
{
log "Starting to extract $2"
borg extract --list --patterns-from include.txt $1::$2 > "$2.extract.log" 2>&1
len=$(wc -l $2.extract.log)
log "Exactly" "$len" "files recreated"
log "Done with $2 touched $len files"
}
#run this script as sudo to avoid permission issues with borg
BORG_PASSPHRASE=passphrase
export BORG_PASSPHRASE
archive_path=/path/to/archive
archivefilter=string-in-archive-name-that-is-filted-
archives=$(borg list --short $archive_path|grep "$archivefilter")
# archives=${archives[@]:0:10} # only for taking first n archieves from the string
log "working on these archives" "$archives"
for archive in $archives; do
extract "$archive_path" "$archive"
done
log "Done with job all"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment