backup_users.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. set -e
  3. function print_centered {
  4. [[ $# == 0 ]] && return 1
  5. declare -i TERM_COLS="$(tput cols)"
  6. declare -i str_len="${#1}"
  7. [[ $str_len -ge $TERM_COLS ]] && {
  8. echo "$1";
  9. return 0;
  10. }
  11. declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
  12. [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
  13. filler=""
  14. for (( i = 0; i < filler_len; i++ )); do
  15. filler="${filler}${ch}"
  16. done
  17. printf "%s%s%s" "$filler" "$1" "$filler"
  18. [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
  19. printf "\n"
  20. return 0
  21. }
  22. function configuration {
  23. if [ ! -f config.dat ]
  24. then
  25. echo ""
  26. print_centered "Fichier de config source.dat manquant !"
  27. print_centered "Sortie"
  28. exit 0
  29. else
  30. source config.dat
  31. print_centered "Disque source : $hdsource"
  32. print_centered "Disque destination: $hddest"
  33. fi
  34. }
  35. clear
  36. print_centered "$(tput bold)$(tput setaf 1)"
  37. print_centered " ▄▄▄▄ ▄▄▄ ▄████▄ ██ ▄█▀ █ ██ ██▓███ "
  38. print_centered "▓█████▄ ▒████▄ ▒██▀ ▀█ ██▄█▒ ██ ▓██▒▓██░ ██▒"
  39. print_centered "▒██▒ ▄██▒██ ▀█▄ ▒▓█ ▄ ▓███▄░ ▓██ ▒██░▓██░ ██▓▒"
  40. print_centered "▒██░█▀ ░██▄▄▄▄██ ▒▓▓▄ ▄██▒▓██ █▄ ▓▓█ ░██░▒██▄█▓▒ ▒"
  41. print_centered "░▓█ ▀█▓ ▓█ ▓██▒▒ ▓███▀ ░▒██▒ █▄▒▒█████▓ ▒██▒ ░ ░"
  42. print_centered "░▒▓███▀▒ ▒▒ ▓▒█░░ ░▒ ▒ ░▒ ▒▒ ▓▒░▒▓▒ ▒ ▒ ▒▓▒░ ░ ░"
  43. print_centered "▒░▒ ░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░░░▒░ ░ ░ ░▒ ░ "
  44. print_centered " ░ ░ ░ ▒ ░ ░ ░░ ░ ░░░ ░ ░ ░░ "
  45. print_centered " ░ ░ ░░ ░ ░ ░ ░ "
  46. print_centered " ░ ░ "
  47. print_centered "$(tput setaf 3)$(tput bold)"
  48. print_centered "Windows Users Backup Script"
  49. if [ ! -f /home/wareck/.pass1 ]
  50. then
  51. print_centered "$(tput bold)$(tput setaf 164)"
  52. print_centered "Executer d'abord le script de build !"
  53. print_centered "$(tput setaf 7)"
  54. exit
  55. else
  56. echo "$(tput setaf 7)"
  57. configuration
  58. sleep 5
  59. fi
  60. sudo umount /mnt/stockage
  61. sudo umount /mnt/hybrid
  62. sudo umount /mnt/swap
  63. echo -e "\n$(tput bold)$(tput setaf 164)Nettoyage des disques avant montage :$(tput setaf 7)"
  64. sudo ntfsfix $hdsource
  65. sudo ntfsfix $ĥddest
  66. #sudo ntfsfix /dev/sdd2
  67. if ! [ -d /mnt/stockage ];then sudo mkdir /mnt/stockage;fi
  68. if ! [ -d /mnt/hybrid ];then sudo mkdir /mnt/hybrid;fi
  69. if ! [ -d /mnt/swap ];then sudo mkdir /mnt/swap;fi
  70. sleep 0.5
  71. echo -e "\n$(tput bold)$(tput setaf 164)Montage du disque Stockage dans /mnt/swap :$(tput setaf 7)"
  72. sudo mount $hddest /mnt/swap
  73. sleep 0.5
  74. echo -e "Ok."
  75. echo -e "\n$(tput bold)$(tput setaf 164)Montage du disque Hybrid dans /mnt/hybrid :$(tput setaf 7)"
  76. sudo mount $hdsource /mnt/hybrid
  77. sleep 0.5
  78. echo -e "Ok."
  79. echo -e "\n$(tput bold)$(tput setaf 164)Delai avant le lancement de copie automatique :$(tput setaf 7)"
  80. for i in {30..1}
  81. do
  82. sleep 0.5
  83. echo -n "."
  84. done
  85. echo -e "\n$(tput bold)$(tput setaf 164)Début de la copie : $(tput setaf 7)"
  86. rsync -v --append --progress --recursive /mnt/hybrid/ /mnt/swap/Backup_Users/
  87. echo -e ""
  88. echo -e "Terminé..."