--- /dev/null
+#!/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 $?
--- /dev/null
+#!/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 $?
--- /dev/null
+#!/bin/sh
+
+# tape-list
+
+# Read configuration informations
+source /etc/backup.conf
+
+print_usage()
+{
+ echo "$(basename $0) - List content of tape archive."
+ echo "Usage: $(basename $0) [-h] [--label]"
+}
+
+if [ ${#} -gt 0 ]; then
+ if [ "x${1}" = "x-h" ]; then
+ print_usage
+ exit 0
+ fi
+fi
+
+if [ $# -gt 1 ]; then
+ print_usage
+ exit 1
+fi
+
+if [ $# = 1 ]; then
+ if [ "x${1}" != "x--label" ]; then
+ echo "Invalid argument"
+ print_usage
+ exit 1
+ fi
+
+ print_label="1"
+fi
+
+if ${MT} status | grep "ONLINE" 1> /dev/null 2>&1; then
+
+ # Rewinding the tape
+ ${MT} rewind || exit 1
+
+ file="0"
+ quit="0"
+
+ while [ ${quit} = "0" ]; do
+
+ file="$(( ${file} + 1 ))"
+
+ if [ "x${print_label}" = "x1" ]; then
+ echo "Label for archive #$file:"
+ tar tvf /dev/tape | grep "V---------"
+ if [ $? -ne 0 ]; then
+ echo "No archive #$file:"
+ quit="1"
+ fi
+ else
+ echo "Content of archive #$file:"
+ tar tvf /dev/tape || exit 1
+ fi
+
+ if [ ${quit} = "0" ]; then
+ # Position tape on next file
+ ${MT} fsf 1
+ if [ $? -ne 0 ]; then
+ quit="1"
+ fi
+ fi
+
+ done
+
+else
+ echo "TAPE DRIVE IS OFFLINE, NO LISTING PERFORMED"
+ exit 1
+fi
+
+exit $?
--- /dev/null
+#!/bin/sh
+
+# tape-restore
+
+# Read configuration informations
+source /etc/backup.conf
+
+print_usage()
+{
+ echo "$(basename $0) - Restore file or directory from tape."
+ echo "Usage: $(basename $0) [-h] FILE"
+}
+
+if [ ${#} -gt 0 ]; then
+ if [ "x${1}" = "x-h" ]; then
+ print_usage
+ exit 0
+ fi
+fi
+
+if [ $# != 1 ]; then
+ print_usage
+ exit 1
+fi
+
+if ${MT} status | grep "ONLINE"; then
+ # Rewinding the tape
+ ${MT} rewind || exit 1
+
+ # The tape is now positioned on the first archive
+ tar xvf /dev/tape ${@} || exit 1
+else
+ echo "TAPE DRIVE IS OFFLINE, NO RESTORE PERFORMED"
+fi
+
+exit $?