On Wed, 21 May 2008 16:43:23 Ira Abramov wrote:
>
> > I can send you a script we use on our system but most of it is our
> > specific details.
>
> you are not scaring me, sounds delicious :-)
> Thanks in advance!

Below is the script (with minor changes). You should also look at the
"rsnapshot" - http://www.rsnapshot.org/ which does the same (with much
more options) in perl.

Ehud


/bin/sh -ex
# Compile by: /bin/sh -ex $*
# --------------------------------------------------

get_size ()                                    # size left on $1 in MB
{                                              # for deleting snapshots
    set +x
    df -m $1 | tail -n 1 | sed -e "s/ [ ]*/ /g" | cut "-d " -f4
    set -x
}
# ----------------------------------------------------------------------

HOUR=`date +%H`                                # hour, HH (10, 13, 16, 22)
case "$HOUR" in                                # check hour (22/23 or else)
   2? )  MAXPRC=20    ;;                       # No. of rsync processes
   * )   MAXPRC=4     ;;                       # Only 4 processes of rsync at 
noon
esac

DIRS="/fs-gib/snapshots"                       # snapshots are here
SNAP=`date +%Y%m%d_%H%M`                       # snapshot directory name
PRV=`ls -1atd $DIRS/2*_???? | head -n 1`       # latest snapshot (update source)

ORG="/snap-$SNAP"                              # source (lvm2 snapshot) name
DST="$DIRS/.NXT"                               # target (temp name)
DSNP="$DIRS/$SNAP"                             # target (final name)

lvcreate -v -L60G -pr -s -n $SNAP ulvm/nfs     # creates /dev/ulvm/$SNAP

mkdir -p $ORG                                  # mount point for snapshot
##  mount -t xfs -o ro,nouuid /dev/ulvm/$SNAP $ORG    # mount it read-only, 
nouuid check (for xfs)
mount -t ext3 -o ro /dev/ulvm/$SNAP $ORG       # mount it read-only

if [ ! -d $DST ] ; then                        # copy of last saved snapshot
    df -m /fs-gib                              # NOT exist, show size & copy
    cp -al $PRV $DST                           # copy latest snap by Hard links
    chmod 700 $DST                             # ONLY root has access to the 
snapshot
fi

touch -r / $DST                                # Set time of snapshot (to last 
change of /)

##############################################################
## rsync-snapshot.sh is our rsync enhanced script           ##
##                                                          ##
## you should use something like:                           ##
##    OPTIONS="--verbose --archive --delete --whole-file"   ##
##    rsync $OPTIONS "$ORG" "$DST" > "$LIST" 2>&1           ##
##############################################################
rsync-snapshot.sh $ORG $DST $MAXPRC ON IGN     # update snapshot by rsyncing 
(keep lst files)

touch -t ${SNAP:0:8}${SNAP:9:4} $DST $DST/bru/SNAP-DATE    # Set time of 
snapshot (to creation time)

sleep 10

umount $ORG                                    # unmount it
rmdir  $ORG                                    # remove temp dir
lvdisplay
lvremove -f ulvm/$SNAP                         # remove snapshot

mv $DST $DSNP                                  # rename to destination name
chmod 755 $DSNP                                # allow normal users to see it

cp -al $DSNP $DST                              # copy (by hard linking) to .NXT
touch -t 200102030405 $DST                     # make it somewhere in the past
chmod 700 $DST                                 # .NXT should be non reachable

df -m $DST                                     # show disk statistics
SIZE=`get_size $DST`                           # get size left on /ldsk

while [ $SIZE -lt 25000 ]                      # less than 15 GB
do
    LAST=`ls -a1td $DIRS/20* | tail -n 1`      # oldest snapshot
    rm -rf $LAST
    df -m $DST                                 # show after snapshot delete
    SIZE=`get_size $DST`
done

df -m                                          # show all mounts again

############################## end of create-snapshot.job 
##############################


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to