Advertisement
Guest User

Untitled

a guest
May 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.88 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # name: 04_system_backup.sh
  5. # path: /root/Configs/Backup_Scripts/04_system_backup.sh
  6. #### #### #### ####
  7. # usage: sh $0 $1 #as root
  8. #### #### #### ####
  9. # comment:  backs up the complete system to the external hard-disk, partition1
  10. #### #### #### ####
  11.  
  12. clear
  13. date
  14. echo "
  15.     "
  16.  
  17. ########
  18. # VARs
  19. ########
  20.  
  21. BU_MP="/media/backup"
  22. BU_DEV=
  23.  
  24. USER=`id -u`
  25.  
  26. #########################################
  27. # Check for the conditio sine qua non
  28. #########################################
  29.  
  30. if [ "$USER" -eq 0 ]
  31. then
  32.     echo "you are root. All cool"
  33.     if [ "$#"  == 1 ]
  34.     then
  35.         BU_DEV="$1"
  36.         echo "We will mount "$1" on "$BU_MP", correct? "
  37.         read answer
  38.         case "$answer" in
  39.             "yes" | "y" | "Yes" ) echo "ok" ;;
  40.             "no" | "n" | "No" ) echo " Check the code"
  41.                                 exit 0 ;;
  42.              * ) "you are too dumb to give a simple answer"
  43.                  exit 0 ;;
  44.         esac
  45.     else
  46.          echo "You missed the device to be mounted. Do it now"
  47.          fdisk -l
  48.          echo -n "which one, full name, like /dev/sdx? "
  49.          read BU_DEV
  50.          echo "We will mount "$BU_DEV" on "$BU_MP", correct? "
  51.          read answer
  52.          case "$answer" in
  53.              "yes" | "y" | "Yes") echo "ok" ;;
  54.              "no" | "n" | "No" ) echo "Check the  code"
  55.                                  exit 0 ;;
  56.               * ) echo "Visit a shrink"
  57.                   exit 0
  58.          esac
  59.      fi
  60. else
  61.     echo "You need to run the script as root"
  62.     echo " Add a device which shall be mounted "
  63.     exit 0
  64. fi
  65.  
  66. ##############################
  67. # Mount "$BU_DEV" on "$BU_MP"
  68. ##############################
  69.  
  70. mount "$BU_DEV" "$BU_MP"
  71. ls /media/backup
  72.  
  73. echo -n "Looks good, you wanna run rsync now? "
  74. read answer
  75. case "$answer" in
  76.     "yes" | "y" | "Yes" ) echo "ok" ;;
  77.     "No" | "n" | "No" ) echo "Check the code"
  78.                         umount "$BU_MP"
  79.                         exit 0 ;;
  80.      * ) echo "Have a break, pal"
  81.                umount "$BU_MP"
  82.                exit 0
  83. esac
  84.  
  85.  
  86. ################################
  87. # run the Backup
  88. # remove " -n and > dry.txt once you know it works
  89. ##################################################
  90.  
  91. rsync -auv -n  --delete-after \
  92. --exclude="/home/m1arkust/[a-zA-Z0-9]*" \
  93. --exclude="/home/m1arkust/.VirtualBox/*" \
  94. --exclude="/home/xepanche/[a-zA-Z0-9]*" \
  95. --exclude="/proc/*" \
  96. --exclude="/lost+found/*" \
  97. --exclude="/dev/*" \
  98. --exclude="/mnt/*" \
  99. --exclude="/media/*" \
  100. --exclude="/sys/*" \
  101. --exclude="/tmp/*" \
  102. / /media/backup  > dry.txt
  103.  
  104. ######################
  105. # Last infos
  106. #######################
  107.  
  108. echo "
  109.    Rsync did finish, here is the actual content of "$BU_MP" "
  110. ls "$BU_MP"
  111. echo "
  112.    If it is wrong you are on your own. "
  113. echo "
  114.     "$BU_MP" will be umounted now"
  115. umount "$BU_MP"
  116.  
  117. echo "
  118.    Bye
  119.    "
  120.  
  121. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement