Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Jul 2007 10:04:31 +0200
From:      Roland Smith <rsmith@xs4all.nl>
To:        L Goodwin <xrayv19@yahoo.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Correct way to use dump to backup a Samba share
Message-ID:  <20070708080431.GA17250@slackbox.xs4all.nl>
In-Reply-To: <543595.21864.qm@web58112.mail.re3.yahoo.com>
References:  <543595.21864.qm@web58112.mail.re3.yahoo.com>

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

--WIyZ46R2i8wDzkSu
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
>=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
>=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
>=20
> # Create the backup:
> /sbin/dump -0u -f /dev/usb0 /sambavol
>=20
> # Unmount the backup drive:
> umount /dev/usb0

The following is a rough outline of what you should do;
-------------- shell-script --------------
#!/bin/sh
# 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
fi

DDIR=3D/mnt/root
# First, check if the target directory exists
if [ ! -d $DDIR ]; then
    echo "The $DDIR directory doesn't exist. Exiting."
    exit 1
fi
# 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
fi

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

SRC=3D/sambavol
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
fi
# Now check if it is mounted
if mount -t ufs|grep $SRC; then
   DFLAGS=3D"-L "$DFLAGS
fi

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

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

Roland
--=20
R.F.Smith                                   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)

iD8DBQFGkJqPEnfvsMMhpyURAoJSAJ9X3sn74F5iIfYNoXgVJnRXtXTUhwCeO8W7
ybzs4SogmaLGUsB9+MC2meY=
=TUdK
-----END PGP SIGNATURE-----

--WIyZ46R2i8wDzkSu--



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20070708080431.GA17250>