Ger Apeldoorn wrote:
Hi Barry,
I dont know if Robert wants to use that approach, but it sure is what i'm
looking for.. So if you could tell us how you got your hal daemon to create
and mount your USB disks that would be great!
I am using Ubuntu btw.
Many thanks,
Ger.
Op vrijdag 24 maart 2006 00:33, schreef Barry L. Bond:
Hi Robert!
Das anyone has Scripts to mount these Harddisks and reports me errors it
they are not ready connected?
I use bacula to backup to two different USB hard disks, both of which
are attached to my computer, but only on one day each week. My schedule
is set to backup to one on Saturday and the other on Tuesday. (I do a
full on the first Saturday or Tuesday of the month, and a differential
thereafter.)
I suspect I will be able to help you on this.
A couple of questions, to help figure out what you want...
I don't exactly have scripts. I figured out how to get my hald (HAL
daemon) to create and mount my USB disks to two, different, paths. Then,
my bacula schedule has them backing up to that path, and if by some
chance, the pathlist isn't there, the backup fails. (This is what I
want.)
Questions for you... what operating system are you using? I'm using
Fedora Core 4 Linux, and I figured out how to get hald to recognize the
specific USB disk being powered on, and create the directory and mount the
USB disk to that pathlist. I can unmount the USB disk, and turn them off,
and hald removes the directory.
Would you be interested in the same, or a similar approach?
Barry
Hi Barry,
Here are the bash scripts I use to write my backups to USB removable
hard disks. They are seen as SCSI-disks.
I created a library with some functions:
vi USB_DVD_lib.sh :
#!/bin/bash
#
# script containing functions and definitions which can be used by other
scripts,
# making them more readable and avoiding duplication of code and settings
dvdwriter=/dev/hdb
dvdbackupspoolmountpoint=/dvdbackupspool
dvdwritermountpoint=/media/cdrecorder
WriteToDVD () {
lines=$@ # This function expects a space delimited list
containing file names of volumes to write to DVD
umount $dvdwritermountpoint
let "count=1"
for i in $lines ; do
if [ $count -le 1 ] ; then
# When creating a DVD with growisofs one needs
to use -Z the first time
echo "Writing first volume file" $count
growisofs -Z $dvdwriter -R -J /dvdbackupspool/$i
else
# and -M the for the next volume files
echo "Writing another volume file" $count
growisofs -M $dvdwriter -R -J /dvdbackupspool/$i
fi
let count="$count+1"
# sleep 5
ls -al $dvdwritermountpoint
sleep 3
done
}
ShowContentsOfSourceDirAndDVD () {
ls -al $dvdbackupspoolmountpoint
mount $dvdwritermountpoint
ls -al $dvdwritermountpoint
umount $dvdwritermountpoint
}
blank="Disc status: blank"
dvdstatus=na
DVDstatus () {
dvdstatus=`dvd+rw-mediainfo $dvdwriter 2> /dev/null | grep "Disc
status"`
}
#Define global variable to hold return value from function
freespace=
# Define function to determine free space on a mount point
FreeSpace () {
freespace=`df $path | grep $path | awk '{print $4}'`
echo $freespace
if [ 0 -ne `expr index "$freespace" %` ] ; then
freespace=`df $path | grep $path | awk '{print $3}'`
fi
}
#Define global variable to hold return value from function
padded=
# Define function to pad a number with spaces to the left for display
PadSpacesToLeft () {
stringtopad=$1
wantedlength=$2
while [ ${#stringtopad} -lt $wantedlength ]
do
stringtopad=" "$stringtopad
done
padded=$stringtopad
}
CreateMountPoints () {
echo " Creating mount points, if they don't exist"
if ! [ -d /mnt/usbdrv ] ; then
mkdir /mnt/usbdrv
fi
if ! [ -d /mnt/usbdrv/bacula ] ; then
mkdir /mnt/usbdrv/bacula
fi
if ! [ -d /mnt/usbdrv/misc ] ; then
mkdir /mnt/usbdrv/misc
fi
}
UnmountMountPointsRelatedToUSB () {
#unmount all mount points related to USB
echo " Making sure no USB devices are mounted"
umount /mnt/usbdrv
umount /mnt/usbdrv/bacula
umount /mnt/usbdrv/misc
umount /mnt/removable
umount /mnt/removable2
umount /mnt/removable3
umount /media/*
}
FindDeviceContainingVolume () {
volumename=$1
echo " Determining whether the right USB device containing our
USBVolume ($volumename) is present physically"
for i in sda sdb sdc sdd sde sdf sdg sdh sdi sdj; do
sd=$i"1"
echo " Trying with $sd"
mount /dev/$sd /mnt/usbdrv/bacula -t ext2
ls -al /mnt/usbdrv/bacula
if [ -f /mnt/usbdrv/bacula/$volumename ] ; then
found=/dev/$i
foundvol=$volumename
else
for vn in USBVolume0001 USBVolume0002 USBVolume0003; do
if [ -f /mnt/usbdrv/bacula/$vn ] ; then
found=/dev/$i
foundvol=$vn
fi
done
fi
umount /mnt/usbdrv/bacula
done
echo
echo " Found: $found containing $foundvol "
echo
}
And scripts that invoke those library functions which run as RunAfterJob
scripts
vi write_to_USB.sh :
#!/bin/bash
#
# shell script to finalize USB backup
#Source functions present in our library
. /etc/bacula/USB_DVD_lib.sh
volumename=$1
CreateMountPoints
UnmountMountPointsRelatedToUSB
#determine which /dev/sd? contains the right USBVolume for this backup
found=nothing
foundvol=
FindDeviceContainingVolume $volumename
if [ $found != nothing ] ; then
# mount /mnt/usbdrv/bacula and /mnt/usbdrv/misc on /dev/sd?1 and
/dev/sd?5 respectively
mount $found"1" /mnt/usbdrv/bacula -t ext2
mount $found"5" /mnt/usbdrv/misc -t vfat
# copy Ghost images of Windows system drives, the contents of
/etc/bacula/*
# and a text file with restore instructions to /mnt/usbdrv/misc
echo " Copying Ghost image of TOSFEB31 to /mnt/usbdrv/misc"
cp -v /mnt/Ghost/PROD/TOSFEB31/SYSTEM.GHO /mnt/usbdrv/misc
echo " Copying Ghost image of TOSFEB32 to /mnt/usbdrv/misc"
cp -v /mnt/Ghost/PROD/TOSFEB32/COFTF32.GHO /mnt/usbdrv/misc
echo " Copying /etc/bacula to /mnt/usbdrv/misc"
cp -Rfv /etc/bacula/ /mnt/usbdrv/misc
echo " Copying Restore instructions to /mnt/usbdrv/misc"
cp -v /etc/bacula/How_To_Restore.txt /mnt/usbdrv/misc
# copy the current USBVolume to /mnt/usbdrv/bacula overwriting the
previous volume file
echo
echo " Copying Bacula USB-volume to /mnt/usbdrv/bacula"
cp -fv /backupspool/$volumename /mnt/usbdrv/bacula
# give some feedback about what was done
echo
echo " Directory contents of /mnt/usbdrv/bacula"
ls -al /mnt/usbdrv/bacula
echo
echo " Directory contents of /mnt/usbdrv/misc"
ls -al /mnt/usbdrv/misc
# unmount /mnt/usbdrv/bacula and /mnt/usbdrv/misc
echo
echo " Unmounting /mnt/usbdrv/... mount points"
umount /mnt/usbdrv/bacula
umount /mnt/usbdrv/misc
else
# send emails if correct medium is not present
# /usr/sbin/smtp
echo "hello"
fi
# This is run as a RunAfterJob of the catalog backup. It already had a
RunAfterJob, so we execute that here
/etc/bacula/delete_catalog_backup
There is another script I run to check whether the (correct) device is
connected. I have three disks for three consecutive weeks.
vi USB_media.sh :
#!/bin/bash
#
# shell script to check which USB volume is connected.
#Source functions present in our library
. /etc/bacula/USB_DVD_lib.sh
volumename=$1
CreateMountPoints
UnmountMountPointsRelatedToUSB
#determine which /dev/sd? contains the right USBVolume for this backup
found=nothing
foundvol=empty
FindDeviceContainingVolume $volumename
echo $found
echo $foundvol
echo $volumename
if [ "$volumename" != "" ] ; then
if [ $foundvol != $volumename ] ; then
exit 1
else
exit 0
fi
fi
if [ $found != nothing ] ; then
exit 0
else
echo No external USB drive is connected! Please find out which drive
is needed and connect it.
if [ "$volumename" != "" ] ; then
echo This probably should be $volumename
fi
echo
echo
exit -1
fi
This has been up and running well for about 3 years now.
I hope this helps,
Jo
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users