Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # home handler script for backupninja
- # Every backup file will identify the host by its FQDN
- getconf backupname
- # Directory to store backups
- getconf backupdir
- # Default compression
- getconf compress
- # Include /home directory
- getconf includes
- # Exclude files with *.mp3 and *.mp4 extensions
- getconf excludes
- # Default extension for the packaged backup file
- getconf EXTENSION
- # Absolute path to date binary
- getconf TAR `which tar`
- # Absolute path to date binary
- getconf DATE `which date`
- # Chosen date format
- DATEFORMAT="%Y-%m-%d"
- # If backupdir does not exist, exit with fatal error
- if [ ! -d "$backupdir" ]
- then
- mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"
- fi
- # If backupdir is not writeable, exit with fatal error as well
- if [ ! -w "$backupdir" ]
- then
- fatal "Directory $backupdir is not writable"
- fi
- # Set the right tar option as per the chosen compression format
- case $compress in
- "gzip")
- compress_option="-z"
- EXTENSION="tar.gz"
- ;;
- "bzip")
- compress_option="-j"
- EXTENSION="tar.bz2"
- ;;
- "none")
- compress_option=""
- ;;
- *)
- warning "Unknown compress filter ($tar_compress)"
- compress_option=""
- EXTENSION="tar.gz"
- ;;
- esac
- # Exclude the following file types / directories
- exclude_options=""
- for i in $excludes
- do
- exclude_options="$exclude_options --exclude $i"
- done
- # Debugging messages, performing backup
- debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
- -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
- $includes
- # Redirect standard output to a file with .list extension
- # and standard error to a file with .err extension
- $TAR -c -p -v $compress_option $exclude_options \
- -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
- $includes \
- > "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
- 2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
- [ $? -ne 0 ] && fatal "Tar backup failed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement