From 9fb3ae02b78da24e7edd75e744477d3bdada1753 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 12 Jan 2016 18:38:43 +0100 Subject: [PATCH] Change license as per agreement with FSFE --- bacula/scripts/Makefile.in | 2 +- bacula/scripts/bacula-ctl-dir.in | 101 +++++---- bacula/scripts/bacula-ctl-fd.in | 99 +++++---- bacula/scripts/bacula-ctl-sd.in | 99 +++++---- bacula/scripts/bacula.in | 5 +- bacula/scripts/bconsole.in | 3 +- bacula/scripts/breload.in | 2 +- bacula/scripts/btraceback.in | 2 +- bacula/scripts/devel_bacula.in | 2 +- bacula/scripts/disk-changer.in | 235 +++++++++++---------- bacula/scripts/dvd-handler.in | 343 +++++++++++++++---------------- bacula/scripts/dvd-simulator.in | 281 +++++++++++++------------ bacula/scripts/logrotate.in | 2 +- bacula/scripts/mtx-changer.in | 141 +++++++------ 14 files changed, 654 insertions(+), 663 deletions(-) diff --git a/bacula/scripts/Makefile.in b/bacula/scripts/Makefile.in index 47e1d9042b..e9b529d78d 100755 --- a/bacula/scripts/Makefile.in +++ b/bacula/scripts/Makefile.in @@ -1,6 +1,6 @@ # # -# Copyright (C) 2000-2015 Kern Sibbald +# Copyright (C) 2000-2016 Kern Sibbald # License: BSD 2-Clause; see file LICENSE-FOSS # @MCOMMON@ diff --git a/bacula/scripts/bacula-ctl-dir.in b/bacula/scripts/bacula-ctl-dir.in index 745651c8a3..ab1eaaca12 100644 --- a/bacula/scripts/bacula-ctl-dir.in +++ b/bacula/scripts/bacula-ctl-dir.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -19,7 +18,7 @@ # Bacula(R) is a registered trademark of Kern Sibbald. # # bacula-ctl-dir This shell script takes care of starting and stopping -# the bacula Director daemon +# the bacula Director daemon # # This is pretty much watered down version of the RedHat script # that works on Solaris as well as Linux, but it won't work everywhere. @@ -53,7 +52,7 @@ DIR_PORT=@dir_port@ DIR_USER=@dir_user@ DIR_GROUP=@dir_group@ Bacula="@BACULA@" -PIDOF=@PIDOF@ +PIDOF=@PIDOF@ # A function to stop a program. killproc() { @@ -82,31 +81,31 @@ killproc() { # Kill it. if [ "$pid" != "" ] ; then if [ "$notset" = "1" ] ; then - if ${PS} -p "$pid">/dev/null 2>&1; then - # TERM first, then KILL if not dead - kill -TERM $pid 2>/dev/null - sleep 1 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - sleep 1 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - sleep 3 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - kill -KILL $pid 2>/dev/null - fi - fi - fi - fi - ${PS} -p "$pid" >/dev/null 2>&1 - RC=$? - [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" + if ${PS} -p "$pid">/dev/null 2>&1; then + # TERM first, then KILL if not dead + kill -TERM $pid 2>/dev/null + sleep 1 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + sleep 1 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + sleep 3 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + kill -KILL $pid 2>/dev/null + fi + fi + fi + fi + ${PS} -p "$pid" >/dev/null 2>&1 + RC=$? + [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" # RC=$((! $RC)) # use specified level only else - if ${PS} -p "$pid" >/dev/null 2>&1; then - kill $killlevel $pid 2>/dev/null - RC=$? - [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" - fi + if ${PS} -p "$pid" >/dev/null 2>&1; then + kill $killlevel $pid 2>/dev/null + RC=$? + [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" + fi fi else failure "$base shutdown" @@ -134,8 +133,8 @@ pidofproc() { if [ -f ${PIDDIR}/$base.$2.pid ] ; then pid=`head -n 1 ${PIDDIR}/$base.$2.pid` if [ "$pid" != "" ] ; then - echo $pid - return 0 + echo $pid + return 0 fi fi @@ -174,12 +173,12 @@ status() { return 0 else pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 } - { if ((prog == $2) || (("(" prog ")") == $2) || - (("[" prog "]") == $2) || - ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` + { if ((prog == $2) || (("(" prog ")") == $2) || + (("[" prog "]") == $2) || + ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` if [ "$pid" != "" ] ; then - echo "$base (pid $pid) is running..." - return 0 + echo "$base (pid $pid) is running..." + return 0 fi fi @@ -187,8 +186,8 @@ status() { if [ -f ${PIDDIR}/$base.$2.pid ] ; then pid=`head -n 1 ${PIDDIR}/$base.$2.pid` if [ "$pid" != "" ] ; then - echo "$base dead but pid file exists" - return 1 + echo "$base dead but pid file exists" + return 1 fi fi # See if the subsys lock exists @@ -219,29 +218,29 @@ fi case "$1" in start) [ -x ${BACDIRBIN}/bacula-dir ] && { - echo "Starting the $Bacula Director daemon" - OPTIONS='' - if [ "${DIR_USER}" != '' ]; then - OPTIONS="${OPTIONS} -u ${DIR_USER}" - fi + echo "Starting the $Bacula Director daemon" + OPTIONS='' + if [ "${DIR_USER}" != '' ]; then + OPTIONS="${OPTIONS} -u ${DIR_USER}" + fi - if [ "${DIR_GROUP}" != '' ]; then - OPTIONS="${OPTIONS} -g ${DIR_GROUP}" - fi + if [ "${DIR_GROUP}" != '' ]; then + OPTIONS="${OPTIONS} -g ${DIR_GROUP}" + fi - if [ "x${VALGRIND_DIR}" = "x1" ]; then - valgrind --leak-check=full ${BACDIRBIN}/bacula-dir $2 $3 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf - else - ${BACDIRBIN}/bacula-dir $2 $3 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf - fi - sleep 1 + if [ "x${VALGRIND_DIR}" = "x1" ]; then + valgrind --leak-check=full ${BACDIRBIN}/bacula-dir $2 $3 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf + else + ${BACDIRBIN}/bacula-dir $2 $3 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf + fi + sleep 1 } ;; stop) [ -x ${BACDIRBIN}/bacula-dir ] && { - echo "Stopping the $Bacula Director daemon" - killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT} $2 + echo "Stopping the $Bacula Director daemon" + killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT} $2 } ;; diff --git a/bacula/scripts/bacula-ctl-fd.in b/bacula/scripts/bacula-ctl-fd.in index c359eaea61..0032f0ba60 100644 --- a/bacula/scripts/bacula-ctl-fd.in +++ b/bacula/scripts/bacula-ctl-fd.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -19,7 +18,7 @@ # Bacula(R) is a registered trademark of Kern Sibbald. # # bacula-ctl-fd This shell script takes care of starting and stopping -# the bacula File daemon. +# the bacula File daemon. # # This is pretty much watered down version of the RedHat script # that works on Solaris as well as Linux, but it won't work everywhere. @@ -50,7 +49,7 @@ FD_PORT=@fd_port@ FD_USER=@fd_user@ FD_GROUP=@fd_group@ Bacula="@BACULA@" -PIDOF=@PIDOF@ +PIDOF=@PIDOF@ # A function to stop a program. killproc() { @@ -79,31 +78,31 @@ killproc() { # Kill it. if [ "$pid" != "" ] ; then if [ "$notset" = "1" ] ; then - if ${PS} -p "$pid">/dev/null 2>&1; then - # TERM first, then KILL if not dead - kill -TERM $pid 2>/dev/null - sleep 1 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - sleep 1 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - sleep 3 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - kill -KILL $pid 2>/dev/null - fi - fi - fi - fi - ${PS} -p "$pid" >/dev/null 2>&1 - RC=$? - [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" + if ${PS} -p "$pid">/dev/null 2>&1; then + # TERM first, then KILL if not dead + kill -TERM $pid 2>/dev/null + sleep 1 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + sleep 1 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + sleep 3 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + kill -KILL $pid 2>/dev/null + fi + fi + fi + fi + ${PS} -p "$pid" >/dev/null 2>&1 + RC=$? + [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" # RC=$((! $RC)) # use specified level only else - if ${PS} -p "$pid" >/dev/null 2>&1; then - kill $killlevel $pid 2>/dev/null - RC=$? - [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" - fi + if ${PS} -p "$pid" >/dev/null 2>&1; then + kill $killlevel $pid 2>/dev/null + RC=$? + [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" + fi fi else failure "$base shutdown" @@ -131,8 +130,8 @@ pidofproc() { if [ -f ${PIDDIR}/$base.$2.pid ] ; then pid=`head -n 1 ${PIDDIR}/$base.$2.pid` if [ "$pid" != "" ] ; then - echo $pid - return 0 + echo $pid + return 0 fi fi @@ -171,12 +170,12 @@ status() { return 0 else pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 } - { if ((prog == $2) || (("(" prog ")") == $2) || - (("[" prog "]") == $2) || - ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` + { if ((prog == $2) || (("(" prog ")") == $2) || + (("[" prog "]") == $2) || + ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` if [ "$pid" != "" ] ; then - echo "$base (pid $pid) is running..." - return 0 + echo "$base (pid $pid) is running..." + return 0 fi fi @@ -184,8 +183,8 @@ status() { if [ -f ${PIDDIR}/$base.$2.pid ] ; then pid=`head -n 1 ${PIDDIR}/$base.$2.pid` if [ "$pid" != "" ] ; then - echo "$base dead but pid file exists" - return 1 + echo "$base dead but pid file exists" + return 1 fi fi # See if the subsys lock exists @@ -216,29 +215,29 @@ fi case "$1" in start) [ -x ${BACFDBIN}/bacula-fd ] && { - echo "Starting the $Bacula File daemon" - OPTIONS='' - if [ "${FD_USER}" != '' ]; then - OPTIONS="${OPTIONS} -u ${FD_USER}" - fi + echo "Starting the $Bacula File daemon" + OPTIONS='' + if [ "${FD_USER}" != '' ]; then + OPTIONS="${OPTIONS} -u ${FD_USER}" + fi - if [ "${FD_GROUP}" != '' ]; then - OPTIONS="${OPTIONS} -g ${FD_GROUP}" - fi + if [ "${FD_GROUP}" != '' ]; then + OPTIONS="${OPTIONS} -g ${FD_GROUP}" + fi - if [ "x${VALGRIND_FD}" = "x1" ]; then - valgrind --leak-check=full ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf - else - ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf - fi + if [ "x${VALGRIND_FD}" = "x1" ]; then + valgrind --leak-check=full ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf + else + ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf + fi } ;; stop) # Stop the FD first so that SD will fail jobs and update catalog [ -x ${BACFDBIN}/bacula-fd ] && { - echo "Stopping the $Bacula File daemon" - killproc ${BACFDBIN}/bacula-fd ${FD_PORT} $2 + echo "Stopping the $Bacula File daemon" + killproc ${BACFDBIN}/bacula-fd ${FD_PORT} $2 } ;; diff --git a/bacula/scripts/bacula-ctl-sd.in b/bacula/scripts/bacula-ctl-sd.in index 3f5543b400..f545cd6380 100644 --- a/bacula/scripts/bacula-ctl-sd.in +++ b/bacula/scripts/bacula-ctl-sd.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -19,7 +18,7 @@ # Bacula(R) is a registered trademark of Kern Sibbald. # # bacula-ctl-sd This shell script takes care of starting and stopping -# the bacula Storage daemon +# the bacula Storage daemon # # This is pretty much watered down version of the RedHat script # that works on Solaris as well as Linux, but it won't work everywhere. @@ -50,7 +49,7 @@ SD_PORT=@sd_port@ SD_USER=@sd_user@ SD_GROUP=@sd_group@ Bacula="@BACULA@" -PIDOF=@PIDOF@ +PIDOF=@PIDOF@ # A function to stop a program. killproc() { @@ -79,31 +78,31 @@ killproc() { # Kill it. if [ "$pid" != "" ] ; then if [ "$notset" = "1" ] ; then - if ${PS} -p "$pid">/dev/null 2>&1; then - # TERM first, then KILL if not dead - kill -TERM $pid 2>/dev/null - sleep 1 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - sleep 1 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - sleep 3 - if ${PS} -p "$pid" >/dev/null 2>&1 ; then - kill -KILL $pid 2>/dev/null - fi - fi - fi - fi - ${PS} -p "$pid" >/dev/null 2>&1 - RC=$? - [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" + if ${PS} -p "$pid">/dev/null 2>&1; then + # TERM first, then KILL if not dead + kill -TERM $pid 2>/dev/null + sleep 1 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + sleep 1 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + sleep 3 + if ${PS} -p "$pid" >/dev/null 2>&1 ; then + kill -KILL $pid 2>/dev/null + fi + fi + fi + fi + ${PS} -p "$pid" >/dev/null 2>&1 + RC=$? + [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" # RC=$((! $RC)) # use specified level only else - if ${PS} -p "$pid" >/dev/null 2>&1; then - kill $killlevel $pid 2>/dev/null - RC=$? - [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" - fi + if ${PS} -p "$pid" >/dev/null 2>&1; then + kill $killlevel $pid 2>/dev/null + RC=$? + [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" + fi fi else failure "$base shutdown" @@ -131,8 +130,8 @@ pidofproc() { if [ -f ${PIDDIR}/$base.$2.pid ] ; then pid=`head -n 1 ${PIDDIR}/$base.$2.pid` if [ "$pid" != "" ] ; then - echo $pid - return 0 + echo $pid + return 0 fi fi @@ -171,12 +170,12 @@ status() { return 0 else pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 } - { if ((prog == $2) || (("(" prog ")") == $2) || - (("[" prog "]") == $2) || - ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` + { if ((prog == $2) || (("(" prog ")") == $2) || + (("[" prog "]") == $2) || + ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` if [ "$pid" != "" ] ; then - echo "$base (pid $pid) is running..." - return 0 + echo "$base (pid $pid) is running..." + return 0 fi fi @@ -184,8 +183,8 @@ status() { if [ -f ${PIDDIR}/$base.$2.pid ] ; then pid=`head -n 1 ${PIDDIR}/$base.$2.pid` if [ "$pid" != "" ] ; then - echo "$base dead but pid file exists" - return 1 + echo "$base dead but pid file exists" + return 1 fi fi # See if the subsys lock exists @@ -216,29 +215,29 @@ fi case "$1" in start) [ -x ${BACSDBIN}/bacula-sd ] && { - echo "Starting the $Bacula Storage daemon" - OPTIONS='' - if [ "${SD_USER}" != '' ]; then - OPTIONS="${OPTIONS} -u ${SD_USER}" - fi + echo "Starting the $Bacula Storage daemon" + OPTIONS='' + if [ "${SD_USER}" != '' ]; then + OPTIONS="${OPTIONS} -u ${SD_USER}" + fi - if [ "${SD_GROUP}" != '' ]; then - OPTIONS="${OPTIONS} -g ${SD_GROUP}" - fi + if [ "${SD_GROUP}" != '' ]; then + OPTIONS="${OPTIONS} -g ${SD_GROUP}" + fi - if [ "x${VALGRIND_SD}" = "x1" ]; then - valgrind --leak-check=full ${BACSDBIN}/bacula-sd $2 $3 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf - else - ${BACSDBIN}/bacula-sd $2 $3 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf - fi + if [ "x${VALGRIND_SD}" = "x1" ]; then + valgrind --leak-check=full ${BACSDBIN}/bacula-sd $2 $3 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf + else + ${BACSDBIN}/bacula-sd $2 $3 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf + fi } ;; stop) [ -x ${BACSDBIN}/bacula-sd ] && { - echo "Stopping the $Bacula Storage daemon" - killproc ${BACSDBIN}/bacula-sd ${SD_PORT} $2 + echo "Stopping the $Bacula Storage daemon" + killproc ${BACSDBIN}/bacula-sd ${SD_PORT} $2 } ;; diff --git a/bacula/scripts/bacula.in b/bacula/scripts/bacula.in index 34adcfc8ec..cadfa655b0 100755 --- a/bacula/scripts/bacula.in +++ b/bacula/scripts/bacula.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -19,7 +18,7 @@ # Bacula(R) is a registered trademark of Kern Sibbald. # # bacula This shell script takes care of starting and stopping -# the bacula daemons. +# the bacula daemons. # # This is pretty much watered down version of the RedHat script # that works on Solaris as well as Linux, but it won't work everywhere. diff --git a/bacula/scripts/bconsole.in b/bacula/scripts/bconsole.in index f711fcf577..f696ba1cfa 100755 --- a/bacula/scripts/bconsole.in +++ b/bacula/scripts/bconsole.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/scripts/breload.in b/bacula/scripts/breload.in index 958acad082..a571f96094 100644 --- a/bacula/scripts/breload.in +++ b/bacula/scripts/breload.in @@ -2,7 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/scripts/btraceback.in b/bacula/scripts/btraceback.in index 1b21954755..269cc7e4a5 100755 --- a/bacula/scripts/btraceback.in +++ b/bacula/scripts/btraceback.in @@ -2,7 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald +# Copyright (C) 2000-2016 Kern Sibbald # Copyright (C) 2000-2014 Free Software Foundation Europe e.V. # # The original author of Bacula is Kern Sibbald, with contributions diff --git a/bacula/scripts/devel_bacula.in b/bacula/scripts/devel_bacula.in index da0f675a83..53e36c156e 100755 --- a/bacula/scripts/devel_bacula.in +++ b/bacula/scripts/devel_bacula.in @@ -1,6 +1,6 @@ #! /bin/sh # -# Copyright (C) 2000-2015 Kern Sibbald +# Copyright (C) 2000-2016 Kern Sibbald # License: BSD 2-Clause; see file LICENSE-FOSS # # bacula This shell script takes care of starting and stopping diff --git a/bacula/scripts/disk-changer.in b/bacula/scripts/disk-changer.in index 9627badfad..cf5a9735c7 100644 --- a/bacula/scripts/disk-changer.in +++ b/bacula/scripts/disk-changer.in @@ -6,8 +6,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -31,7 +30,7 @@ # included. # # disk-changer "changer-device" "command" "slot" "archive-device" "drive-index" "volume" -# $1 $2 $3 $4 $5 $6 +# $1 $2 $3 $4 $5 $6 # # By default the autochanger has 10 Volumes and 1 Drive. # @@ -41,8 +40,8 @@ # # changer-device is the name of a file that overrides the default # volumes and drives. It may have: -# maxslot=n where n is one based (default 10) -# maxdrive=m where m is zero based (default 1 -- i.e. 2 drives) +# maxslot=n where n is one based (default 10) +# maxdrive=m where m is zero based (default 1 -- i.e. 2 drives) # # This code can also simulate barcodes. You simply put # a list of the slots and barcodes in the "base" directory/barcodes. @@ -86,7 +85,7 @@ wd=@working_dir@ dbgfile="$wd/disk-changer.log" debug() { if test -f $dbgfile; then - echo "`date +\"%Y%m%d-%H:%M:%S\"` $*" >> $dbgfile + echo "`date +\"%Y%m%d-%H:%M:%S\"` $*" >> $dbgfile fi } @@ -99,8 +98,8 @@ make_temp_file() { if test x${TMPFILE} = x; then TMPFILE="$wd/disk-changer.$$" if test -f ${TMPFILE}; then - echo "Temp file security problem on: ${TMPFILE}" - exit 1 + echo "Temp file security problem on: ${TMPFILE}" + exit 1 fi fi } @@ -111,14 +110,14 @@ check_parm_count() { pCount=$1 pCountNeed=$2 if test $pCount -lt $pCountNeed; then - echo "usage: disk-changer ctl-device command [slot archive-device drive-index]" - echo " Insufficient number of arguments arguments given." - if test $pCount -lt 2; then - echo " Mimimum usage is first two arguments ..." - else - echo " Command expected $pCountNeed arguments" - fi - exit 1 + echo "usage: disk-changer ctl-device command [slot archive-device drive-index]" + echo " Insufficient number of arguments arguments given." + if test $pCount -lt 2; then + echo " Mimimum usage is first two arguments ..." + else + echo " Command expected $pCountNeed arguments" + fi + exit 1 fi } @@ -131,7 +130,7 @@ get_dir() { dir=`echo "$device" | sed -e s%/$bn%%g` if [ ! -d $dir ]; then echo "ERROR: Autochanger directory \"$dir\" does not exist." - echo " You must create it." + echo " You must create it." exit 1 fi } @@ -178,32 +177,32 @@ fi # case $2 in list|listall) - check_parm_count $# 2 - ;; + check_parm_count $# 2 + ;; slots) - check_parm_count $# 2 - ;; + check_parm_count $# 2 + ;; transfer) - check_parm_count $# 4 - if [ $slot -gt $maxslot ]; then - echo "Slot ($slot) out of range (1-$maxslot)" - debug "Error: Slot ($slot) out of range (1-$maxslot)" - exit 1 - fi - ;; + check_parm_count $# 4 + if [ $slot -gt $maxslot ]; then + echo "Slot ($slot) out of range (1-$maxslot)" + debug "Error: Slot ($slot) out of range (1-$maxslot)" + exit 1 + fi + ;; *) - check_parm_count $# 5 - if [ $drive -gt $maxdrive ]; then - echo "Drive ($drive) out of range (0-$maxdrive)" - debug "Error: Drive ($drive) out of range (0-$maxdrive)" - exit 1 - fi - if [ $slot -gt $maxslot ]; then - echo "Slot ($slot) out of range (1-$maxslot)" - debug "Error: Slot ($slot) out of range (1-$maxslot)" - exit 1 - fi - ;; + check_parm_count $# 5 + if [ $drive -gt $maxdrive ]; then + echo "Drive ($drive) out of range (0-$maxdrive)" + debug "Error: Drive ($drive) out of range (0-$maxdrive)" + exit 1 + fi + if [ $slot -gt $maxslot ]; then + echo "Slot ($slot) out of range (1-$maxslot)" + debug "Error: Slot ($slot) out of range (1-$maxslot)" + exit 1 + fi + ;; esac @@ -214,21 +213,21 @@ case $cmd in debug "Doing disk -f $ctl unload $slot $device $drive $volume" get_dir if [ -f $dir/loaded${drive} ]; then - ld=`cat $dir/loaded${drive}` + ld=`cat $dir/loaded${drive}` else - echo "Storage Element $slot is Already Full" - debug "Unload error: $dir/loaded${drive} is already unloaded" - exit 1 + echo "Storage Element $slot is Already Full" + debug "Unload error: $dir/loaded${drive} is already unloaded" + exit 1 fi if [ $slot -eq $ld ]; then - echo "0" >$dir/loaded${drive} - unlink $device 2>/dev/null >/dev/null - unlink ${device}.add 2>/dev/null >/dev/null - rm -f ${device} ${device}.add + echo "0" >$dir/loaded${drive} + unlink $device 2>/dev/null >/dev/null + unlink ${device}.add 2>/dev/null >/dev/null + rm -f ${device} ${device}.add else - echo "Storage Element $slot is Already Full" - debug "Unload error: $dir/loaded${drive} slot=$ld is already unloaded" - exit 1 + echo "Storage Element $slot is Already Full" + debug "Unload error: $dir/loaded${drive} slot=$ld is already unloaded" + exit 1 fi ;; @@ -238,53 +237,53 @@ case $cmd in i=0 # Check if slot already in a drive while [ $i -le $maxdrive ]; do - if [ -f $dir/loaded${i} ]; then - ld=`cat $dir/loaded${i}` - else - ld=0 - fi - if [ $ld -eq $slot ]; then - echo "Drive ${i} Full (Storage element ${ld} loaded)" - debug "Load error: Cannot load Slot=${ld} in drive=$drive. Already in drive=${i}" - exit 1 - fi - i=`expr $i + 1` + if [ -f $dir/loaded${i} ]; then + ld=`cat $dir/loaded${i}` + else + ld=0 + fi + if [ $ld -eq $slot ]; then + echo "Drive ${i} Full (Storage element ${ld} loaded)" + debug "Load error: Cannot load Slot=${ld} in drive=$drive. Already in drive=${i}" + exit 1 + fi + i=`expr $i + 1` done # Check if we have a Volume name get_vol if [ $havevol -eq 0 ]; then - # check if slot exists - if [ ! -f $dir/slot${slot} ] ; then - echo "source Element Address $slot is Empty" - debug "Load error: source Element Address $slot is Empty" - exit 1 - fi + # check if slot exists + if [ ! -f $dir/slot${slot} ] ; then + echo "source Element Address $slot is Empty" + debug "Load error: source Element Address $slot is Empty" + exit 1 + fi fi if [ -f $dir/loaded${drive} ]; then - ld=`cat $dir/loaded${drive}` + ld=`cat $dir/loaded${drive}` else - ld=0 + ld=0 fi if [ $ld -ne 0 ]; then - echo "Drive ${drive} Full (Storage element ${ld} loaded)" - echo "Load error: Drive ${drive} Full (Storage element ${ld} loaded)" - exit 1 + echo "Drive ${drive} Full (Storage element ${ld} loaded)" + echo "Load error: Drive ${drive} Full (Storage element ${ld} loaded)" + exit 1 fi echo "0" >$dir/loaded${drive} unlink $device 2>/dev/null >/dev/null unlink ${device}.add 2>/dev/null >/dev/null rm -f ${device} ${device}.add if [ $havevol -ne 0 ]; then - ln -s $dir/$volume $device - ln -s $dir/${volume}.add ${device}.add - rtn=$? + ln -s $dir/$volume $device + ln -s $dir/${volume}.add ${device}.add + rtn=$? else - ln -s $dir/slot${slot} $device - ln -s $dir/slot${slot}.add ${device}.add - rtn=$? + ln -s $dir/slot${slot} $device + ln -s $dir/slot${slot}.add ${device}.add + rtn=$? fi if [ $rtn -eq 0 ]; then - echo $slot >$dir/loaded${drive} + echo $slot >$dir/loaded${drive} fi exit $rtn ;; @@ -293,20 +292,20 @@ case $cmd in debug "Doing disk -f $ctl -- to list volumes" get_dir if [ -f $dir/barcodes ]; then - cat $dir/barcodes + cat $dir/barcodes else - i=1 - while [ $i -le $maxslot ]; do - slot=$i - volume= - get_vol - if [ $havevol -eq 0 ]; then - echo "$i:" - else - echo "$i:$volume" - fi - i=`expr $i + 1` - done + i=1 + while [ $i -le $maxslot ]; do + slot=$i + volume= + get_vol + if [ $havevol -eq 0 ]; then + echo "$i:" + else + echo "$i:$volume" + fi + i=`expr $i + 1` + done fi exit 0 ;; @@ -317,20 +316,20 @@ case $cmd in debug "Doing disk -f $ctl -- to list volumes" get_dir if [ ! -f $dir/barcodes ]; then - exit 0 + exit 0 fi # we print drive content seen by autochanger # and we also remove loaded media from the barcode list i=0 while [ $i -le $maxdrive ]; do - if [ -f $dir/loaded${i} ]; then - ld=`cat $dir/loaded${i}` - v=`awk -F: "/^$ld:/"' { print $2 }' $dir/barcodes` - echo "D:$i:F:$ld:$v" - echo "^$ld:" >> $TMPFILE - fi - i=`expr $i + 1` + if [ -f $dir/loaded${i} ]; then + ld=`cat $dir/loaded${i}` + v=`awk -F: "/^$ld:/"' { print $2 }' $dir/barcodes` + echo "D:$i:F:$ld:$v" + echo "^$ld:" >> $TMPFILE + fi + i=`expr $i + 1` done # Empty slots are not in barcodes file @@ -339,15 +338,15 @@ case $cmd in grep -v -f $TMPFILE $dir/barcodes | sort -n | \ perl -ne 'BEGIN { $cur=1 } if (/(\d+):(.+)?/) { - if ($cur == $1) { - print "S:$1:F:$2\n" - } else { - while ($cur < $1) { - print "S:$cur:E\n"; - $cur++; - } - } - $cur++; + if ($cur == $1) { + print "S:$1:F:$2\n" + } else { + while ($cur < $1) { + print "S:$cur:E\n"; + $cur++; + } + } + $cur++; } END { while ($cur < '"$maxslot"') { print "S:$cur:E\n"; $cur++; } } ' @@ -360,12 +359,12 @@ case $cmd in make_temp_file slotdest=$device if [ -f $dir/slot{$slotdest} ]; then - echo "destination Element Address $slot is Full" - exit 1 + echo "destination Element Address $slot is Full" + exit 1 fi if [ ! -f $dir/slot${slot} ] ; then - echo "source Element Address $slot is Empty" - exit 1 + echo "source Element Address $slot is Empty" + exit 1 fi echo "Transfering $slot to $slotdest" @@ -373,8 +372,8 @@ case $cmd in mv $dir/slot${slot}.add $dir/slot{$slotdest}.add if [ -f $dir/barcodes ]; then - sed "s/^$slot:/$slotdest:/" > $TMPFILE - sort -n $TMPFILE > $dir/barcodes + sed "s/^$slot:/$slotdest:/" > $TMPFILE + sort -n $TMPFILE > $dir/barcodes fi exit 0 ;; @@ -382,9 +381,9 @@ case $cmd in debug "Doing disk -f $ctl $drive -- to find what is loaded" get_dir if [ -f $dir/loaded${drive} ]; then - a=`cat $dir/loaded${drive}` + a=`cat $dir/loaded${drive}` else - a="0" + a="0" fi debug "Loaded: drive=$drive is $a" echo $a diff --git a/bacula/scripts/dvd-handler.in b/bacula/scripts/dvd-handler.in index e8492ae2bf..2d2bcf154f 100644 --- a/bacula/scripts/dvd-handler.in +++ b/bacula/scripts/dvd-handler.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -27,30 +26,30 @@ # operations used by Bacula: # # free (no arguments) -# Scan the device and report the available space. It returns: -# Prints on the first output line the free space available in bytes. -# If an error occurs, prints a negative number (-errno), followed, -# on the second line, by an error message. +# Scan the device and report the available space. It returns: +# Prints on the first output line the free space available in bytes. +# If an error occurs, prints a negative number (-errno), followed, +# on the second line, by an error message. # # write op filename -# Write a part file to disk. -# This operation needs two additional arguments. -# The first (op) indicates to -# 0 -- append -# 1 -- first write to a blank disk -# 2 -- blank or truncate a disk +# Write a part file to disk. +# This operation needs two additional arguments. +# The first (op) indicates to +# 0 -- append +# 1 -- first write to a blank disk +# 2 -- blank or truncate a disk # -# The second is the filename to write +# The second is the filename to write # # operations available but not used by Bacula: # # test Scan the device and report the information found. -# This operation needs no further arguments. +# This operation needs no further arguments. # prepare Prepare a DVD+/-RW for being used by Bacula. -# Note: This is only useful if you already have some -# non-Bacula data on a medium, and you want to use -# it with Bacula. Don't run this on blank media, it -# is useless. +# Note: This is only useful if you already have some +# non-Bacula data on a medium, and you want to use +# it with Bacula. Don't run this on blank media, it +# is useless. # # # $Id$ @@ -90,23 +89,23 @@ class disk: # dvd-writepart doesn't not always need to know the free space). # # The following methods are implemented: -# __init__ we need that... -# __repr__ this seems to be a good idea to have. -# Quite minimalistic implementation, though. -# __str__ For casts to string. Return the current disk information -# is_empty Returns TRUE if the disk is empty, blank... this needs more -# work, especially concerning non-RW media and blank vs. no -# filesystem considerations. Here, we should also look for -# other filesystems - probably we don't want to silently -# overwrite UDF or ext2 or anything not mentioned in fstab... -# (NB: I don't think it is a problem) -# free Returns the available free space. -# write Writes one part file to disk, either starting a new file -# system on disk, or appending to it. -# This method should also prepare a blank disk so that a -# certain part of the disk is used to allow detection of a -# used disk by all / more disk drives. -# prepare Blank the device +# __init__ we need that... +# __repr__ this seems to be a good idea to have. +# Quite minimalistic implementation, though. +# __str__ For casts to string. Return the current disk information +# is_empty Returns TRUE if the disk is empty, blank... this needs more +# work, especially concerning non-RW media and blank vs. no +# filesystem considerations. Here, we should also look for +# other filesystems - probably we don't want to silently +# overwrite UDF or ext2 or anything not mentioned in fstab... +# (NB: I don't think it is a problem) +# free Returns the available free space. +# write Writes one part file to disk, either starting a new file +# system on disk, or appending to it. +# This method should also prepare a blank disk so that a +# certain part of the disk is used to allow detection of a +# used disk by all / more disk drives. +# prepare Blank the device # ############################################################################### def __init__(self, devicename): @@ -125,10 +124,10 @@ class disk: self.growcmd += " -quiet" if self.is4gbsupported(): - self.growcmd += " -use-the-force-luke=4gms" + self.growcmd += " -use-the-force-luke=4gms" self.growparams = " -A 'Bacula Data' -input-charset=default -iso-level 3 -pad " + \ - "-p 'dvd-handler / growisofs' -sysid 'BACULADATA' -R" + "-p 'dvd-handler / growisofs' -sysid 'BACULADATA' -R" return @@ -137,9 +136,9 @@ class disk: def __str__(self): if not self.freespace_collected: - self.collect_freespace(); + self.collect_freespace(); if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); self.me = "Class disk, initialized with device '" + self.device + "'\n" self.me += "type = '" + self.disktype + "' mode='" + self.diskmode + "' status = '" + self.diskstatus + "'\n" @@ -153,47 +152,47 @@ class disk: processi = popen2.Popen4("uname -s -r") status = processi.wait() if not os.WIFEXITED(status): - return 1 + return 1 if os.WEXITSTATUS(status) != 0: - return 1 + return 1 strres = processi.fromchild.readline()[0:-1] version = re.search(r"Linux (\d+)\.(\d+)\.(\d+)", strres) if not version: # Non-Linux: allow - return 1 + return 1 if (int(version.group(1)) > 2) or (int(version.group(2)) > 6) or ((int(version.group(1)) == 2) and (int(version.group(2)) == 6) and (int(version.group(3)) >= 8)): - return 1 + return 1 else: - return 0 + return 0 def collect_freespace(self): # Collects current free space self.cmd = self.growcmd + " -F " + self.device processi = popen2.Popen4(self.cmd) status = processi.wait() if not os.WIFEXITED(status): - raise DVDError(0, "growisofs process did not exit correctly.") + raise DVDError(0, "growisofs process did not exit correctly.") result = processi.fromchild.read() if os.WEXITSTATUS(status) != 0: - if (os.WEXITSTATUS(status) & 0x7F) == errno.ENOSPC: - # Kludge to force dvd-handler to return a free space of 0 - self.next_session = 1 - self.capacity = 1 - self.freespace_collected = 1 - return - else: - raise DVDError(os.WEXITSTATUS(status), "growisofs returned with an error " + result + ". Please check your are using a patched version of dvd+rw-tools.") + if (os.WEXITSTATUS(status) & 0x7F) == errno.ENOSPC: + # Kludge to force dvd-handler to return a free space of 0 + self.next_session = 1 + self.capacity = 1 + self.freespace_collected = 1 + return + else: + raise DVDError(os.WEXITSTATUS(status), "growisofs returned with an error " + result + ". Please check your are using a patched version of dvd+rw-tools.") next_sess = re.search(r"\snext_session=(\d+)\s", result, re.MULTILINE) capa = re.search(r"\scapacity=(\d+)\s", result, re.MULTILINE) if next_sess and capa: - self.next_session = long(next_sess.group(1)) - self.capacity = long(capa.group(1)) - - # testing cheat (emulate 4GB boundary at 100MB) - #if self.next_session > 100000000: - # self.capacity = self.next_session + self.next_session = long(next_sess.group(1)) + self.capacity = long(capa.group(1)) + + # testing cheat (emulate 4GB boundary at 100MB) + #if self.next_session > 100000000: + # self.capacity = self.next_session else: - raise DVDError(0, "Cannot get next_session and capacity from growisofs.\nReturned: " + result) + raise DVDError(0, "Cannot get next_session and capacity from growisofs.\nReturned: " + result) self.freespace_collected = 1 return @@ -204,10 +203,10 @@ class disk: processi = popen2.Popen4(cmd) status = processi.wait() if not os.WIFEXITED(status): - raise DVDError(0, self.dvdrwmediainfo + " process did not exit correctly.") + raise DVDError(0, self.dvdrwmediainfo + " process did not exit correctly.") if os.WEXITSTATUS(status) != 0: - raise DVDError(0, "Cannot get media info from " + self.dvdrwmediainfo) - return + raise DVDError(0, "Cannot get media info from " + self.dvdrwmediainfo) + return result = processi.fromchild.read() hardware = re.search(r"INQUIRY:\s+(.*)\n", result, re.MULTILINE) @@ -216,23 +215,23 @@ class disk: status = re.search(r"\sDisc status:\s+(.*)\n", result, re.MULTILINE) if hardware: - self.hardwaredevice = hardware.group(1) + self.hardwaredevice = hardware.group(1) if mediatype: - self.disktype = mediatype.group(2) + self.disktype = mediatype.group(2) else: - raise DVDError(0, "Media type not found in " + self.dvdrwmediainfo + " output") + raise DVDError(0, "Media type not found in " + self.dvdrwmediainfo + " output") if self.disktype == "DVD-RW": - if mediamode: - self.diskmode = mediamode.group(1) - else: - raise DVDError(0, "Media mode not found for DVD-RW in " + self.dvdrwmediainfo + " output") + if mediamode: + self.diskmode = mediamode.group(1) + else: + raise DVDError(0, "Media mode not found for DVD-RW in " + self.dvdrwmediainfo + " output") if status: - self.diskstatus = status.group(1) + self.diskstatus = status.group(1) else: - raise DVDError(0, "Disc status not found in " + self.dvdrwmediainfo + " output") + raise DVDError(0, "Disc status not found in " + self.dvdrwmediainfo + " output") self.mediumtype_collected = 1 @@ -240,76 +239,76 @@ class disk: def is_empty(self): if not self.freespace_collected: - self.collect_freespace(); + self.collect_freespace(); return 0 == self.next_session def is_RW(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return "DVD-RW" == self.disktype or "DVD+RW" == self.disktype or "DVD-RAM" == self.disktype def is_plus_RW(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return "DVD+RW" == self.disktype def is_minus_RW(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return "DVD-RW" == self.disktype def is_restricted_overwrite(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return self.diskmode == "Restricted Overwrite" def is_blank(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return self.diskstatus == "blank" def free(self): if not self.freespace_collected: - self.collect_freespace(); + self.collect_freespace(); fr = self.capacity-self.next_session-self.margin if fr < 0: - return 0 + return 0 else: - return fr + return fr def term_handler(self, signum, frame): print 'dvd-handler: Signal term_handler called with signal', signum if self.pid != 0: - print "dvd-handler: Sending SIGTERM to pid", self.pid - os.kill(self.pid, signal.SIGTERM) - time.sleep(10) - print "dvd-handler: Sending SIGKILL to pid", self.pid - os.kill(self.pid, signal.SIGKILL) - sys.exit(1) + print "dvd-handler: Sending SIGTERM to pid", self.pid + os.kill(self.pid, signal.SIGTERM) + time.sleep(10) + print "dvd-handler: Sending SIGKILL to pid", self.pid + os.kill(self.pid, signal.SIGKILL) + sys.exit(1) def write(self, newvol, partfile): # Blank DVD+RW when there is no data on it if newvol and self.is_plus_RW() and self.is_blank(): - print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs." - self.blank() - print "Done, now writing the part file." + print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs." + self.blank() + print "Done, now writing the part file." if newvol and self.is_minus_RW() and (not self.is_restricted_overwrite()): - print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite" - self.reformat_minus_RW() - print "Done, now writing the part file." + print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite" + self.reformat_minus_RW() + print "Done, now writing the part file." cmd = self.growcmd + self.growparams if newvol: - # Ignore any existing iso9660 filesystem - used for truncate - if newvol == 2: - cmd += " -use-the-force-luke=tty" - cmd += " -Z " + # Ignore any existing iso9660 filesystem - used for truncate + if newvol == 2: + cmd += " -use-the-force-luke=tty" + cmd += " -Z " else: - cmd += " -M " + cmd += " -M " cmd += self.device + " " + str(partfile) print "Running " + cmd oldsig = signal.signal(signal.SIGTERM, self.term_handler) @@ -317,40 +316,40 @@ class disk: self.pid = proc.pid status = proc.poll() while status == -1: - line = proc.fromchild.readline() - while len(line) > 0: - print line, - line = proc.fromchild.readline() - time.sleep(1) - status = proc.poll() + line = proc.fromchild.readline() + while len(line) > 0: + print line, + line = proc.fromchild.readline() + time.sleep(1) + status = proc.poll() self.pid = 0 print signal.signal(signal.SIGTERM, oldsig) if not os.WIFEXITED(status): - raise DVDError(0, cmd + " process did not exit correctly, signal/status " + str(status)) + raise DVDError(0, cmd + " process did not exit correctly, signal/status " + str(status)) if os.WEXITSTATUS(status) != 0: - raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) + raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) def prepare(self): if not self.is_RW(): - raise DVDError(0, "I won't prepare a non-rewritable medium") + raise DVDError(0, "I won't prepare a non-rewritable medium") # Blank DVD+RW when there is no data on it if self.is_plus_RW() and self.is_blank(): - print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs." - self.blank() - return # It has been completely blanked: Medium is ready to be used by Bacula + print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs." + self.blank() + return # It has been completely blanked: Medium is ready to be used by Bacula if self.is_minus_RW() and (not self.is_restricted_overwrite()): - print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite" - self.reformat_minus_RW() - return # Reformated: Medium is ready to be used by Bacula + print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite" + self.reformat_minus_RW() + return # Reformated: Medium is ready to be used by Bacula # TODO: Check if /dev/fd/0 and /dev/zero exists, otherwise, run self.blank() if not os.path.exists("/dev/fd/0") or not os.path.exists("/dev/zero"): - print "/dev/fd/0 or /dev/zero doesn't exist, blank the medium completely." - self.blank() - return + print "/dev/fd/0 or /dev/zero doesn't exist, blank the medium completely." + self.blank() + return cmd = self.dd + " if=/dev/zero bs=1024 count=512 | " + self.growcmd + " -Z " + self.device + "=/dev/fd/0" print "Running " + cmd @@ -359,17 +358,17 @@ class disk: self.pid = proc.pid status = proc.poll() while status == -1: - line = proc.fromchild.readline() - while len(line) > 0: - print line, - line = proc.fromchild.readline() - time.sleep(1) - status = proc.poll() + line = proc.fromchild.readline() + while len(line) > 0: + print line, + line = proc.fromchild.readline() + time.sleep(1) + status = proc.poll() self.pid = 0 print signal.signal(signal.SIGTERM, oldsig) if os.WEXITSTATUS(status) != 0: - raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) + raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) def blank(self): cmd = self.growcmd + " -Z " + self.device + "=/dev/zero" @@ -379,17 +378,17 @@ class disk: self.pid = proc.pid status = proc.poll() while status == -1: - line = proc.fromchild.readline() - while len(line) > 0: - print line, - line = proc.fromchild.readline() - time.sleep(1) - status = proc.poll() + line = proc.fromchild.readline() + while len(line) > 0: + print line, + line = proc.fromchild.readline() + time.sleep(1) + status = proc.poll() self.pid = 0 print signal.signal(signal.SIGTERM, oldsig) if os.WEXITSTATUS(status) != 0: - raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) + raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) def reformat_minus_RW(self): cmd = self.dvdrwformat + " -force " + self.device @@ -399,17 +398,17 @@ class disk: self.pid = proc.pid status = proc.poll() while status == -1: - line = proc.fromchild.readline() - while len(line) > 0: - print line, - line = proc.fromchild.readline() - time.sleep(1) - status = proc.poll() + line = proc.fromchild.readline() + while len(line) > 0: + print line, + line = proc.fromchild.readline() + time.sleep(1) + status = proc.poll() self.pid = 0 print signal.signal(signal.SIGTERM, oldsig) if os.WEXITSTATUS(status) != 0: - raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) + raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) # class disk ends here. @@ -418,7 +417,7 @@ class DVDError(Exception): self.errno = errno self.value = value if self.value[-1] == '\n': - self.value = self.value[0:-1] + self.value = self.value[0:-1] def __str__(self): return str(self.value) + " || errno = " + str(self.errno) + " (" + os.strerror(self.errno & 0x7F) + ")" @@ -435,19 +434,19 @@ dvd-handler DEVICE prepare where DEVICE is a device name like /dev/sr0 or /dev/dvd. Operations: -test Scan the device and report the information found. - This operation needs no further arguments. -free Scan the device and report the available space. -write Write a part file to disk. - This operation needs two additional arguments. - The first indicates to append (0), restart the - disk (1) or restart existing disk (2). The second - is the file to write. +test Scan the device and report the information found. + This operation needs no further arguments. +free Scan the device and report the available space. +write Write a part file to disk. + This operation needs two additional arguments. + The first indicates to append (0), restart the + disk (1) or restart existing disk (2). The second + is the file to write. prepare Prepare a DVD+/-RW for being used by Bacula. - Note: This is only useful if you already have some - non-Bacula data on a medium, and you want to use - it with Bacula. Don't run this on blank media, it - is useless. + Note: This is only useful if you already have some + non-Bacula data on a medium, and you want to use + it with Bacula. Don't run this on blank media, it + is useless. """ sys.exit(1) @@ -459,31 +458,31 @@ dvd = disk(sys.argv[1]) if "free" == sys.argv[2]: if len(sys.argv) == 3: try: - free = dvd.free() + free = dvd.free() except DVDError, e: - if e.errno != 0: - print -e.errno - else: - print errno.EPIPE - print str(e) + if e.errno != 0: + print -e.errno + else: + print errno.EPIPE + print str(e) else: - print free - print "No Error reported." + print free + print "No Error reported." else: print "Wrong number of arguments for free operation. Wanted 3 got", len(sys.argv) usage() elif "prepare" == sys.argv[2]: if len(sys.argv) == 3: try: - dvd.prepare() + dvd.prepare() except DVDError, e: - print "Error while preparing medium: ", str(e) - if e.errno != 0: - sys.exit(e.errno & 0x7F) - else: - sys.exit(errno.EPIPE) + print "Error while preparing medium: ", str(e) + if e.errno != 0: + sys.exit(e.errno & 0x7F) + else: + sys.exit(errno.EPIPE) else: - print "Medium prepared successfully." + print "Medium prepared successfully." else: print "Wrong number of arguments for prepare operation. Wanted 3 got", len(sys.argv) usage() @@ -497,15 +496,15 @@ elif "test" == sys.argv[2]: elif "write" == sys.argv[2]: if len(sys.argv) == 5: try: - dvd.write(long(sys.argv[3]), sys.argv[4]) + dvd.write(long(sys.argv[3]), sys.argv[4]) except DVDError, e: - print "Error while writing part file: ", str(e) - if e.errno != 0: - sys.exit(e.errno & 0x7F) - else: - sys.exit(errno.EPIPE) + print "Error while writing part file: ", str(e) + if e.errno != 0: + sys.exit(e.errno & 0x7F) + else: + sys.exit(errno.EPIPE) else: - print "Part file " + sys.argv[4] + " successfully written to disk." + print "Part file " + sys.argv[4] + " successfully written to disk." else: print "Wrong number of arguments for write operation. Wanted 5 got", len(sys.argv) usage() diff --git a/bacula/scripts/dvd-simulator.in b/bacula/scripts/dvd-simulator.in index a3033f0255..75bc5d2dd2 100644 --- a/bacula/scripts/dvd-simulator.in +++ b/bacula/scripts/dvd-simulator.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -28,27 +27,27 @@ # operations used by Bacula: # # free (no arguments) -# Scan the device and report the available space. +# Scan the device and report the available space. # # write op filename -# Write a part file to disk. -# This operation needs two additional arguments. -# The first (op) indicates to -# 0 -- append -# 1 -- first write to a blank disk -# 2 -- blank or truncate a disk +# Write a part file to disk. +# This operation needs two additional arguments. +# The first (op) indicates to +# 0 -- append +# 1 -- first write to a blank disk +# 2 -- blank or truncate a disk # -# The second is the filename to write +# The second is the filename to write # # operations available but not used by Bacula: # # test Scan the device and report the information found. -# This operation needs no further arguments. +# This operation needs no further arguments. # prepare Prepare a DVD+/-RW for being used by Bacula. -# Note: This is only useful if you already have some -# non-Bacula data on a medium, and you want to use -# it with Bacula. Don't run this on blank media, it -# is useless. +# Note: This is only useful if you already have some +# non-Bacula data on a medium, and you want to use +# it with Bacula. Don't run this on blank media, it +# is useless. # # # in case of operation ``free'' returns: @@ -92,23 +91,23 @@ class disk: # dvd-writepart doesn't not always need to know the free space). # # The following methods are implemented: -# __init__ we need that... -# __repr__ this seems to be a good idea to have. -# Quite minimalistic implementation, though. -# __str__ For casts to string. Return the current disk information -# is_empty Returns TRUE if the disk is empty, blank... this needs more -# work, especially concerning non-RW media and blank vs. no -# filesystem considerations. Here, we should also look for -# other filesystems - probably we don't want to silently -# overwrite UDF or ext2 or anything not mentioned in fstab... -# (NB: I don't think it is a problem) -# free Returns the available free space. -# write Writes one part file to disk, either starting a new file -# system on disk, or appending to it. -# This method should also prepare a blank disk so that a -# certain part of the disk is used to allow detection of a -# used disk by all / more disk drives. -# blank Blank the device +# __init__ we need that... +# __repr__ this seems to be a good idea to have. +# Quite minimalistic implementation, though. +# __str__ For casts to string. Return the current disk information +# is_empty Returns TRUE if the disk is empty, blank... this needs more +# work, especially concerning non-RW media and blank vs. no +# filesystem considerations. Here, we should also look for +# other filesystems - probably we don't want to silently +# overwrite UDF or ext2 or anything not mentioned in fstab... +# (NB: I don't think it is a problem) +# free Returns the available free space. +# write Writes one part file to disk, either starting a new file +# system on disk, or appending to it. +# This method should also prepare a blank disk so that a +# certain part of the disk is used to allow detection of a +# used disk by all / more disk drives. +# blank Blank the device # ############################################################################### def __init__(self, devicename): @@ -128,10 +127,10 @@ class disk: self.growcmd += " -quiet" if self.is4gbsupported(): - self.growcmd += " -use-the-force-luke=4gms" + self.growcmd += " -use-the-force-luke=4gms" self.growparams = " -A 'Bacula Data' -input-charset=default -iso-level 3 -pad " + \ - "-p 'dvd-handler / growisofs' -sysid 'BACULADATA' -R" + "-p 'dvd-handler / growisofs' -sysid 'BACULADATA' -R" return @@ -140,9 +139,9 @@ class disk: def __str__(self): if not self.freespace_collected: - self.collect_freespace(); + self.collect_freespace(); if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); self.me = "Class disk, initialized with device '" + self.device + "'\n" self.me += "type = '" + self.disktype + "' mode='" + self.diskmode + "' status = '" + self.diskstatus + "'\n" @@ -156,18 +155,18 @@ class disk: processi = popen2.Popen4("uname -s -r") status = processi.wait() if not os.WIFEXITED(status): - return 1 + return 1 if os.WEXITSTATUS(status) != 0: - return 1 + return 1 strres = processi.fromchild.readline()[0:-1] version = re.search(r"Linux (\d+)\.(\d+)\.(\d+)", strres) if not version: # Non-Linux: allow - return 1 + return 1 if (int(version.group(1)) > 2) or (int(version.group(2)) > 6) or ((int(version.group(1)) == 2) and (int(version.group(2)) == 6) and (int(version.group(3)) >= 8)): - return 1 + return 1 else: - return 0 + return 0 def collect_freespace(self): # Collects current free space self.next_session = 0 @@ -175,19 +174,19 @@ class disk: self.freespace_collected = 1 cmd = "du -sb " + self.device - processi = popen2.Popen4(cmd) + processi = popen2.Popen4(cmd) status = processi.wait() if not os.WIFEXITED(status): - return 1; + return 1; if os.WEXITSTATUS(status) != 0: - return 1; + return 1; result = processi.fromchild.read() used = re.search(r"(\d+)\s", result, re.MULTILINE) self.capacity = self.maxcapacity - long(used.group(1)) if self.capacity < 0: - self.capacity = 0 + self.capacity = 0 return 0 @@ -197,10 +196,10 @@ class disk: processi = popen2.Popen4(cmd) status = processi.wait() if not os.WIFEXITED(status): - raise DVDError(0, self.dvdrwmediainfo + " process did not exit correctly.") + raise DVDError(0, self.dvdrwmediainfo + " process did not exit correctly.") if os.WEXITSTATUS(status) != 0: - raise DVDError(0, "Cannot get media info from " + self.dvdrwmediainfo) - return + raise DVDError(0, "Cannot get media info from " + self.dvdrwmediainfo) + return result = processi.fromchild.read() hardware = re.search(r"INQUIRY:\s+(.*)\n", result, re.MULTILINE) @@ -209,23 +208,23 @@ class disk: status = re.search(r"\sDisc status:\s+(.*)\n", result, re.MULTILINE) if hardware: - self.hardwaredevice = hardware.group(1) + self.hardwaredevice = hardware.group(1) if mediatype: - self.disktype = mediatype.group(2) + self.disktype = mediatype.group(2) else: - raise DVDError(0, "Media type not found in " + self.dvdrwmediainfo + " output") + raise DVDError(0, "Media type not found in " + self.dvdrwmediainfo + " output") if self.disktype == "DVD-RW": - if mediamode: - self.diskmode = mediamode.group(1) - else: - raise DVDError(0, "Media mode not found for DVD-RW in " + self.dvdrwmediainfo + " output") + if mediamode: + self.diskmode = mediamode.group(1) + else: + raise DVDError(0, "Media mode not found for DVD-RW in " + self.dvdrwmediainfo + " output") if status: - self.diskstatus = status.group(1) + self.diskstatus = status.group(1) else: - raise DVDError(0, "Disc status not found in " + self.dvdrwmediainfo + " output") + raise DVDError(0, "Disc status not found in " + self.dvdrwmediainfo + " output") self.mediumtype_collected = 1 @@ -233,84 +232,84 @@ class disk: def is_empty(self): if not self.freespace_collected: - self.collect_freespace(); + self.collect_freespace(); return 0 == self.next_session def is_RW(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return "DVD-RW" == self.disktype or "DVD+RW" == self.disktype or "DVD-RAM" == self.disktype def is_plus_RW(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return "DVD+RW" == self.disktype def is_minus_RW(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return "DVD-RW" == self.disktype def is_restricted_overwrite(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return self.diskmode == "Restricted Overwrite" def is_blank(self): if not self.mediumtype_collected: - self.collect_mediumtype(); + self.collect_mediumtype(); return self.diskstatus == "blank" def free(self): if not self.freespace_collected: - self.collect_freespace(); + self.collect_freespace(); fr = self.capacity-self.next_session-self.margin if fr < 0: - return 0 + return 0 else: - return fr + return fr def term_handler(self, signum, frame): print 'dvd-handler: Signal term_handler called with signal', signum if self.pid != 0: - print "dvd-handler: Sending SIGTERM to pid", self.pid - os.kill(self.pid, signal.SIGTERM) - time.sleep(10) - print "dvd-handler: Sending SIGKILL to pid", self.pid - os.kill(self.pid, signal.SIGKILL) - sys.exit(1) + print "dvd-handler: Sending SIGTERM to pid", self.pid + os.kill(self.pid, signal.SIGTERM) + time.sleep(10) + print "dvd-handler: Sending SIGKILL to pid", self.pid + os.kill(self.pid, signal.SIGKILL) + sys.exit(1) def write(self, newvol, partfile): if newvol: - print "Newvol", newvol - print "Zap everything ..." - os.system("rm -f "+self.device+"/*") + print "Newvol", newvol + print "Zap everything ..." + os.system("rm -f "+self.device+"/*") print "cp", partfile, self.device shutil.copy(partfile,self.device) def prepare(self): if not self.is_RW(): - raise DVDError(0, "I won't prepare a non-rewritable medium") + raise DVDError(0, "I won't prepare a non-rewritable medium") # Blank DVD+RW when there is no data on it if self.is_plus_RW() and self.is_blank(): - print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs." - self.blank() - return # It has been completely blanked: Medium is ready to be used by Bacula + print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs." + self.blank() + return # It has been completely blanked: Medium is ready to be used by Bacula if self.is_minus_RW() and (not self.is_restricted_overwrite()): - print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite" - self.reformat_minus_RW() - return # Reformated: Medium is ready to be used by Bacula + print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite" + self.reformat_minus_RW() + return # Reformated: Medium is ready to be used by Bacula # TODO: Check if /dev/fd/0 and /dev/zero exists, otherwise, run self.blank() if not os.path.exists("/dev/fd/0") or not os.path.exists("/dev/zero"): - print "/dev/fd/0 or /dev/zero doesn't exist, blank the medium completely." - self.blank() - return + print "/dev/fd/0 or /dev/zero doesn't exist, blank the medium completely." + self.blank() + return cmd = self.dd + " if=/dev/zero bs=1024 count=512 | " + self.growcmd + " -Z " + self.device + "=/dev/fd/0" print "Running " + cmd @@ -319,17 +318,17 @@ class disk: self.pid = proc.pid status = proc.poll() while status == -1: - line = proc.fromchild.readline() - while len(line) > 0: - print line, - line = proc.fromchild.readline() - time.sleep(1) - status = proc.poll() + line = proc.fromchild.readline() + while len(line) > 0: + print line, + line = proc.fromchild.readline() + time.sleep(1) + status = proc.poll() self.pid = 0 print signal.signal(signal.SIGTERM, oldsig) if os.WEXITSTATUS(status) != 0: - raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) + raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) def blank(self): cmd = self.growcmd + " -Z " + self.device + "=/dev/zero" @@ -339,17 +338,17 @@ class disk: self.pid = proc.pid status = proc.poll() while status == -1: - line = proc.fromchild.readline() - while len(line) > 0: - print line, - line = proc.fromchild.readline() - time.sleep(1) - status = proc.poll() + line = proc.fromchild.readline() + while len(line) > 0: + print line, + line = proc.fromchild.readline() + time.sleep(1) + status = proc.poll() self.pid = 0 print signal.signal(signal.SIGTERM, oldsig) if os.WEXITSTATUS(status) != 0: - raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) + raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) def reformat_minus_RW(self): cmd = self.dvdrwformat + " -force " + self.device @@ -359,17 +358,17 @@ class disk: self.pid = proc.pid status = proc.poll() while status == -1: - line = proc.fromchild.readline() - while len(line) > 0: - print line, - line = proc.fromchild.readline() - time.sleep(1) - status = proc.poll() + line = proc.fromchild.readline() + while len(line) > 0: + print line, + line = proc.fromchild.readline() + time.sleep(1) + status = proc.poll() self.pid = 0 print signal.signal(signal.SIGTERM, oldsig) if os.WEXITSTATUS(status) != 0: - raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) + raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status)) # class disk ends here. @@ -378,7 +377,7 @@ class DVDError(Exception): self.errno = errno self.value = value if self.value[-1] == '\n': - self.value = self.value[0:-1] + self.value = self.value[0:-1] def __str__(self): return str(self.value) + " || errno = " + str(self.errno) + " (" + os.strerror(self.errno & 0x7F) + ")" @@ -395,19 +394,19 @@ dvd-handler DEVICE blank where DEVICE is a device name like /dev/sr0 or /dev/dvd. Operations: -test Scan the device and report the information found. - This operation needs no further arguments. -free Scan the device and report the available space. -write Write a part file to disk. - This operation needs two additional arguments. - The first indicates to append (0), restart the - disk (1) or restart existing disk (2). The second - is the file to write. +test Scan the device and report the information found. + This operation needs no further arguments. +free Scan the device and report the available space. +write Write a part file to disk. + This operation needs two additional arguments. + The first indicates to append (0), restart the + disk (1) or restart existing disk (2). The second + is the file to write. prepare Prepare a DVD+/-RW for being used by Bacula. - Note: This is only useful if you already have some - non-Bacula data on a medium, and you want to use - it with Bacula. Don't run this on blank media, it - is useless. + Note: This is only useful if you already have some + non-Bacula data on a medium, and you want to use + it with Bacula. Don't run this on blank media, it + is useless. """ sys.exit(1) @@ -419,16 +418,16 @@ dvd = disk(sys.argv[1]) if "free" == sys.argv[2]: if len(sys.argv) == 3: try: - free = dvd.free() + free = dvd.free() except DVDError, e: - if e.errno != 0: - print -e.errno - else: - print errno.EPIPE - print str(e) + if e.errno != 0: + print -e.errno + else: + print errno.EPIPE + print str(e) else: - print free - print "No Error reported." + print free + print "No Error reported." else: print "Wrong number of arguments for free operation. Wanted 3 got", len(sys.argv) print sys.argv[1], sys.argv[2], sys.argv[3] @@ -436,15 +435,15 @@ if "free" == sys.argv[2]: elif "prepare" == sys.argv[2]: if len(sys.argv) == 3: try: - dvd.prepare() + dvd.prepare() except DVDError, e: - print "Error while preparing medium: ", str(e) - if e.errno != 0: - sys.exit(e.errno & 0x7F) - else: - sys.exit(errno.EPIPE) + print "Error while preparing medium: ", str(e) + if e.errno != 0: + sys.exit(e.errno & 0x7F) + else: + sys.exit(errno.EPIPE) else: - print "Medium prepared successfully." + print "Medium prepared successfully." else: print "Wrong number of arguments for prepare operation." usage() @@ -458,15 +457,15 @@ elif "test" == sys.argv[2]: elif "write" == sys.argv[2]: if len(sys.argv) == 5: try: - dvd.write(long(sys.argv[3]), sys.argv[4]) + dvd.write(long(sys.argv[3]), sys.argv[4]) except DVDError, e: - print "Error while writing part file: ", str(e) - if e.errno != 0: - sys.exit(e.errno & 0x7F) - else: - sys.exit(errno.EPIPE) + print "Error while writing part file: ", str(e) + if e.errno != 0: + sys.exit(e.errno & 0x7F) + else: + sys.exit(errno.EPIPE) else: - print "Part file " + sys.argv[4] + " successfully written to disk." + print "Part file " + sys.argv[4] + " successfully written to disk." else: print "Wrong number of arguments for write operation." usage() diff --git a/bacula/scripts/logrotate.in b/bacula/scripts/logrotate.in index a06db840e4..825666fd15 100644 --- a/bacula/scripts/logrotate.in +++ b/bacula/scripts/logrotate.in @@ -1,5 +1,5 @@ # -# Copyright (C) 2000-2015 Kern Sibbald +# Copyright (C) 2000-2016 Kern Sibbald # License: BSD 2-Clause; see file LICENSE-FOSS # # diff --git a/bacula/scripts/mtx-changer.in b/bacula/scripts/mtx-changer.in index 9c7111d5cf..f1dc2d3141 100644 --- a/bacula/scripts/mtx-changer.in +++ b/bacula/scripts/mtx-changer.in @@ -2,8 +2,7 @@ # # Bacula(R) - The Network Backup Solution # -# Copyright (C) 2000-2015 Kern Sibbald -# Copyright (C) 2000-2014 Free Software Foundation Europe e.V. +# Copyright (C) 2000-2016 Kern Sibbald # # The original author of Bacula is Kern Sibbald, with contributions # from many others, a complete list can be found in the file AUTHORS. @@ -27,7 +26,7 @@ # in come cases, not all are used. # # mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index" -# $1 $2 $3 $4 $5 +# $1 $2 $3 $4 $5 # # for example: # @@ -38,13 +37,13 @@ # is /dev/nst0. # # The commands are: -# Command Function -# unload unload a given slot -# load load a given slot -# loaded which slot is loaded? -# list list Volume names (requires barcode reader) -# slots how many slots total? -# listall list all info +# Command Function +# unload unload a given slot +# load load a given slot +# loaded which slot is loaded? +# list list Volume names (requires barcode reader) +# slots how many slots total? +# listall list all info # transfer # # Slots are numbered from 1 ... @@ -89,7 +88,7 @@ fi dbgfile="@working_dir@/mtx.log" debug() { if test -f $dbgfile -a ${debug_level} -ge $1; then - echo "`date +%m%d-%H:%M:%S.%N|cut -c1-16` ${chgr_id} $2" >> $dbgfile + echo "`date +%m%d-%H:%M:%S.%N|cut -c1-16` ${chgr_id} $2" >> $dbgfile fi } @@ -102,8 +101,8 @@ make_temp_file() { if test x${TMPFILE} = x; then TMPFILE="@working_dir@/mtx.$$" if test -f ${TMPFILE}; then - echo "ERROR: Temp file security problem on: ${TMPFILE}" - exit 1 + echo "ERROR: Temp file security problem on: ${TMPFILE}" + exit 1 fi fi } @@ -124,8 +123,8 @@ make_err_file() { if test x${ERRFILE} = x; then ERRFILE="@working_dir@/mtx.err.$$" if test -f ${ERRFILE}; then - echo "ERROR: Temp file security problem on: ${ERRFILE}" - exit 1 + echo "ERROR: Temp file security problem on: ${ERRFILE}" + exit 1 fi fi } @@ -160,14 +159,14 @@ check_parm_count() { pCount=$1 pCountNeed=$2 if test $pCount -lt $pCountNeed; then - echo "ERROR: usage: mtx-changer ctl-device command [slot archive-device drive-index]" - echo " Insufficient number of arguments given." - if test $pCount -lt 2; then - echo " Mimimum usage is first two arguments ..." - else - echo " Command expected $pCountNeed arguments" - fi - exit 1 + echo "ERROR: usage: mtx-changer ctl-device command [slot archive-device drive-index]" + echo " Insufficient number of arguments given." + if test $pCount -lt 2; then + echo " Mimimum usage is first two arguments ..." + else + echo " Command expected $pCountNeed arguments" + fi + exit 1 fi } @@ -176,17 +175,17 @@ check_parm_count() { # case $2 in list|listall) - check_parm_count $# 2 - ;; + check_parm_count $# 2 + ;; slots) - check_parm_count $# 2 - ;; + check_parm_count $# 2 + ;; transfer) - check_parm_count $# 4 - ;; + check_parm_count $# 4 + ;; *) - check_parm_count $# 5 - ;; + check_parm_count $# 5 + ;; esac @@ -203,29 +202,29 @@ case $cmd in unload) if test ${offline} -eq 1 ; then - mt -f $device offline + mt -f $device offline fi if test ${offline_sleep} -ne 0 ; then - sleep ${offline_sleep} + sleep ${offline_sleep} fi make_err_file for i in 1 2 3 4 5 ; do - debug $idbglvl "Doing mtx -f $ctl unload slot=$slot drv=$drive" - ${MTX} -f $ctl unload $slot $drive 2>${ERRFILE} - rtn=$? - if test $rtn -eq 0 ; then - break - fi - grep "Error Code=" ${ERRFILE} 2>/dev/null 1>/dev/null - if test $? -ne 0 ; then - break - fi - sleep $i + debug $idbglvl "Doing mtx -f $ctl unload slot=$slot drv=$drive" + ${MTX} -f $ctl unload $slot $drive 2>${ERRFILE} + rtn=$? + if test $rtn -eq 0 ; then + break + fi + grep "Error Code=" ${ERRFILE} 2>/dev/null 1>/dev/null + if test $? -ne 0 ; then + break + fi + sleep $i done cat ${ERRFILE} rm -f ${ERRFILE} >/dev/null 2>&1 if test $rtn -ne 0 ; then - debug $idbglvl "FAIL: mtx -f $ctl unload slot=$slot drv=$drive" + debug $idbglvl "FAIL: mtx -f $ctl unload slot=$slot drv=$drive" fi exit $rtn ;; @@ -233,26 +232,26 @@ case $cmd in load) make_err_file for i in 1 2 3 4 5 ; do - debug $idbglvl "Doing mtx -f $ctl load slot=$slot drv=$drive" - ${MTX} -f $ctl load $slot $drive 2>${ERRFILE} - rtn=$? - if test $rtn -eq 0 ; then - break - fi - grep "Error Code=" ${ERRFILE} 2>/dev/null 1>/dev/null - if test $? -ne 0 ; then - break - fi - sleep $i + debug $idbglvl "Doing mtx -f $ctl load slot=$slot drv=$drive" + ${MTX} -f $ctl load $slot $drive 2>${ERRFILE} + rtn=$? + if test $rtn -eq 0 ; then + break + fi + grep "Error Code=" ${ERRFILE} 2>/dev/null 1>/dev/null + if test $? -ne 0 ; then + break + fi + sleep $i done if test ${load_sleep} -ne 0 ; then - sleep ${load_sleep} + sleep ${load_sleep} fi wait_for_drive $device cat ${ERRFILE} rm -f ${ERRFILE} >/dev/null 2>&1 if test $rtn -ne 0 ; then - debug $idbglvl "FAIL: mtx -f $ctl load slot=$slot drv=$drive" + debug $idbglvl "FAIL: mtx -f $ctl load slot=$slot drv=$drive" fi exit $rtn ;; @@ -260,43 +259,43 @@ case $cmd in list) make_temp_file if test ${inventory} -ne 0 ; then - ${MTX} -f $ctl inventory + ${MTX} -f $ctl inventory fi debug $dbglvl "Doing mtx -f $ctl list" ${MTX} -f $ctl status >${TMPFILE} rtn=$? if test ${vxa_packetloader} -ne 0 ; then - cat ${TMPFILE} | grep " *Storage Element [0-9]*:.*Full" | sed "s/ Storage Element //" | sed "s/Full :VolumeTag=//" + cat ${TMPFILE} | grep " *Storage Element [0-9]*:.*Full" | sed "s/ Storage Element //" | sed "s/Full :VolumeTag=//" else - cat ${TMPFILE} | grep " Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//" + cat ${TMPFILE} | grep " Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//" fi cat ${TMPFILE} | grep "^Data Transfer Element [0-9]*:Full (Storage Element [0-9]" | awk '{printf "%s:%s\n",$7,$10}' rm -f ${TMPFILE} >/dev/null 2>&1 if test $rtn -ne 0 ; then - debug $idbglvl "FAIL: mtx -f $ctl list" + debug $idbglvl "FAIL: mtx -f $ctl list" fi exit $rtn ;; listall) -# Drive content: D:Drive num:F:Slot loaded:Volume Name +# Drive content: D:Drive num:F:Slot loaded:Volume Name # D:0:F:2:vol2 or D:Drive num:E # D:1:F:42:vol42 # D:3:E # # Slot content: -# S:1:F:vol1 S:Slot num:F:Volume Name -# S:2:E or S:Slot num:E +# S:1:F:vol1 S:Slot num:F:Volume Name +# S:2:E or S:Slot num:E # S:3:F:vol4 # # Import/Export tray slots: -# I:10:F:vol10 I:Slot num:F:Volume Name -# I:11:E or I:Slot num:E +# I:10:F:vol10 I:Slot num:F:Volume Name +# I:11:E or I:Slot num:E # I:12:F:vol40 make_temp_file if test ${inventory} -ne 0 ; then - ${MTX} -f $ctl inventory + ${MTX} -f $ctl inventory fi debug $dbglvl "Doing mtx -f $ctl -- to list all" ${MTX} -f $ctl status >${TMPFILE} @@ -324,7 +323,7 @@ case $cmd in ${MTX} -f $ctl transfer $slot $slotdest rtn=$? if test $rtn -ne 0 ; then - debug $idbglvl "FAIL: mtx -f $ctl transfer from=$slot to=$slotdest" + debug $idbglvl "FAIL: mtx -f $ctl transfer from=$slot to=$slotdest" fi exit $rtn ;; @@ -338,7 +337,7 @@ case $cmd in cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}" rm -f ${TMPFILE} >/dev/null 2>&1 if test $rtn -ne 0 ; then - debug $idbglvl "FAIL: mtx -f $ctl loaded drv=$drive" + debug $idbglvl "FAIL: mtx -f $ctl loaded drv=$drive" fi exit $rtn ;; @@ -348,7 +347,7 @@ case $cmd in ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$5}" rtn=$? if test $rtn -ne 0 ; then - debug $idbglvl "FAIL: mtx -f $ctl slots" + debug $idbglvl "FAIL: mtx -f $ctl slots" fi ;; esac -- 2.39.5