Advertisement
gacanepa

backupninjahandler

Nov 29th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.03 KB | None | 0 0
  1. # home handler script for backupninja
  2.  
  3. # Every backup file will identify the host by its FQDN
  4. getconf backupname
  5.  
  6. # Directory to store backups
  7. getconf backupdir
  8.  
  9. # Default compression
  10. getconf compress
  11.  
  12. # Include /home directory
  13. getconf includes
  14.  
  15. # Exclude files with *.mp3 and *.mp4 extensions
  16. getconf excludes
  17.  
  18. # Default extension for the packaged backup file
  19. getconf EXTENSION
  20.  
  21. # Absolute path to date binary
  22. getconf    TAR    `which tar`
  23.  
  24. # Absolute path to date binary
  25. getconf    DATE    `which date`
  26.  
  27. # Chosen date format
  28. DATEFORMAT="%Y-%m-%d"
  29.  
  30. # If backupdir does not exist, exit with fatal error
  31. if [ ! -d "$backupdir" ]
  32. then
  33.    mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"
  34. fi
  35.  
  36. # If backupdir is not writeable, exit with fatal error as well
  37. if [ ! -w "$backupdir" ]
  38. then
  39.    fatal "Directory $backupdir is not writable"
  40. fi
  41.  
  42. # Set the right tar option as per the chosen compression format
  43. case $compress in
  44.    "gzip")
  45.       compress_option="-z"
  46.       EXTENSION="tar.gz"
  47.       ;;
  48.    "bzip")
  49.       compress_option="-j"
  50.       EXTENSION="tar.bz2"
  51.       ;;
  52.    "none")
  53.       compress_option=""
  54.       ;;
  55.    *)
  56.       warning "Unknown compress filter ($tar_compress)"
  57.       compress_option=""
  58.       EXTENSION="tar.gz"
  59.       ;;
  60. esac
  61.  
  62. # Exclude the following file types / directories
  63. exclude_options=""
  64. for i in $excludes
  65. do
  66.    exclude_options="$exclude_options --exclude $i"
  67. done
  68.  
  69. # Debugging messages, performing backup
  70. debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
  71.    -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
  72.    $includes
  73.  
  74. # Redirect standard output to a file with .list extension
  75. # and standard error to a file with .err extension
  76. $TAR -c -p -v $compress_option $exclude_options \
  77.    -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
  78.    $includes \
  79.    > "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
  80.    2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
  81.  
  82. [ $? -ne 0 ] && fatal "Tar backup failed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement