#! /bin/sh # # Author : Carsten Grohmann # # Date : 08. December 2003 # VERSION="0.4"; # # Licence : GPL # # State : runs fine # # Syntax : none # # Execute amdump and amverify with multiple optionsmultiple like # - no dumps on holydays and other free days # - save the mysql database before the dump # - only one crontab entry instead of several entries # - you can labeling monthly tapes automatically and mark them as no-reuse # # return values: # - 10 user is not AMANDA_USER # - 20 no tape in device # - 30 error during labeling the tape # # BEGIN USER CONFIG ################### # Weekdays to force a full backup # More entries are seperated by a space character # It is also possible to use a range of weekdays. In this case you can use # firstweekday-lastweekday. # Format of the entries: # Sunday = 0, Monday = 1, ... # Example: "5-6 0" means no backup Friday, Saturday and Sunday WEEKDAY_FORCE_FULL_DUMP="5" # Parts of the backup to force a full backup on level 0 # More entries are seperated by a space character. # Format of the entries: # computer_name:/directory # more entries are seperated by a space character # Example: "localhost:/home/exampleuser" oder "mycomputer:/home/only_me" FORCE_FULL_DUMP="localhost:/example my.domain.tld:/home" # Amanda configuration BACKUP_CONFIG="example" # Days without backup like holydays. # More entries are seperated by a space character. # It is also possible to use a range of days. In this case you can use # firstday-lastday. # Format of the entries: YYYYMMDD # Example: 20031224 means no backup on Chrismas Eve NOBACKUP_DAYS="20030102 20030103 20030418-20030421 \ 20030501 20030502 20030529 20030609 \ 20031003 20031119 20031223-20040102" # Days on with the tape should be labled # More entries are seperated by a space character. # Format of the entries: YYYYMMDD:NewLabel # Example: 20031219:Dezember2003 labled the tape on 19.12.2003 with the # name Dezember2003 LABEL_DAYS="20031219:Dezember2003" # mark the via LABEL_DAYS labeled types as no-reuse MARK_NOREUSE="yes" # Weekdays without backup. # More values are seperated by a space character. # You could use this option instead day based cronjobs NOBACKUP_WEEKDAYS="" # userid of the amanda programs AMANDA_USER="amanda" # runs amverify to verify your backup # default: should be "yes" USE_AMVERIFY="yes" # run $MYSQLBACKUP to save the databases USE_MYSQLBACKUP="yes" # print messages VERBOSE="no" # END USER CONFIG ################# # program settings -- do NOT change TIME=$(date '+%d.%m.%Y %H:%M') TODAY=$(date '+%Y%m%d') WEEKDAY=$(date '+%w') SCRIPT_USER=$(id -un) DEVICE="/dev/nst0" # program files AMDUMP="/usr/sbin/amdump" AMVERIFY="/usr/sbin/amverify" AMADMIN="/usr/sbin/amadmin" AMLABEL="/usr/sbin/amlabel" MYSQLBACKUP="/usr/bin/mysql_backup.pl" # Own functions ############### # Show the info message function do_info () { test $VERBOSE = yes && echo -e $* } # Show a waring message function do_warning () { echo "WARNING:" $* } # Show a error message function do_error () { echo "ERROR:" $* } # finish the script function do_exit () { do_info "Script finished" exit $1 } function is_range () { echo $1 | grep --silent "-" } # 1. first day # 2. today # 3. last day function is_inrange() { # only to better human read my_firstday=$1 my_today=$2 my_lastday=$3 test $my_firstday -le $my_today -a $my_today -le $my_lastday } # Program ######### # print program name and version do_info "`basename $0` Version $VERSION" trap do_exit SIGHUP SIGSTOP SIGKILL SIGTERM # check userid if [ "$SCRIPT_USER" != "$AMANDA_USER" ]; then do_error "You are not user $AMANDA_USER. Please start this script as user $AMANDA_USER or change the settings." do_exit 10 fi # check days without backup for i in $NOBACKUP_DAYS; do if is_range "$i"; then FIRSTDAY=${i%-*} LASTDAY=${i#*-} if is_inrange $FIRSTDAY $TODAY $LASTDAY; then do_info "No backup today ($TODAY)" do_exit fi elif [ "$i" -eq "$TODAY" ]; then do_info "No backup today ($TODAY)" do_exit fi done # check weekday without backup for i in $NOBACKUP_WEEKDAYS; do if is_range "$i"; then FIRSTDAY=${i%-*} LASTDAY=${i#*-} if is_inrange $FIRSTDAY $WEEKDAY $LASTDAY; then do_info "No backup this weekday ($WEEKDAY)" do_exit fi elif [ "$i" -eq "$WEEKDAY" ]; then do_info "No backup this weekday ($WEEKDAY)" do_exit fi done # check tape mt -f $DEVICE status >/dev/null 2>&1 if [ $? != 0 ]; then do_error "No tape in device $DEVICE. The backup failed." do_exit 20 fi # check day to label tape for i in $LABEL_DAYS; do LDAY=${i%:*} LLABEL=${i#*:} if [ "$TODAY" = "$LDAY" ]; then $AMLABEL $BACKUP_CONFIG $LLABEL if [ "$?" != "0" ]; then do_error "During label the tape" do_exit 30 fi if [ "$MARK_NOREUSE" = "yes" ]; then NO_REUSE=$LLABEL fi fi unset LDAY; unset LLABEL; done # force full backup for i in $WEEKDAY_FORCE_FULL_DUMP; do if [ "$i" -eq "$WEEKDAY" ]; then for j in $FORCE_FULL_DUMP; do do_info "force full dump for for ${j//:/ }" $AMADMIN $BACKUP_CONFIG force ${j//:/ } done fi done # dump MySQL database if [ "$USE_MYSQLBACKUP" = "yes" ]; then do_info "Save MySQL databases:" $MYSQLBACKUP >/dev/null 2>&1 if [ $? -ne 0 ]; then do_error "Backup of the MySQL databases failed" fi fi # write backup: call Amanda amdump do_info "Amdump started:" $AMDUMP $BACKUP_CONFIG >/dev/null 2>&1 # verify backup: call Amanda amverify if [ "$USE_AMVERIFY" = "yes" ]; then do_info "Amverify started:" $AMVERIFY $BACKUP_CONFIG >/dev/null 2>&1 fi # mark monthly tapes as no reuseable if [ "$NO_REUSE" ]; then do_info "Mark $NO_REUSE as no-reuse" $AMADMIN $BACKUP_CONFIG no-reuse $NO_REUSE >/dev/null 2>&1 fi do_info "Backup finished" do_exit