From owner-freebsd-questions@FreeBSD.ORG Sun Jul 8 08:04:34 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0568516A41F for ; Sun, 8 Jul 2007 08:04:34 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from smtp-vbr1.xs4all.nl (smtp-vbr1.xs4all.nl [194.109.24.21]) by mx1.freebsd.org (Postfix) with ESMTP id A89B013C455 for ; Sun, 8 Jul 2007 08:04:33 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from slackbox.xs4all.nl (slackbox.xs4all.nl [213.84.242.160]) by smtp-vbr1.xs4all.nl (8.13.8/8.13.8) with ESMTP id l6884Vqp023210; Sun, 8 Jul 2007 10:04:32 +0200 (CEST) (envelope-from rsmith@xs4all.nl) Received: by slackbox.xs4all.nl (Postfix, from userid 1001) id B59C1B854; Sun, 8 Jul 2007 10:04:31 +0200 (CEST) Date: Sun, 8 Jul 2007 10:04:31 +0200 From: Roland Smith To: L Goodwin Message-ID: <20070708080431.GA17250@slackbox.xs4all.nl> Mail-Followup-To: L Goodwin , freebsd-questions@freebsd.org References: <543595.21864.qm@web58112.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="WIyZ46R2i8wDzkSu" Content-Disposition: inline In-Reply-To: <543595.21864.qm@web58112.mail.re3.yahoo.com> X-GPG-Fingerprint: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 X-GPG-Key: http://www.xs4all.nl/~rsmith/pubkey.txt X-GPG-Notice: If this message is not signed, don't assume I sent it! User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: by XS4ALL Virus Scanner Cc: freebsd-questions@freebsd.org Subject: Re: Correct way to use dump to backup a Samba share X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jul 2007 08:04:34 -0000 --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--