2021-04-05 11:18:32 +02:00
|
|
|
|
###############################################################################
|
|
|
|
|
# help functions
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
function bobaman {
|
|
|
|
|
cat << EOF
|
|
|
|
|
BorgBackup alias and functions (by Djan GICQUEL)
|
|
|
|
|
---
|
|
|
|
|
bobals With argument : list all files of an archive
|
|
|
|
|
Without argument : list achives in repo
|
|
|
|
|
bobagrepls List the archives of the repository with a filter (prompting)
|
|
|
|
|
bobainfoa Get information of an archive in argument
|
|
|
|
|
bobainfor Get information of a repository
|
|
|
|
|
bobainfolast Get info from last archive
|
|
|
|
|
bobainfoall Get info from all archives in the repository (can be long and cpu intensive)
|
|
|
|
|
bobadurationr Show name and backup duration for all archive in the current repo (can be long and cpu intensive)
|
|
|
|
|
bobadur List the name of all archives and sizes (O,C,D) (can be long and cpu intensive)
|
|
|
|
|
bobamount Mount archive in argument in the home dir of the current user
|
|
|
|
|
bobamountfirst Mount first archive in the home dir of the current user
|
|
|
|
|
bobamountlast Mount last archive in the home dir of the current user
|
|
|
|
|
bobasearchinrepo Search for a file in the repository, the function will display a list of all archives that contain the match
|
|
|
|
|
bobasearchinarchive Search for a file in the archive in argument, displaying full path in the archive
|
|
|
|
|
1st argument : archive,2nd argument : text to find
|
|
|
|
|
bobacachedel Delete the cache dir of a repository (do not delete any archive)
|
|
|
|
|
bobasecuritydel Delete the security folder from a repository (do not delete any archive)
|
|
|
|
|
bobadel Delete the archive in argument
|
|
|
|
|
bobadelast Delete the last archive in the repository
|
|
|
|
|
bobacheckrepo Check the repo consistencyi without repairing it (to avoid data lost)
|
|
|
|
|
bobadeleter Mass archives deleting
|
|
|
|
|
bobagrepdeleter Mass archives deleting with filter (prompting)
|
|
|
|
|
bobarenamer Mass archives renaming
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bobaaide {
|
|
|
|
|
cat << EOF
|
|
|
|
|
BorgBackup alias and functions (by Djan GICQUEL)
|
|
|
|
|
---
|
|
|
|
|
bobals Lister les archives du dépôt
|
|
|
|
|
bobagrepls Lister les archives du dépôt avec un filtre (saisie)
|
|
|
|
|
bobainfoa Obtenir les informations d’une archive
|
|
|
|
|
bobainfor Obtenir les informations d’un dépôt
|
|
|
|
|
bobainfolast Obtenir les informations de la dernière archive
|
|
|
|
|
bobadel Supprimer l'archive en paramètre
|
|
|
|
|
bobadelast Supprimer la dernière archive du dépôt
|
|
|
|
|
bobacheckrepo Vérifier la consistance d'un dépôt sans le réparer (pour éviter les pertes de donnée)
|
|
|
|
|
bobamount Monter une archive dans le home de l'utilisateur courant
|
|
|
|
|
bobamountlast Monter la dernière archive dans le home de l'utilisateur courant
|
|
|
|
|
bobainfolast Afficher les infos de la dernière archive
|
|
|
|
|
bobainfoall Affiche les infos de toutes les archives du dépôt (peut être long)
|
|
|
|
|
bobasearchinrepo Chercher un fichier dans le dépôt, la fonction va afficher le nom de toutes les archives qui contienne le fichier
|
|
|
|
|
bobasearchinarchive Chercher un fichier dans une archive en argument, affiche le chemin dans l'archive
|
|
|
|
|
1er argument : archive,2ème argument : chaîne de caractère à chercher
|
|
|
|
|
bobaduration Montrer le nom des archives et le temps de sauvegarde
|
|
|
|
|
bobadur Lister le nom des archive et leurs tailles (originale, compressée, dédupliquée)
|
|
|
|
|
bobadeleter Supprimer facilement plusieurs archives d'un dépôt
|
|
|
|
|
bobagrepdeleter Supprimer facilement plusieurs archives d'un dépôt avec un filtre (saisie)
|
|
|
|
|
bobarenamer Renommer en masses les archives d'un dépôt
|
|
|
|
|
bobacachedel Supprimer le cache d'un dépôt (ne supprime aucune archive)
|
|
|
|
|
bobasecuritydel Supprimer le dossier security d'un dépôt (ne supprime aucune archive)
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alias bobahelp="bobaman"
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
###############################################################################
|
|
|
|
|
# generals functions
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
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
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
function UnMount {
|
|
|
|
|
fusermount -u -z "$mountpoint"
|
|
|
|
|
sleep 5
|
|
|
|
|
rmdir "$mountpoint"
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
function DirExists {
|
|
|
|
|
if [ ! -d "$1" ]; then
|
|
|
|
|
echo "Error, directory $1 missing."
|
|
|
|
|
echo "Exiting.";sleep 10
|
|
|
|
|
exit
|
|
|
|
|
fi
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
###############################################################################
|
|
|
|
|
# list and infos functions
|
|
|
|
|
###############################################################################
|
2021-04-05 11:11:02 +02:00
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
function bobals {
|
|
|
|
|
TestBorgRepo
|
|
|
|
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
2021-04-05 11:11:02 +02:00
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
if [ "$1" != "" ]; then
|
|
|
|
|
borg list --short .::$1
|
|
|
|
|
else
|
|
|
|
|
borg list --short ./
|
|
|
|
|
fi
|
|
|
|
|
}
|
2021-04-05 11:11:02 +02:00
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
function bobagrepls {
|
|
|
|
|
TestBorgRepo
|
|
|
|
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
|
|
|
|
|
|
|
|
|
read -p "Pattern to filter : " grepfilter
|
|
|
|
|
borg list --short ./ | grep $grepfilter
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
function bobainfoa {
|
|
|
|
|
TestBorgRepo
|
|
|
|
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
|
|
|
|
|
|
|
|
|
borg info ./::$1
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
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
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bobainfoall {
|
2021-04-05 11:20:00 +02:00
|
|
|
|
TestBorgRepo
|
|
|
|
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
|
|
|
|
|
|
|
|
|
for borgarchive in $(borg list --short ./);do
|
|
|
|
|
echo "------------------------------------------------------------------------------"
|
|
|
|
|
borg info .::$borgarchive
|
|
|
|
|
echo "------------------------------------------------------------------------------"
|
|
|
|
|
done
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
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
|
2021-04-05 11:11:02 +02:00
|
|
|
|
}
|
2021-04-05 11:15:32 +02:00
|
|
|
|
|
|
|
|
|
function bobasearchinarchive {
|
2021-04-05 11:20:00 +02:00
|
|
|
|
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
|
2021-04-05 11:16:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
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
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2021-04-05 11:16:05 +02:00
|
|
|
|
function bobadeleter {
|
2021-04-05 11:20:00 +02:00
|
|
|
|
TestBorgRepo
|
|
|
|
|
if [ "$TestBorgErr" = "1" ]; then return;fi
|
|
|
|
|
|
2021-04-05 11:16:05 +02:00
|
|
|
|
borgrepo="${PWD##*/}"
|
|
|
|
|
file="borgdelete_$borgrepo.sh"
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
borg list --short . >> $file
|
|
|
|
|
if [ "$?" != "0" ]; then echo "Error generating list of archives. Exiting." && return;fi
|
2021-04-05 11:16:05 +02:00
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
sed -i 's/^/"/' $file
|
|
|
|
|
sed -i 's/$/"/' $file
|
|
|
|
|
sed -i 's/^/#borg delete -v .::/' $file
|
2021-04-05 11:16:05 +02:00
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
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
|
|
|
|
|
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
|
2021-04-05 11:16:05 +02:00
|
|
|
|
|
|
|
|
|
sed -i 's/^/"/' $file
|
|
|
|
|
sed -i 's/$/"/' $file
|
|
|
|
|
sed -i 's/^/#borg delete -v .::/' $file
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
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
|
2021-04-05 11:16:05 +02:00
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
$EDITOR $file
|
2021-04-05 11:16:05 +02:00
|
|
|
|
sh $file
|
|
|
|
|
rm $file
|
2021-04-05 11:17:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 11:20:00 +02:00
|
|
|
|
|
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:20:00 +02:00
|
|
|
|
}
|