From 36468bc88f3711c60e4f24113a126d6198def88e Mon Sep 17 00:00:00 2001 From: Djan <> Date: Sun, 10 Apr 2022 11:49:12 +0200 Subject: [PATCH] adding index functions - bobaindexgeneratelist - bobaindexsearch - bobaindexumount --- borgaliasandfunctions.txt | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/borgaliasandfunctions.txt b/borgaliasandfunctions.txt index 1602cbd..a4ec4f8 100644 --- a/borgaliasandfunctions.txt +++ b/borgaliasandfunctions.txt @@ -85,11 +85,15 @@ function TestBorgRepo { if [ ! -f "config" ]; then TestBorgErr=1 echo "Unable to find borgbackup repo config file." + sleep 3 + exit fi if [ ! -d "data" ]; then TestBorgErr=1 echo "Unable to find borgbackup data folder." + sleep 3 + exit fi } @@ -206,6 +210,61 @@ function bobadur { done } +function bobaindexgeneratelist { + TestBorgRepo + echo "Warning, list of file will be generating OUTSIDE the repo,so it will be in CLEARTEXT." + echo "This could be a securty issue, as it will expose file list of all archives." + echo "Generating list could last a very long time and take some disk space." + read -p "Continue ? [N/y] " CONT + if [ "$CONT" != "y" ];then + return + fi + + echo "Generating list..." + indexdir=bobaindex_$(date +%Y%m%d) + mkdir -p $indexdir + + for archive in $(borg list --short ./);do + echo "Generating list for $archive" + borg list --short .::"$archive" >> $indexdir/"$archive" + done + + echo "Adding index to repo..." + borg create .::bobaindex_$(date +%Y%m%d) $indexdir/ + rm -rf $indexdir/ + echo "Borg index generated." +} + +function bobaindexsearch { + TestBorgRepo + indexarchive=$(borg list --short . | grep bobaindex | head -n 1) + + if [ "$1" = "" ];then + echo "No argument.";return + fi + + if [ $indexarchive = "" ];then + echo "bobaindex not found";return + fi + + if [ ! -d $HOME/$indexarchive ];then + echo "Mounting index..." + mkdir $HOME/$indexarchive + borg mount ./::$indexarchive $HOME/$indexarchive + fi + + cd $HOME/$indexarchive + grep -i -r $1 ./ + cd - +} + +function bobaindexumount { + mountpoint=$(findmnt -l --output TARGET | grep bobaindex) + fusermount -u -z "$mountpoint" + sleep 5 + rmdir "$mountpoint" +} + ############################################################################### # mount functions ###############################################################################