From owner-freebsd-questions@FreeBSD.ORG Wed Nov 21 13:55:17 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07B4416A419 for ; Wed, 21 Nov 2007 13:55:17 +0000 (UTC) (envelope-from valerio.daelli@gmail.com) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.225]) by mx1.freebsd.org (Postfix) with ESMTP id B303013C4D3 for ; Wed, 21 Nov 2007 13:55:16 +0000 (UTC) (envelope-from valerio.daelli@gmail.com) Received: by nz-out-0506.google.com with SMTP id l8so1910968nzf for ; Wed, 21 Nov 2007 05:55:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=tX0P90cA/cleP2aOwXMZ4DDIrlovPPraAcZjQT13RoU=; b=JL+HohI3L7PukxNx+5vM9aF17hVczDgBPtIrjDU+pw6JDwIwBbmeOGwGHWiG2yOeriXgbw08mdgaAwajQYLMiheumYcA2oBfsmzOdYu2ErMsjKR3aPPEHLfK39eYV4xcwOMy2hBZdZ4+CdZj86nYxXFngcOSvgUBdaVAyiGMsjU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=N5v9zKRSBOsZlO3d/HSDSgV+kRt9oJcXFjjMP7SqIwjUTImgUj2fxpU3K7p71DlL9IeoHydAnNIxsw7BrG6cg3LrFZEVhBqzVbeoXnZDH2UxfCvUrJ2o/RO5ALwUAQeMFrehUS6YMt+VMSQDPX94QPu7uQaPNPW2rPktd+3gGLI= Received: by 10.142.52.9 with SMTP id z9mr1929838wfz.1195653305207; Wed, 21 Nov 2007 05:55:05 -0800 (PST) Received: by 10.142.81.18 with HTTP; Wed, 21 Nov 2007 05:55:05 -0800 (PST) Message-ID: <27dbfc8c0711210555h1a862f5drccb1a6f5bcb1a837@mail.gmail.com> Date: Wed, 21 Nov 2007 14:55:05 +0100 From: "Valerio Daelli" To: "=?ISO-8859-1?Q?Andreas_Wider=F8e_Andersen?=" , freebsd-questions In-Reply-To: <23ed14b80711210539w4bed1enc180f8e32ec76881@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <23ed14b80711210539w4bed1enc180f8e32ec76881@mail.gmail.com> Cc: Subject: Re: Need help with backup shell script 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: Wed, 21 Nov 2007 13:55:17 -0000 On Nov 21, 2007 2:39 PM, Andreas Wider=F8e Andersen wrot= e: > Hi, > > I'm working on a shell script that will let me attach (mount) an > external USB 2.0 harddrive and to my FreeBSD 6.2 server and perform a > full backup of /backup on my server (all files and subfolders) once or > twice a week (whenever I run the cronjob). The script must be able to > run through a cronjob and the drive must be mounted and unmounted > after each job (I will swap between two drives of the same type and > size). The script must also remove folders/files older than 30 days. > > Does anyone use a script like this today that they can share? I'm not > a shell scripter myself so any help is highly appreciated. > > Here's my rough idea/sketch: > > #! /bin/sh > > $MOUNT =3D /external > $DATE=3D date_today > > mount usb_drive $MOUNT > cd /$MOUNT > rm all files forlders older than 30 days > mkdir /$DATE > cp -fr /backup to /$MOUNT/$DATE > cd > unmount > > --- #!/bin/sh MOUNT=3D/external DATE=3D`date +%Y%m%d%H%M` mount /dev/da2 $MOUNT #Change device name find $MOUNT -mtime +30 -delete mkdir $MOUNT/$DATE cp -rp /backup/* $MOUNT/$DATE umount /external --- Bye Valerio Daelli