#! /bin/bash which zenity if [ "$?" != "0" ]; then echo "Zenity n'est pas installé.";exit exit fi which borg if [ "$?" != "0" ]; then echo "borgbackup n'est pas installé.";exit exit fi # META VARIABLES ################################################################################# export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes dossierprofil="$HOME/.config/borg/" # FONCTIONS ################################################################################# TestBorgRepo () { if [ ! -f "config" ]; then TestBorgErr=1 infoerr=$(echo "Impossible de trouver le fichier de configuration borg.") zenity --width=600 --error --text="$infoerr" exit fi if [ ! -d "data" ]; then TestBorgErr=1 infoerr=$(echo "Impossible de trouver le fichier de configuration borg.") zenity --width=600 --error --text="$infoerr" exit fi if [ -d "lock.exclusive" ]; then TestBorgErr=1 infoerr=$(echo "Le dépôt est bloqué, une opération est peut-être en cours") zenity --width=600 --error --text="$infoerr" exit fi } bobainfoa () { TestBorgRepo borg info ./::$borg_repo } DossierPresent () { if [ ! -d "$1" ]; then inforerror=$(echo "Erreur, le dossier $1 est absent.\nFin du script.") zenity --width=600 --error --text="$inforerror" exit fi } # Profils et tests ################################################################################# # si $1 n'est pas vide fichier de profil = $1 # sinon afficher les profils disponibles if [ ! $1 = "" ]; then fichierprofil="$1" . "$1" else cd $dossierprofil fichierprofil=$(ls -1 *.txt | zenity --height=500 --width=600 --list --title "Liste des profils" --hide-header --column "profil") && . $fichierprofil fi if [ "$fichierprofil" = "" ]; then infoerr=$(echo "Aucun profil choisi.") zenity --width=600 --error --text="$infoerr" exit elif [ "$nomsauvegarde" = "" ]; then infoerr=$(echo "Nom de sauvegarde non défini.") zenity --width=600 --error --text="$infoerr" exit elif [ "$borg_repo" = "" ]; then infoerr=$(echo "Variable \$borg_repo absente") zenity --width=600 --error --text="$infoerr" exit fi cd $borg_repo TestBorgRepo ################################################################################# # MENU PRINCIPAL ################################################################################# ################################################################################# # Gestion des options du menu ################################################################################# while [ ! "$choixmenu" = "qu" ] do choixmenu=$(echo -e "\ cs\nCréer une archive\n\ ms\nMonter une archive\n\ dm\nDemonter une archive\n\ ss\nSupprimmer une archive\n\ is\nInformation archive\n\ id\nInformation sur le dépôt\n\ ap\nAfficher le profil\n\ ed\nEspace disque utilisé\n\ qu\nQuitter\ " | zenity --list \ --height=400 --width=400 \ --title "BORG GUI : $nomsauvegarde" \ --hide-header --hide-column=1 --column "id" --column "choix") if [ "$choixmenu" = "cs" ] ;then # Créer une archive TestBorgRepo DossierPresent $borg_repo DossierPresent $borg_dir espacedisqueutil=$(df -k --output=pcent $borg_repo | tail -n +2) zenity --width=600 --notification --text "Espace disque utilisé : $espacedisqueutil" borg create $borg_excludes $borg_compress $borg_repo::$borg_archive $borg_dir | zenity --width=600 --progress --pulsate --auto-close --title="Sauvegarde en cours..." sync | zenity --width=600 --progress --pulsate --auto-close --title="Synchronisation des écritures..." zenity --notification --text "Sauvegarde $nomsauvegarde terminée" zenity --width=600 --info --text "Sauvegarde $nomsauvegarde terminée" elif [ "$choixmenu" = "ed" ] ;then # Espace disque utilisé espacedisqueutil=$(df -k --output=pcent $borg_repo | tail -n +2) zenity --width=600 --info --text "Espace disque utilisé : $espacedisqueutil" elif [ "$choixmenu" = "ms" ];then # Monter une archive borg_archive=$(borg list --short $borg_repo | zenity --height=500 --list --title "Listes des archives" --column "Archive") mkdir $HOME/$borg_archive borg mount $borg_repo::$borg_archive $HOME/$borg_archive | zenity --width=600 --progress --pulsate --auto-close zenity --width=600 --info --text="La sauvegarde est disponible dans le dossier\n$HOME/$borg_archive" elif [ "$choixmenu" = "dm" ];then # Demonter une archive ptnmontage=$(mount | grep borgfs | cut -d" " -f3 | zenity --width=500 --height=400 --list --title "Liste des points de montages" --column "") fusermount -u $ptnmontage | zenity --width=600 --progress --pulsate --auto-close sleep 5 | zenity --width=600 --progress --pulsate --auto-close rmdir $ptnmontage | zenity --width=600 --progress --pulsate --auto-close elif [ "$choixmenu" = "ss" ];then # Supprimmer une archive borg_archive=$(borg list --short $borg_repo | zenity --height=500 --list --title "Listes des archives" --column "Archive") borg delete $borg_repo::$borg_archive | zenity --width=600 --progress --pulsate --auto-close zenity --width=600 --info --text="Suppresion de l'archive $borg_archive terminée" elif [ "$choixmenu" = "is" ];then # Information archive borg_archive=$(borg list --short $borg_repo | zenity --height=500 --list --title "Listes des archives" --column "Archive") zenity --width=600 --info --text="$(borg info $borg_repo::$borg_archive)" | zenity --width=600 --progress --pulsate --auto-close elif [ "$choixmenu" = "id" ];then # Information sur le dépôt zenity --width=600 --info --text="$(borg info $borg_repo)" | zenity --width=600 --progress --pulsate --auto-close --title="Récupération des informations..." elif [ "$choixmenu" = "ap" ];then # Afficher le profil zenity --width=600 --height=400 --info --text="$(cd $dossierprofil && cat $fichierprofil)" elif [ "$choixmenu" = "" ];then zenity --width=600 --info --text="Aucun choix, retour au menu." fi done