delimiter for groups
reorganization of functions
This commit is contained in:
parent
82b68d3421
commit
f06458f1a0
@ -65,131 +65,294 @@ EOF
|
||||
|
||||
alias bobahelp="bobaman"
|
||||
|
||||
##################################
|
||||
# Fonctions borg
|
||||
##################################
|
||||
#Une fonction qu permet d’obtenir les information d’une archive.
|
||||
function bobainfo {
|
||||
borg info ./::$1
|
||||
}
|
||||
###############################################################################
|
||||
# generals functions
|
||||
###############################################################################
|
||||
|
||||
#Supprimmer l'archive en paramètre
|
||||
function bobadel {
|
||||
borg delete ./::$1
|
||||
}
|
||||
|
||||
#Supprimmer la dernière archive du dépôt
|
||||
function bobadelast {
|
||||
archive=$(borg list ./ --short | tail -n 1)
|
||||
borg delete .::$archive
|
||||
}
|
||||
|
||||
#Lister les archives du dépôt
|
||||
alias bobals="borg list ./ --short"
|
||||
|
||||
#Créer un dépôt Borg. Par défaut, il sera chiffré avec un fichier clé créé dans votre home.Retour ligne automatique
|
||||
alias bobaini="borg init ./"
|
||||
|
||||
#Créer un dépôt Borg sans chiffrement.Retour ligne automatique
|
||||
alias bobaininoenc="borg init --encryption=none ./"
|
||||
|
||||
#Vérifier la consistence d'un dépôt
|
||||
alias boback="borg check -v ."
|
||||
|
||||
#Monter une archive en paramètre
|
||||
function bobamount {
|
||||
mountpoint="$HOME/borg_$1"
|
||||
mkdir $mountpoint
|
||||
borg mount ./::$1 $mountpoint
|
||||
read -p "Presser une touche pour démontage" CONT
|
||||
fusermount -u $mountpoint && sleep 5 && rmdir $mountpoint
|
||||
}
|
||||
|
||||
#Monter la dernière archive du dépôt
|
||||
function bobamountlast {
|
||||
archive=$(borg list ./ --short | tail -n 1)
|
||||
mountpoint="$HOME/borg_$archive"
|
||||
mkdir $mountpoint
|
||||
borg mount ./::$archive $mountpoint
|
||||
read -p "Presser une touche pour démontage" CONT
|
||||
fusermount -u $mountpoint && sleep 5 && rmdir $mountpoint
|
||||
}
|
||||
|
||||
#Afficher les informations de la dernière archive
|
||||
function bobainflastsave {
|
||||
archive=$(borg list --short ./ | tail -n 1)
|
||||
borg info .::$archive
|
||||
}
|
||||
|
||||
#Cette fonction récupère toutes les informations des archives dans un dépôt Borg. Cela peut être utile pour faire des statiques sur un dépôt.Retour ligne automatique
|
||||
#Attention, si le nombre d’archives est élevé et la compression forte cela peut prendre du temps.
|
||||
function bobainfoall {
|
||||
for borgarchive in $(borg list --short ./);do
|
||||
echo "---------------------------------------------------------------------------------------"
|
||||
borg info .::$borgarchive
|
||||
echo "---------------------------------------------------------------------------------------"
|
||||
done
|
||||
}
|
||||
|
||||
#Exporter toutes les informations des archives dans un dépôt dans un fichier json
|
||||
function bobainfoalljson {
|
||||
for borgarchive in $(borg list --short ./);do
|
||||
borg info --json .::$borgarchive >> $HOME/borginfo.txt
|
||||
done
|
||||
}
|
||||
|
||||
#Trouver un fichier dans un dépôt, affiche la liste des archives qui contient le fichier
|
||||
function bobasearchinarchive {
|
||||
for borgarchive in $(borg list --short ./);do
|
||||
borggrep=$(borg list --short .::$borgarchive | grep $1)
|
||||
if [ $? = 0 ];then
|
||||
echo "Chaine trouvé dans l'archive : $borgarchive"
|
||||
function TestBorgRepo {
|
||||
if [ ! -f "config" ]; then
|
||||
TestBorgErr=1
|
||||
echo "Unable to find borgbackup repo config file."
|
||||
fi
|
||||
|
||||
if [ ! -d "data" ]; then
|
||||
TestBorgErr=1
|
||||
echo "Unable to find borgbackup data folder."
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#Supprimmer en masse des archives dans un dépôt
|
||||
function UnMount {
|
||||
fusermount -u -z "$mountpoint"
|
||||
sleep 5
|
||||
rmdir "$mountpoint"
|
||||
}
|
||||
|
||||
function DirExists {
|
||||
if [ ! -d "$1" ]; then
|
||||
echo "Error, directory $1 missing."
|
||||
echo "Exiting.";sleep 10
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
# list and infos functions
|
||||
###############################################################################
|
||||
|
||||
function bobals {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
if [ "$1" != "" ]; then
|
||||
borg list --short .::$1
|
||||
else
|
||||
borg list --short ./
|
||||
fi
|
||||
}
|
||||
|
||||
function bobagrepls {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
read -p "Pattern to filter : " grepfilter
|
||||
borg list --short ./ | grep $grepfilter
|
||||
}
|
||||
|
||||
function bobainfoa {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
borg info ./::$1
|
||||
}
|
||||
|
||||
function bobainfor {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
borg info ./
|
||||
}
|
||||
|
||||
function bobainfolast {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
archive=$(borg list --short ./ | tail -n 1)
|
||||
borg info .::$archive
|
||||
}
|
||||
|
||||
function bobainfoall {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
for borgarchive in $(borg list --short ./);do
|
||||
echo "------------------------------------------------------------------------------"
|
||||
borg info .::$borgarchive
|
||||
echo "------------------------------------------------------------------------------"
|
||||
done
|
||||
}
|
||||
|
||||
function bobadurationr {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
for borgarchive in $(borg list --short ./);do
|
||||
borg info .::$borgarchive | grep "Archive name"
|
||||
borg info .::$borgarchive | grep "Duration"
|
||||
echo ""
|
||||
done
|
||||
}
|
||||
|
||||
function bobadur {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ];then return;fi
|
||||
|
||||
echo " Original size Compressed size Deduplicated size"
|
||||
for borgarchive in $(borg list --short ./);do
|
||||
borg info .::$borgarchive | grep "Archive name" | cut -d" " -f3
|
||||
borg info .::$borgarchive | grep "This archive" | cut -d":" -f2
|
||||
done
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# mount functions
|
||||
###############################################################################
|
||||
|
||||
function bobamount {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
mountpoint="$HOME/borg_$1"
|
||||
mkdir $mountpoint
|
||||
echo "Archive : $1"
|
||||
borg mount ./::$1 $mountpoint
|
||||
read -p "Presser une touche pour démontage" CONT
|
||||
UnMount
|
||||
}
|
||||
|
||||
function bobamountfirst {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
archive=$(borg list ./ --short | head -n 1)
|
||||
mountpoint="$HOME/borg_$archive"
|
||||
mkdir $mountpoint
|
||||
borg mount ./::$archive $mountpoint
|
||||
|
||||
read -p "Presser une touche pour démontage" CONT
|
||||
UnMount
|
||||
}
|
||||
|
||||
function bobamountlast {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
archive=$(borg list ./ --short | tail -n 1)
|
||||
mountpoint="$HOME/borg_$archive"
|
||||
mkdir $mountpoint
|
||||
borg mount ./::$archive $mountpoint
|
||||
|
||||
read -p "Presser une touche pour démontage" CONT
|
||||
UnMount
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
# search functions
|
||||
###############################################################################
|
||||
|
||||
function bobasearchinrepo {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
for borgarchive in $(borg list --short ./);do
|
||||
borggrep=$(borg list --short .::$borgarchive | grep -i $1)
|
||||
if [ $? = 0 ];then
|
||||
echo ""
|
||||
echo "-- $borgarchive --"
|
||||
echo "$borggrep"
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function bobasearchinarchive {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
borg list --short .::$1 | grep -i $2
|
||||
}
|
||||
|
||||
|
||||
function bobacachedel {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ];then return;fi
|
||||
|
||||
repoid=$(cat config | grep id | cut -f3 -d" ")
|
||||
echo "Repo ID : "$repoid;sleep 5
|
||||
DirExists $HOME/.cache/borg/$repoid
|
||||
rm -r $HOME/.cache/borg/$repoid
|
||||
}
|
||||
|
||||
function bobasecuritydel {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ];then return;fi
|
||||
|
||||
repoid=$(cat config | grep id | cut -f3 -d" ")
|
||||
echo "Repo ID : "$repoid;sleep 5
|
||||
DirExists $HOME/.config/borg/security/$repoid
|
||||
rm -r $HOME/.config/borg/security/$repoid
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# modify repo
|
||||
###############################################################################
|
||||
|
||||
function bobadel {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
borg delete ./::$1
|
||||
}
|
||||
|
||||
function bobadelast {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
archive=$(borg list ./ --short | tail -n 1)
|
||||
borg delete .::$archive
|
||||
}
|
||||
|
||||
function bobacheckrepo {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
borgrepo="${PWD##*/}"
|
||||
|
||||
borg check -v .
|
||||
notify-send "borg check" "Repo $borgrepo checked"
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# mass functions
|
||||
###############################################################################
|
||||
|
||||
function bobadeleter {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
borgrepo="${PWD##*/}"
|
||||
file="borgdelete_$borgrepo.sh"
|
||||
editor="$EDITOR"
|
||||
|
||||
#test dépôt
|
||||
borgrepofile="config"
|
||||
if [ ! -f "$borgrepofile" ]; then
|
||||
echo "Not in a borg repo. Unable to find $borgrepofile."
|
||||
return
|
||||
fi
|
||||
|
||||
borgrepofile="data"
|
||||
if [ ! -d "$borgrepofile" ]; then
|
||||
echo "Not in a borg repo. Unable to find $borgrepofile."
|
||||
return
|
||||
fi
|
||||
|
||||
#générer la liste des archives
|
||||
borg list --short . >> $file
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "Error."
|
||||
return
|
||||
fi
|
||||
if [ "$?" != "0" ]; then echo "Error generating list of archives. Exiting." && return;fi
|
||||
|
||||
sed -i 's/^/"/' $file
|
||||
sed -i 's/$/"/' $file
|
||||
sed -i 's/^/#borg delete -v .::/' $file
|
||||
|
||||
clear
|
||||
echo "### BORG DELETER ###"
|
||||
echo ""
|
||||
echo "Just uncomment lines you want to delete and save your file."
|
||||
echo "Watch out you're doing, there won't be other confirmation."
|
||||
sleep 5
|
||||
sed -i '1s/^/\n/' $file
|
||||
sed -i '1s/^/BORG_PASSPHRASE=\"\"\n/' $file
|
||||
sed -i '1s/^/#Quick and dirty fix for repo with passphrase\n/' $file
|
||||
sed -i '1s/^/\n/' $file
|
||||
sed -i '1s/^/#Watch out you'\''re doing, there won'\''t be other confirmation\n/' $file
|
||||
sed -i '1s/^/#Just uncomment lines you want to delete and save your file\n/' $file
|
||||
sed -i '1s/^/\n/' $file
|
||||
sed -i '1s/^/### BORG DELETER ###\n/' $file
|
||||
|
||||
$editor $file
|
||||
$EDITOR $file
|
||||
sh $file
|
||||
rm $file
|
||||
}
|
||||
|
||||
function bobagrepdeleter {
|
||||
TestBorgRepo
|
||||
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||
|
||||
borgrepo="${PWD##*/}"
|
||||
file="borgdelete_$borgrepo.sh"
|
||||
read -p "Pattern to filter : " grepfilter
|
||||
borg list --short ./ | grep $grepfilter >> $file
|
||||
if [ "$?" != "0" ]; then echo "Error generating list of archives. Exiting." && rm $file && return;fi
|
||||
|
||||
sed -i 's/^/"/' $file
|
||||
sed -i 's/$/"/' $file
|
||||
sed -i 's/^/#borg delete -v .::/' $file
|
||||
|
||||
sed -i '1s/^/\n/' $file
|
||||
sed -i '1s/^/BORG_PASSPHRASE=\"\"\n/' $file
|
||||
sed -i '1s/^/#Quick and dirty fix for repo with passphrase\n/' $file
|
||||
sed -i '1s/^/\n/' $file
|
||||
sed -i '1s/^/#Watch out you'\''re doing, there won'\''t be other confirmation.\n/' $file
|
||||
sed -i '1s/^/#Just uncomment lines you want to delete and save your file.\n/' $file
|
||||
sed -i '1s/^/\n/' $file
|
||||
sed -i '1s/^/### BORG GREP DELETER ###\n/' $file
|
||||
|
||||
$EDITOR $file
|
||||
sh $file
|
||||
rm $file
|
||||
}
|
||||
|
||||
|
||||
# mass archive renaming
|
||||
function bobarenamer {
|
||||
TestBorgRepo
|
||||
|
Loading…
Reference in New Issue
Block a user