Re: Scripting backup of file naming?

From: Chuck Swiger (cswiger_at_mac.com)
Date: 06/07/04

  • Next message: Tim Traver: "port upgrades"
    Date: Mon, 07 Jun 2004 12:27:15 -0400
    To: Bart Silverstrim <bsilver@chrononomicon.com>
    
    

    Bart Silverstrim wrote:
    [ ... ]
    > *problem; on server1, I'm going to have two directories: ~/archive and
    > ~/workingdir. I want the scp to move the files from server2 to
    > ~/workingdir, tar and zip them as a file name with a date attached (like
    > backup06072004.tgz) to make the filename distinctive, then move that
    > file from ~/workingdir to ~/archive. The filename would need to be
    > distinctive both to allow for reference when needing to restore a
    > snapshot and also to keep the archives from overwriting each other when
    > moved over.

    Consider the following script. You may want to switch to using scp rather
    than rsync, and you may choose to hardcode the SSH key rather than passing it
    in as the first argument. You might also want to change how $DESTROOT is set
    to match the paths you want to use. Finally, you will want to add something like:

            cd ${DESTROOT}/..
            ARCHIVEFILE=/home/SOMEUSER/archive/backup`date "+%Y%m%d"`.tgz
            tar cf - ${CLIENT} | gzip --best > ${ARCHIVEFILE}

    ...just before the final done. Test things out by hand for a while (or on a
    machine-by-machine basis), and then set this up in cron.

    -- 
    -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 <chuck@pkix.net>
    # $Id: backup.sh,v 1.3 2003/05/16 07:17:06 chuck Exp $
    #
    ####
    if [ $# -lt 2 ]; then
         echo "Usage: backup.sh <SSH key> <host1> [<host2>...]"
         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`."
    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    

  • Next message: Tim Traver: "port upgrades"

    Relevant Pages

    • Re: Sanity check needed on an idea
      ... such-and-such server all day yesterday, why is it broken, and when is it going ... as well as a backup copy handy if you need 'em. ... # operate on that host. ... echo "Authenticating via SSH key id: ...
      (freebsd-questions)
    • Backup script, was: Re: storage data
      ... Rsync is your friend; so are more serious backup tools like Amanda, ... # operate on that host. ... echo "Authenticating via SSH key id: ...
      (freebsd-questions)
    • Re: add virtual Disk ppc without reboot
      ... # Skript to rescan SCSI bus, ... echo "Host adapter $hostno found." ...
      (linux.redhat)
    • Re: "New" ZFS crash on FS (pool?) unmount/export
      ... the box stopped responding to pings at 02:07AM and it has a cron backup job using zfs send/recv at 02:00, so I'm guessing it's related, even though the backup probably should have finished before then... ... Essentially, it creates a GEOM provider of a file, containing a zpool, imports the pool and creates a clone to it, and then exports the pool. ... Every time it crashes it seems to be during or very soon after the export - only this time it didn't even take the snapshots. ... echo Creating ggate device ...
      (freebsd-current)
    • Re: Home Page Link Bars have stopped appearing
      ... Have tried the web host and they don't have a back up ... As I type the online version is publishing to my local machine which will ... have a backup on the internet (even if a little ... Now the original website has no link bars on ...
      (microsoft.public.frontpage.client)