Newer
Older
tbku / tbku
  1. #!/bin/sh
  2. # Automated Backup Script For TundraWare Inc. Servers
  3. # Copyright (c) 2004-2008, TundraWare Inc., Des Plaines, IL
  4. # All Rights Reserved.
  5. # For Updates See: http://www.tundraware.com/Software/tbku
  6. # $Id: tbku,v 1.115 2012/06/09 18:17:40 tundra Exp $
  7.  
  8.  
  9. #####
  10. # Things User May Want To Change
  11. #####
  12.  
  13. ###
  14. # Program Locations
  15. ###
  16.  
  17. # Try to figure out where things are on this particular
  18. # system. If you can't, default to FreeBSD settings.
  19.  
  20. DATE=`which date`
  21. LS=`which ls`
  22. SED=`which sed`
  23. TAR=`which tar`
  24. TOUCH=`which touch`
  25. UNAME=`which uname`
  26.  
  27. DATE=${DATE:-"/bin/date"}
  28. LS=${LS:-"/bin/ls"}
  29. SED=${SED:-"/usr/bin/sed"}
  30. TAR=${TAR:-"/usr/bin/tar"}
  31. TOUCH=${TOUCH:-"/usr/bin/touch"}
  32. UNAME=${UNAME:-"/usr/bin/uname"}
  33.  
  34. ###
  35. # Default Directories
  36. ###
  37.  
  38. # You can override with corresponding environment
  39. # variable or change the default value here.
  40.  
  41. BKUDIR=${TBKUDIR:-"/bku"} # Where to write the backup files
  42. FILESETDIR=${TBKUSETS:-"$HOME/tbku"} # Where to find fileset files
  43.  
  44. ###
  45. # Tape Device
  46. ###
  47.  
  48. TAPEDEV=${TBKUTAPE:-"/dev/sa0"} # Default to FreeBSD SCSI tape
  49.  
  50. ###
  51. # File Naming
  52. ###
  53.  
  54. DATETIME=-`${DATE} "+%Y%m%d"` # Datestamp used to uniquely ID backups
  55. MACHINE=`${UNAME} -n`- # Name of the machine we're on
  56. OSTYPE=`${UNAME} -s`- # Operating System Type
  57. OSREV=`${UNAME} -r`- # Operating System Revision Level
  58. HWTYPE=`${UNAME} -p` # Processor Type
  59.  
  60. BKUNAME=${MACHINE}${OSTYPE}${OSREV}${HWTYPE} # Backup base name
  61. BKUNAME=${TBKUNAME:-$BKUNAME} # But the user can override it
  62.  
  63. ####
  64. # Automatic Deletion Of Previous Backups
  65. ####
  66.  
  67. # Use this with caution!
  68.  
  69. BKUDEL=${TBKUDEL:-"NO"} # Must be "YES" for autodelete
  70.  
  71.  
  72. ############## Nothing Below Should Need To Be Changed #############
  73.  
  74.  
  75. ALLSETS="allsets" # Special name to force every backup set to be done
  76. COMMON="auto" # Common name for automated backups
  77.  
  78. #####
  79. # Setup
  80. #####
  81.  
  82. umask 077 # Make sure only owner can read backups
  83. mkdir -p ${BKUDIR} # Make sure the backup directory exists
  84.  
  85.  
  86. #####
  87. # Figure Out Which Backup Sets To Do
  88. #####
  89.  
  90. cd $FILESETDIR
  91.  
  92. if [ $# -ne 0 ]
  93. then
  94. if [ _$1 = _$ALLSETS ]
  95. then
  96. LIST=`${LS} * 2>/dev/null`
  97. else
  98. for arg in $*
  99. do
  100. a=`${LS} *${arg} 2>/dev/null`
  101. LIST=$LIST" $a"
  102. done
  103. fi
  104.  
  105. else
  106. LIST=`${LS} $COMMON* 2>/dev/null`
  107. fi
  108.  
  109.  
  110. #####
  111. # Do The Actual Backups, And Leave Indication Of Start/Stop Times For Each Backup Set
  112. #####
  113.  
  114.  
  115. # If nothing matches / there is nothing to do, tell the user
  116.  
  117. LST=`echo $LIST | ${SED} "s/\ //"` # Get rid of spaces from concatenation above
  118. if [ "_${LST}" = "_" ]
  119. then
  120. echo "tbku: Nothing to do! Exiting ..."
  121. exit
  122. fi
  123.  
  124.  
  125. # Otherwise process each fileset
  126.  
  127. for x in $LIST
  128. do
  129. s=`echo $x | ${SED} "s/.*\.//"` # Get the suffix
  130.  
  131. BASENAME=$BKUNAME-$s
  132. STAMPEDNAME=${BASENAME}${DATETIME}
  133.  
  134. #####
  135. # Distinguish Between Tape And File Backups
  136. #####
  137.  
  138. if [ "_${s}" = "_tape" ]
  139. then
  140. FULLNAME=$TAPEDEV
  141. else
  142. FULLNAME=$BKUDIR/$STAMPEDNAME.tar.gz
  143. fi
  144.  
  145. # Optionally, get rid of previous backups of this fileset
  146.  
  147. if [ _${TBKUDEL} = "_YES" ]
  148. then
  149. rm $BKUDIR/.$BASENAME* $BKUDIR/$BASENAME*
  150. fi
  151.  
  152. echo "Now Doing Backup Set: $s"
  153. ${TOUCH} $BKUDIR/.$STAMPEDNAME-begin
  154. ${TAR} -cvzT $FILESETDIR/$x -f $FULLNAME >$BKUDIR/$STAMPEDNAME.log 2>&1
  155. ${TOUCH} $BKUDIR/.$STAMPEDNAME-end
  156. done