#!/bin/bash # # dump Backup Script # VER. 0.1 - http://exitmind.hybridoptix.net # Copyright (c) 2007-2008 crainte@hybridoptix.net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # -------------------------------------------------------------------- # -------------------------------------------------------------------- # Set the following variables to your system needs # (Detailed instructions below variables) # -------------------------------------------------------------------- # Backup location e.g /backups BACKUPDIR="/mnt/backup/filesystem" # Directory to backup BACKUP="/home" # Mail setup # What would you like to be mailed to you? # - log : send only log file # - stdout : will simply output the log to the screen if run manually # - quiet : only send logs if an error occurs MAILCONTENT="log" # Email Address to send mail to? (user@domain.com) MAILADDR="admin@clemsonlinux.org" # -------------------------------------------------------------------- # Advanced Options # -------------------------------------------------------------------- # Choose Compression level. (0 - 9) COMPLEVEL="2" DLEVEL="9" MLEVEL="0" # -------------------------------------------------------------------- # Change Log # -------------------------------------------------------------------- # # VER 0.1 - (2008-05-02) # Initial Release # # -------------------------------------------------------------------- # -------------------------------------------------------------------- # -------------------------------------------------------------------- # # Should not need to be modified from here down # # -------------------------------------------------------------------- # -------------------------------------------------------------------- # -------------------------------------------------------------------- VALUE=0 DATE=`date +%Y-%m-%d_%Hh%Mm` # Datestamp e.g 2002-09-21 DOW=`date +%A` # Day of the week e.g. Monday DNOW=`date +%u` # Day number of the week 1 to 7 where 1 represents Monday DOM=`date +%d` # Date of the Month e.g. 27 M=`date +%B` # Month e.g January W=`date +%V` # Week Number e.g 37 VER=0.1 # Version Number LOGFILE=$BACKUPDIR/DUMP-`date +%N`.log # Logfile Name OPT="-q -u" # Modify compession level if [ "$COMPLEVEL" != "2" ] then OPT="$OPT -z$COMPLEVEL" else OPT="$OPT -z" fi # Create required directories if [ ! -e "$BACKUPDIR" ] then mkdir -p "$BACKUPDIR" fi # Check for daily directories if [ ! -e "$BACKUPDIR/daily" ] then mkdir -p "$BACKUPDIR/daily" fi # Check for monthly directories if [ ! -e "$BACKUPDIR/monthly" ] then mkdir -p "$BACKUPDIR/monthly" fi HOST=`hostname` touch $LOGFILE exec 6>&1 # Link file descriptor #6 with stdout. # Saves stdout. exec > $LOGFILE # stdout replaced with file $LOGFILE. exec 7>&2 # Link file descriptor #7 with stderr. # Saves stderr. exec 2>&1 # stderr replaced with file $LOGFILE. # Functions fsdump () { /usr/sbin/dump $OPT -f $1 $BACKUP VALUE=$? return 0 } echo ========================================================= echo AutoDumpBackup VER $VER echo echo Backup of Server - $HOST echo ========================================================= echo Backup Start Time `date` echo ========================================================= if [ $DOM = "01" ]; then OPT="-$MLEVEL $OPT" echo "Monthly Backup of $BACKUP..." echo fsdump "$BACKUPDIR/monthly/$DATE.$M.backup" echo echo ------------------------------------------------------ else OPT="-$DLEVEL $OPT" echo "Daily Backup of $BACKUP..." echo Rotating last weeks Backup... eval rm -fv "$BACKUPDIR/daily/*.$DOW.backup" echo fsdump "$BACKUPDIR/daily/$DATE.$DOW.backup" echo echo ------------------------------------------------------ fi echo Backup End `date` echo ========================================================= echo Total disk space used for backup storage... echo Size - Location echo `du -hs "$BACKUPDIR"` echo echo ========================================================= # Clean up IO redirection exec 1>&6 6>&- exec 2>&7 7>&- if [ "$MAILCONTENT" = "log" ]; then cat "$LOGFILE" | mail -s "Filesystem Dump Log for $HOST - $DATE" $MAILADDR elif [ "$MAILCONTENT" = "quiet" ]; then if [ "$VALUE" = "3" ]; then cat "$LOGFILE" fi else cat "$LOGFILE" fi if [ "$VALuE" != 0 ] then STATUS=1 else STATUS=0 fi # Clean up Logfile eval rm -f "$LOGFILE" exit $STATUS