Posted By

rubinsta on 09/10/08


Tagged

Bash rsync linux simmons college gslis


Versions (?)

DocBack


 / Published in: Bash
 

  1. # Docback 0.2
  2. # -----------------
  3. # A front-end to rsync:
  4. #
  5. # Back up documents to the
  6. # Simmons server space
  7. # -----------------
  8. # Aaron Rubinstein
  9. # 7/17/08
  10.  
  11. usage()
  12. {
  13. cat <<EOF
  14.  
  15. Docback
  16. Back up documents to your Simmons server space
  17. A front-end for rsync
  18.  
  19. Usage: -u value [-r value] [-d] [-t] filename1 [filename2...]
  20. -u Simmons username (required)
  21. -r remote directory
  22. -d copy entire directory
  23. -t copy file only if edited in last 24 hrs
  24. -g update local file from Simmons server (use with -r)
  25.  
  26. EOF
  27. exit 2;
  28. }
  29.  
  30. if [ $# -lt 1 ] ; then
  31. usage;
  32. fi
  33.  
  34. # Define options
  35. rflag=
  36. uflag=
  37. dflag=
  38. tflag=
  39. gflag=
  40.  
  41. while getopts 'r:u:dgt' OPTION
  42. do
  43. case $OPTION in
  44.  
  45. r) rflag=1
  46. rval="$OPTARG"
  47. ;;
  48. u) uflag=1
  49. uval="$OPTARG"
  50. ;;
  51. d) dflag=1
  52. ;;
  53. t) tflag=1
  54. ;;
  55. g) gflag=1
  56. ;;
  57. ?) printf "Usage: %s: -u value [-r value] [-t] [-d] [-g] filename1 [filename2...]\n" $(basename $0) >&2
  58. exit 2
  59. ;;
  60. esac
  61. done
  62. shift $(($OPTIND - 1))
  63.  
  64. # If "-d" specified, recursively copy directory with rsync
  65. if [ "$dflag" ] ; then
  66. rsync -vtr $* $uval@cleo.simmons.edu:/users/gslis/$uval/$rval
  67. fi
  68.  
  69. # If "-t" specified find file if edited within last 24 hrs
  70. if [ "$tflag" ] ; then
  71. FILE=$(find ${HOME}/ -mtime -1 -name $*)
  72.  
  73. # If nothing found, print message and exit
  74. if [ ! $FILE ] ; then
  75. echo "File has not been edited within last 24 hours"
  76. exit 1;
  77. fi
  78. fi
  79.  
  80. if [ "$gflag" ] ; then
  81. # Update local folder with contents of remote folder
  82. rsync -vtr $uval@cleo.simmons.edu:/users/gslis/$uval/$rval $*
  83. fi
  84.  
  85. # Send found file(s) via rsync
  86. rsync -v -t --progress $* $uval@cleo.simmons.edu:/users/gslis/$uval/$rval

Report this snippet  

You need to login to post a comment.