borgaliasandfunctions/borgaliasandfunctions.txt

168 lines
4.5 KiB
Plaintext
Raw Normal View History

##################################
# Fonctions borg
##################################
#Une fonction qu permet dobtenir les information dune archive.
function bobainfo {
borg info ./::$1
}
#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 darchives 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
}
2021-04-05 11:15:32 +02:00
#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"
fi
done
2021-04-05 11:16:05 +02:00
}
#Supprimmer en masse des archives dans un dépôt
function bobadeleter {
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
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
$editor $file
sh $file
rm $file
2021-04-05 11:17:28 +02:00
}
# mass archive renaming
function bobarenamer {
TestBorgRepo
if [ "$TestBorgErr" = "1" ]; then return;fi
which paste || echo "Paste command not found." exit
borgrepo="${PWD##*/}"
file="file_$borgrepo.txt"
originals="originals_$borgrepo.txt"
script="borgrenamer_$borgrepo.sh"
echo "Generating list of archives..."
borg list --short . >> $originals
if [ "$?" != "0" ]; then echo "Error generating list of archives. Exiting." && return;fi
cp $originals $file
$EDITOR $file
sed -i 's/^/"/' $originals
sed -i 's/$/"/' $originals
sed -i 's/^/borg rename -v .::/' $originals
sed -i 's/^/"/' $file
sed -i 's/$/"/' $file
paste -d" " $originals $file > $script
sed -i '1s/^/\n/' $script
sed -i '1s/^/\n/' $script
sed -i '1s/^/BORG_PASSPHRASE=\"\"\n/' $script
sed -i '1s/^/#Quick and dirty fix for repo with passphrase\n/' $script
sed -i '1s/^/\n/' $script
sed -i '1s/^/#Modifications in this file will be applied\, comment all to cancel\.\n/' $script
sed -i '1s/^/### BORG RENAMER ###\n/' $script
$EDITOR $script
echo "Renaming..."
sh $script
rm $file
rm $originals
rm $script
2021-04-05 11:15:32 +02:00
}