Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Jul 2007 10:04:31 +0200
From:      Roland Smith <>
To:        L Goodwin <>
Subject:   Re: Correct way to use dump to backup a Samba share
Message-ID:  <>
In-Reply-To: <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Jul 07, 2007 at 06:42:20PM -0700, L Goodwin wrote:
> I have a Samba share on a software RAID 1 array (using
> gmirror) that I need to backup. I want to create a
> shell script that does a level 0 backup every time to
> (alternately) one of two USB drives. I plan to have
> only ONE USB drive connected at a time.=20
> I want the script to mount the drive, perform the
> backup, then unmount the drive so that it is ready for
> someone who knows zip about computers to safely remove
> and take offsite.=20
> Here are the steps I have for the script.
> Is this all I need to do? Do I need any error handling
> logic? THANKS!

> # Mount the backup drive:
> mount /dev/usb0
> # Create the backup:
> /sbin/dump -0u -f /dev/usb0 /sambavol
> # Unmount the backup drive:
> umount /dev/usb0

The following is a rough outline of what you should do;
-------------- shell-script --------------
# The following assumes that the USB mass-storage device is formatted
# with a UFS filesystem

# Only root can perform dumps.
if [ $(id -u) -ne 0 ]; then
    echo "Only root can perform dumps. Exiting."
    exit 1

# First, check if the target directory exists
if [ ! -d $DDIR ]; then
    echo "The $DDIR directory doesn't exist. Exiting."
    exit 1
# Then check if it is already mounted
if mount|grep $DDDIR >/dev/null; then
   echo "The $DDIR directory is already in use. Exiting"
    exit 1

# Check if the device to dump to exists;
if [ ! -c $DEV ]; then
    echo "The $DEV device doesn't exist. Exiting."
    exit 1
# Check if the device is already mounted
if mount|grep $DEV >/dev/null; then
   echo "The $DEV device is already mounted. Exiting"
   exit 1

DFLAGS=3D"-0 -u -f"
# Check if the filesystem that is to be dumped exists.
if [ ! -d $SRC ]; then
    echo "The $SRC directory doesn't exist. Exiting."
    exit 1
# Now check if it is mounted
if mount -t ufs|grep $SRC; then

# Mount the USB device.
if ! mount $DEV $DDIR; then
   "Mounting the USB disk failed. Exiting"
   exit 1

DATE=3D$(date "+%Y%m%d")
# Perfrom the dump, assuming that the filesystem is live.
dump $DFLAGS ${DDIR}/sambavol-0-${DATE}.dump $SRC

umount $DDIR
-------------- shell-script --------------

Of course, you have to remove old dumps once in a while, lest you run
out of disk space.

Depending on the contents of the samba share, it might be worthwhile to
compress the dump with gzip;

# Perfrom the dump,=20
dump $DFLAGS - $SRC|gzip >${DDIR}/sambavol-0-${DATE}.gz

[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v2.0.4 (FreeBSD)



Want to link to this message? Use this URL: <>