backup-add-script 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # mybackupadd - Add file to ~/.mybackup file, then backup and email all
  3. # file as tar.gz to your email a/c.
  4. #
  5. # Usage : ./mybackupadd ~/public_html/
  6. #
  7. # Copyright (C) 2004 nixCraft project
  8. # Email : http://cyberciti.biz/fb/
  9. # Date : Aug-2004
  10. # -------------------------------------------------------------------------
  11. # This program is free software; you can redistribute it and/or
  12. # modify it under the terms of the GNU General Public License
  13. # as published by the Free Software Foundation; either version 2
  14. # of the License, or (at your option) any later version.
  15. # -------------------------------------------------------------------------
  16. # This script is part of nixCraft shell script collection (NSSC)
  17. # Visit http://bash.cyberciti.biz/ for more information.
  18. # -------------------------------------------------------------------------
  19. FILE=~/.mybackup
  20. MYH=~
  21. CWD=`pwd`
  22. SRC=$1
  23. if [ "$SRC" == "" ]; then
  24. echo "Must supply dir or file name"
  25. exit 1
  26. fi
  27. # if list $FILE does not exist
  28. [ ! -f $FILE ] && touch $FILE || :
  29. # make sure that file or dir exists to backup
  30. if [ ! -f $SRC ]; then
  31. if [ ! -d $SRC ]; then
  32. echo "$SRC does not exists"
  33. exit 2
  34. fi
  35. fi
  36. # make sure we don't do add duplicate stuff
  37. cat $FILE | grep -w $SRC > /dev/null
  38. if [ "$?" == "0" ]; then
  39. echo "$SRC exists in $FILE"
  40. exit 3
  41. fi
  42. # okay now add that to backup list
  43. echo "$SRC" >> $FILE
  44. echo "$SRC added to $FILE"