1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#/bin/sh
ping -c 1 "192.168.1.100" > /dev/null #test du réseau
if [ $? -ne 0 ]
then
echo "Le serveur n'est pas accessible."
exit 1
fi
mount | grep "//192.168.1.100" > /dev/null #test du montage
if [ $? -eq 1 ]
then
echo "Le montage n'est pas disponible."
exit 2
fi
if [ $# -eq 1 ]
then
pc="/home/fabien/Documents/$1"
serveur="/media/Partage/BackUp/Backup_pc/$1/"
rep="$1"
else
pc="/home/fabien/Documents"
serveur="/media/Partage/BackUp/Backup_pc/"
rep=""
fi
if [ $# -eq 3 ]
then
nbfic="$2"
taillefic="$3"
else
nbfic=0
taillefic=0
fi
for ficourep in "$pc"/*
do
fic=`basename "$ficourep"`
echo "$fic"
if [ -f "$ficourep" ] #si le "fic" est un fichier
then
if [ ! -f "$serveur$fic" ] #si le fic n'est pas présent sur le serveur
then
echo "Copie de $fic"
cp "$ficourep" "$serveur"
tfic=`stat -c %s "$ficourep"`
taillefic=`expr $taillefic + $tfic`
nbfic=`expr $nbfic + 1`
else #si le fic est déjà présent
date_serv=`stat -c "%Y" "$serveur$fic"`
date_pc=`stat -c "%Y" "$ficourep"`
if [ "$date_pc" -gt "$date_serv" ] #si le fic est plus récent
then
echo "Copie de $fic"
cp "$ficourep" "$serveur"
tfic=`stat -c %s "$ficourep"`
taillefic=`expr $taillefic + $tfic`
nbfic=`expr $nbfic + 1`
fi
fi
elif [ -d "$ficourep" ] #si le "fic" est un repertoire
then
if [ ! -d $serveur$fic ] #si le "fic" n'existe pas sur le serveur
then
mkdir $serveur$fic
fi
sh "$0" "$rep/$fic" $nbfic "$taillefic"
fi
done
tailletot="$taillefic octet"
if [ $taillefic -gt 1024 -a $taillefic -lt 1048576 ]
then
taillefic=$(echo "scale = 2; $taillefic/1024" | bc)
tailletot="$taillefic ko"
elif [ $taillefic -gt 1048576 ]
then
taillefic=$(echo "scale = 2; $taillefic/1024" | bc)
tailletot="$taillefic mo"
fi
if [ $nbfic -gt 1 ]
then
nbtot="$nbfic fichiers"
else [ $nbfic -eq 1 ]
nbtot="$nbfic fichier"
fi
echo "$nbtot mis à jour pour un total de $tailletot"
exit 0 |
Partager