MesPhotos/ => c'est bon
MesPhotos/Courchevel/ => c'est PAS bon car il y a un sous-répertoire…pour l'instant, car je suis en train de régler ce problème…
=======
Edit : Voilà, c'est maintenant fait :
MesPhotos/ => c'est bon
et
MesPhotos/autant de sous répertoires/avec des espaces/dans le nom/Courchevel/ => c'est bon aussi
Code : Tout sélectionner
#!/bin/bash
### Nom du fichier qui va recevoir les messages d'erreurs de rsync
backup="/home/bernard/bin/Sauvegardes/backuperror0Del-portable_Sauv1T_500go_SSD224Go_Test3-complet.log"
### Options rsync
optsRsync="--archive --partial --progress --delete-during --stats"
### Couleurs
INVRT="\\033[7m"
STNDT="\\033[0;39m"
ROUGE="\\033[1;31m"
BLANC="\\033[0;02m"
JAUNE="\\033[1;33m"
BLEU="\\033[1;34m"
VERT="\\033[1;32m"
ROSE="\\033[1;35m"
CYAN="\\033[1;36m"
### Tableaux
tblNomSauv=( "SSD224Go" "DD1To" "DD500Go" )
tblColoMsg=( "${CYAN}" "${ROSE}" "${BLEU}" )
tblMntPnts=( "/media/bernard/SSD224Go/" "/media/bernard/Sauv1To-a/" "/media/usb0/" )
tblTrgDirs=( "" "SauvDdPrincipal1/" "SauvDdPrincipal2/" )
tblSrcRoot=( "/home/bernard/" "/" "/" )
tblSrcDirs=( "MesPhotos/;MesDocuments/;DocumentsPerso/;MesScripts/" "home/;etc/" "home/;etc/" )
### Séparateur liste répertoires tblSrcDirs
sepRep=";"
### Recommencer les tests si la touche R a été pressée
REPLY="r"
while [[ $REPLY = [rR] ]]; do
msg="\n"
erreurs=0
for idx in ${!tblMntPnts[@]}; do
msg+="${tblColoMsg[${idx}]}Le point de mountage\t${STNDT}${tblMntPnts[${idx}]} ${INVRT}"
if mountpoint -q "${tblMntPnts[${idx}]}"; then
msg+="${VERT} est bien un point de mountage accessible."
else
erreurs=1
msg+="${ROUGE} n'est pas un point de mountage."
fi
msg+="${STNDT}\n"
msg+="${tblColoMsg[${idx}]}Le répertoire\t\t${STNDT}${tblMntPnts[${idx}]}${tblTrgDirs[${idx}]} ${INVRT}"
if test -w "${tblMntPnts[${idx}]}${tblTrgDirs[${idx}]}"; then
msg+="${VERT} est OK."
else
erreurs=1
msg+="${ROUGE} n'est pas accessible en écriture."
fi
msg+="${STNDT}\n\n"
done
echo -e "${msg}"
### Si erreur trouvée => Dialogue
if test $erreurs = 1; then
echo -e "${INVRT}${VERT}P${STNDT}oursuivre la Sauvegarde, ${INVRT}${VERT}Q${STNDT}uitter (ou autre touche), ${INVRT}${VERT}R${STNDT}ecommencer.\n"
read -sn1
[[ $REPLY != [pPrR] ]] && { echo -e "${ROUGE}Abandon sauvegarde.${STNDT}\nSortie Sauvegarde\n"; exit; }
else
REPLY="P"
fi
done
### Générer le fichier pour rsync
genFileForRsync() {
while read myDir; do
myDir="${myDir%/*}"
printf '%s\n' "+ ${myDir}/***"
until [ "${myDir}" = "${myDir%/*}" ]; do
myDir="${myDir%/*}"
printf '%s\n' "+ ${myDir}/"
done
done < <(echo -e "${1}")
printf '%s\n' "- *"
}
### Sauvegarde(s)
for idx in ${!tblNomSauv[@]}; do
echo -e "${tblColoMsg[${idx}]}=========================================\nSynchronisation en cours pour ${tblNomSauv[${idx}]}..."
genFileForRsync "${tblSrcDirs[${idx}]//;/\\n}" | rsync ${optsRsync} --include-from=- "${tblSrcRoot[${idx}]}" "${tblMntPnts[${idx}]}${tblTrgDirs[${idx}]}" 2>> "${backup}"
done
### Message de fin
echo -e "${STNDT}============================================\nSauvegarde terminée $(date +'le : '%d-%m-%Y' à '%T)"
echo "$(date)" >> "${backup}"