#!/bin/sh # tape-backup # # Creates a single archive on tape. After the backup is finished, # the tape is rewound. # Read configuration informations source /etc/backup.conf # Exclude files list EXC_LIST="/tmp/exclude-sockets" print_usage() { echo "$(basename $0) - Backup directories/files, starting at the beginning of the tape." echo " After the backup is finished, the tape is rewound." echo "Usage: $(basename $0) [-h] [--label "label"] DIR1 DIR2 ..." } if [ ${#} -gt 0 ]; then if [ "x${1}" = "x-h" ]; then print_usage exit 0 fi fi if [ $# = 0 ]; then echo "Missing arguments" print_usage exit 1 fi if [ "x${1}" = "x--label" ]; then if [ $# -lt 2 ]; then echo "Missing arguments for --label option" print_usage exit 1 fi TAPE_LABEL=${2} shift shift if [ $# = 0 ]; then echo "No directory to backup specified" print_usage exit 1 fi else TAPE_LABEL="CVDS Linux Mail/Web Server Backup (`date '+%Y-%m-%d'`)." fi DIRECTORIES=${@} echo "TAPE_LABEL=$TAPE_LABEL" if ${MT} status | grep "ONLINE"; then # Rewinding the tape ${MT} rewind || exit 1 # Finding sockets find ${DIRECTORIES} -type s > ${EXC_LIST} || exit 1 # Setting compression on ${MT} compression 1 || exit 1 # Archiving tar -cf /dev/tape ${DIRECTORIES} --ignore-failed-read --label="${TAPE_LABEL}" \ --exclude="*.sock" --exclude="*.lock" --exclude-from=${EXC_LIST} \ --absolute-names --totals || exit 1 if ! ${MT} status | grep "ONLINE"; then echo "***** tape-drive status is not ONLINE" exit 1 fi # Rewinding the tape ${MT} rewind || exit 1 # Ejecting tape ${MT} offline || exit 1 rm ${EXC_LIST} else echo "***** WARNING TAPE DRIVE IS OFFLINE, NO BACKUPS PERFORMED" exit 1 fi exit $?