From owner-freebsd-questions@FreeBSD.ORG Thu May 15 23:40:25 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1CBE237B408 for ; Thu, 15 May 2003 23:40:25 -0700 (PDT) Received: from pop016.verizon.net (pop016pub.verizon.net [206.46.170.173]) by mx1.FreeBSD.org (Postfix) with ESMTP id 361C043F93 for ; Thu, 15 May 2003 23:40:24 -0700 (PDT) (envelope-from cswiger@mac.com) Received: from mac.com ([129.44.60.214]) by pop016.verizon.net (InterMail vM.5.01.05.33 201-253-122-126-133-20030313) with ESMTP id <20030516064022.BXES3199.pop016.verizon.net@mac.com>; Fri, 16 May 2003 01:40:22 -0500 Message-ID: <3EC487D6.5030806@mac.com> Date: Fri, 16 May 2003 02:40:22 -0400 From: Chuck Swiger Organization: The Courts of Chaos User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4b) Gecko/20030507 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd@werosoft.com References: <3EC16C98.11161.4AB9BB@localhost> In-Reply-To: <3EC16C98.11161.4AB9BB@localhost> X-Enigmail-Version: 0.75.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Authentication-Info: Submitted using SMTP AUTH at pop016.verizon.net from [129.44.60.214] at Fri, 16 May 2003 01:40:22 -0500 cc: freebsd-questions@freebsd.org Subject: Backup script, was: Re: storage data X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 May 2003 06:40:25 -0000 Ronald Weinrich wrote: [ ... ] > has any one a script written, to pull data from host-a to host-b, tar it on > host-b in regular (cron) time. Rsync is your friend; so are more serious backup tools like Amanda, Retrospect, and even Legato Networker. That being said, here's a shell script that you might find useful. Enjoy! -Chuck ============== #! /bin/sh #### # # Backup script. Takes SSH key as the first argument, then a list of # one or more hostnames to backup. This script removes slashes found # in hostnames and tests whether a host is pingable before trying to # operate on that host. # # In other words, if you configure one host at a time to backup okay # by adjusting SSH keys and such, running "./backup.sh _ident_ *.com" # at a later date will backup all of the hosts manually configured # automaticly. If a host is down, it will be skipped without its # files being deleted by the "rsync --delete" or "rm" commands # (if enabled; see below). # # Copyright (c) 2003. Charles Swiger # $Id: backup.sh,v 1.2 2003/05/16 06:22:03 chuck Exp $ # #### if [ $# -lt 2 ]; then echo "Usage: backup.sh [...]" exit 1 fi ID=${1} shift echo "Authenticating via SSH key id: ${ID}" echo PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/libexec:/usr/lib:/bin:/sbin MKDIR="mkdir -p" RM="/bin/rm -rf" RSYNC_RSH="ssh -i ${ID}" export RSYNC_RSH COPY="rsync -aqRC --copy-unsafe-links --delete" # Alternative COPY version if you don't have or want to use rsync: # COPY="scp -rq -i ${ID}" # Loop through all of the remaing arguments, and test whether reachable for name ; do CLIENT=`echo "$name" | tr -d '/'` if { ! /sbin/ping -q -c 1 -t 10 ${CLIENT} > /dev/null ; } then echo "${CLIENT} is unpingable and may be down. Consult errors above." continue fi echo "Backing up ${CLIENT} at `date`." # This is the destination to backup the client to. DESTROOT=/export/Backups/"${CLIENT}"/ #### # DANGEROUS: (optionally) completely clean contents first? # # You will probably be sorry if you leave this enabled and run # backups via cron. Only turn this on when running by hand. # ${RM} ${DESTROOT} #### ${MKDIR} ${DESTROOT} ${COPY} ${CLIENT}:/etc ${DESTROOT} 2> /dev/null ${COPY} ${CLIENT}:/var/log ${DESTROOT} 2> /dev/null ${COPY} ${CLIENT}:/var/named ${DESTROOT} 2> /dev/null ${COPY} ${CLIENT}:/usr/local/etc ${DESTROOT} 2> /dev/null ${COPY} ${CLIENT}:/opt/apache/conf ${DESTROOT} 2> /dev/null # add directory locations you care about here... done echo echo "Finished backup at `date`."