Advertisement
Guest User

Untitled

a guest
May 21st, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.53 KB | None | 0 0
  1. # Function perpose;
  2. #   To check if the nas drive is mounted
  3. #   if not, mount it, if it is, move onto the rsync
  4. check_mount()
  5. {
  6.  
  7.     command=$(mount | grep $NAS_MOUNTDIR | cut -d\ -f3)
  8.     if [ "$command" != "$NAS_MOUNTDIR" ]
  9.     then
  10.     nas_mount
  11.     else
  12.     echo "$NAS_MOUNTDIR already mounted"
  13.     rsync_nas
  14.     fi
  15. #   exit 0
  16. }
  17.  
  18. # Function perpose;
  19. #   to mount the NAS cifs share to a local directory
  20. #  
  21. nas_mount()
  22. {
  23.     sudo mount -t cifs //$NAS_SERVER/$NAS_PATH -o username=$NAS_USER,password=$NAS_PASS /$NAS_MOUNTDIR
  24.          if [ ${PIPESTATUS[0]} -ne 0 ] ; then
  25.         echo -e "Mounting of cifs share from $NAS_SERVER has failed $(date +%R)" | log
  26.     exit
  27.         else
  28.         echo -e "Mounting of cifs share from $NAS_SERVER sucessful, moving onto rsync $(date +%R)" | log
  29.     rsync_nas
  30.          fi
  31. }
  32.  
  33. # Function perpose
  34. #   to remove the cif's mount
  35. #
  36. nas_umount()
  37. {
  38.     sudo umount /$NAS_MOUNTDIR
  39. }
  40.  
  41. # script perpose;
  42. #   take a local copy of the backup directory (including scanned archives) and
  43. #   rsync them to the mount cifs share mounted with the nas_mount function
  44. rsync_nas()
  45. {
  46.     sudo rsync -vauz $BACK_DIR/* /$NAS_MOUNTDIR 2>&1 > $LOG_DIR/rsync.$(datsudo e +%Y%m%d).log
  47.         if [ ${PIPESTATUS[0]} -ne 0 ] ; then
  48.         echo -e "rsync of $BACK_DIR has failed  $(date +%R)" | log
  49.     exit
  50.         else
  51.         echo -e "rsync of $BACK_DIR sucessful  $(date +%R)" | log
  52.     fi
  53. }
  54.  
  55. # Add the below Var's
  56.  
  57. # Add $NAS_SERVER=10.3.60.60
  58. # Add $NAS_USER=su
  59. # Add $NAS_PASS=*****
  60. # Add $NAS_PATH=comrad
  61. # Add $NAS_MOUNTDIR=/mnt/
  62. # Add $RSYNC_NAS=YES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement