+#!/bin/sh
+
+# tape-backup-mult
+#
+# Creates archive at current position of tape, thus enabling creation of
+# multiple archives on a single tape. After the backup is finished,
+# the tape is NOT 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 current position of the tape."
+ echo " After the backup is finished, the tape is NOT 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="Backup (`date '+%Y-%m-%d'`)"
+fi
+
+DIRECTORIES=${@}
+
+echo "TAPE_LABEL=$TAPE_LABEL"
+
+if ${MT} status | grep "ONLINE"; then
+
+ # We don't rewind the tape, we add a new archive at the current position of the tape.
+
+ # Finding sockets
+ # Removed, because the find command returned: "find: /root/big-file.tar.bz2: Value too large for defined data type"
+ # (the file was 6G)
+ # find ${DIRECTORIES} -type s > ${EXC_LIST} || exit 1
+ echo "" > ${EXC_LIST}
+
+ # Setting compression on
+ ${MT} compression 1 || exit 1
+
+ # Archiving
+ tar -cf /dev/tape ${DIRECTORIES} --label="${TAPE_LABEL}" --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
+
+ rm ${EXC_LIST}
+else
+ echo "***** WARNING TAPE DRIVE IS OFFLINE, NO BACKUPS PERFORMED"
+ exit 1
+fi
+
+exit $?