delimiter for groups
reorganization of functions
This commit is contained in:
parent
82b68d3421
commit
f06458f1a0
@ -65,131 +65,294 @@ EOF
|
|||||||
|
|
||||||
alias bobahelp="bobaman"
|
alias bobahelp="bobaman"
|
||||||
|
|
||||||
##################################
|
###############################################################################
|
||||||
# Fonctions borg
|
# generals functions
|
||||||
##################################
|
###############################################################################
|
||||||
#Une fonction qu permet d’obtenir les information d’une archive.
|
|
||||||
function bobainfo {
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
borg info ./::$1
|
||||||
}
|
}
|
||||||
|
|
||||||
#Supprimmer l'archive en paramètre
|
function bobainfor {
|
||||||
function bobadel {
|
TestBorgRepo
|
||||||
borg delete ./::$1
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||||
|
|
||||||
|
borg info ./
|
||||||
}
|
}
|
||||||
|
|
||||||
#Supprimmer la dernière archive du dépôt
|
function bobainfolast {
|
||||||
function bobadelast {
|
TestBorgRepo
|
||||||
archive=$(borg list ./ --short | tail -n 1)
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||||
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)
|
archive=$(borg list --short ./ | tail -n 1)
|
||||||
borg info .::$archive
|
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 {
|
function bobainfoall {
|
||||||
|
TestBorgRepo
|
||||||
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||||
|
|
||||||
for borgarchive in $(borg list --short ./);do
|
for borgarchive in $(borg list --short ./);do
|
||||||
echo "---------------------------------------------------------------------------------------"
|
echo "------------------------------------------------------------------------------"
|
||||||
borg info .::$borgarchive
|
borg info .::$borgarchive
|
||||||
echo "---------------------------------------------------------------------------------------"
|
echo "------------------------------------------------------------------------------"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#Exporter toutes les informations des archives dans un dépôt dans un fichier json
|
function bobadurationr {
|
||||||
function bobainfoalljson {
|
TestBorgRepo
|
||||||
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||||
|
|
||||||
for borgarchive in $(borg list --short ./);do
|
for borgarchive in $(borg list --short ./);do
|
||||||
borg info --json .::$borgarchive >> $HOME/borginfo.txt
|
borg info .::$borgarchive | grep "Archive name"
|
||||||
|
borg info .::$borgarchive | grep "Duration"
|
||||||
|
echo ""
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#Trouver un fichier dans un dépôt, affiche la liste des archives qui contient le fichier
|
function bobadur {
|
||||||
function bobasearchinarchive {
|
TestBorgRepo
|
||||||
|
if [ "$TestBorgErr" = "1" ];then return;fi
|
||||||
|
|
||||||
|
echo " Original size Compressed size Deduplicated size"
|
||||||
for borgarchive in $(borg list --short ./);do
|
for borgarchive in $(borg list --short ./);do
|
||||||
borggrep=$(borg list --short .::$borgarchive | grep $1)
|
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
|
if [ $? = 0 ];then
|
||||||
echo "Chaine trouvé dans l'archive : $borgarchive"
|
echo ""
|
||||||
|
echo "-- $borgarchive --"
|
||||||
|
echo "$borggrep"
|
||||||
|
echo ""
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#Supprimmer en masse des archives dans un dépôt
|
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 {
|
function bobadeleter {
|
||||||
|
TestBorgRepo
|
||||||
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
||||||
|
|
||||||
borgrepo="${PWD##*/}"
|
borgrepo="${PWD##*/}"
|
||||||
file="borgdelete_$borgrepo.sh"
|
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
|
borg list --short . >> $file
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$?" != "0" ]; then echo "Error generating list of archives. Exiting." && return;fi
|
||||||
echo "Error."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
sed -i 's/^/"/' $file
|
sed -i 's/^/"/' $file
|
||||||
sed -i 's/$/"/' $file
|
sed -i 's/$/"/' $file
|
||||||
sed -i 's/^/#borg delete -v .::/' $file
|
sed -i 's/^/#borg delete -v .::/' $file
|
||||||
|
|
||||||
clear
|
sed -i '1s/^/\n/' $file
|
||||||
echo "### BORG DELETER ###"
|
sed -i '1s/^/BORG_PASSPHRASE=\"\"\n/' $file
|
||||||
echo ""
|
sed -i '1s/^/#Quick and dirty fix for repo with passphrase\n/' $file
|
||||||
echo "Just uncomment lines you want to delete and save your file."
|
sed -i '1s/^/\n/' $file
|
||||||
echo "Watch out you're doing, there won't be other confirmation."
|
sed -i '1s/^/#Watch out you'\''re doing, there won'\''t be other confirmation\n/' $file
|
||||||
sleep 5
|
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
|
sh $file
|
||||||
rm $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
|
# mass archive renaming
|
||||||
function bobarenamer {
|
function bobarenamer {
|
||||||
TestBorgRepo
|
TestBorgRepo
|
||||||
|
Loading…
Reference in New Issue
Block a user