[prev in list] [next in list] [prev in thread] [next in thread] 

List:       suse-linux-e
Subject:    Re: [SLE] batch files
From:       Stephen Allewell <stephen () mirramar ! fsnet ! co ! uk>
Date:       2002-02-06 19:36:33
[Download RAW message or body]

Harry G wrote:
> 
> OK.  Now for a really dumb question.
> Do I write the scripts in an editor, or from the command line or what?  In
> DOS, you used an editor and named it with an .bat extension.  I would suspect
> you would do some sort of chmod ??? filename, then run it with a ./file.sh?
> 

Hi Harry,

I came across a script a while ago which I've been using ever
since for my backups.

------------------------------------------------------------------------------
#!/bin/bash

# Incremental backup of $DIR
# To make a master backup, just delete the snapshot file
# NB, the exclude file must not include any blank lines - not
even a final empty
 line.
# Implement the curly bracket wrapper below if you want to log
# all this (and not see anything directly on the screen).
#{

[ $# -eq 0 ] && exit 0
DIR=$1
BUTYPE=Incr

# if $DIR/.tar.exclude doesn't exist we need to make it, else tar
will refuse to
 run.
# assuming write permission here

[ -e $DIR/.tar.exclude ] || touch $DIR/.tar.exclude

# if this file exists - and is NOT EMPTY (-s) - then is a Main
backup

[ -s $DIR/.tar.snapshot ] || BUTYPE=Full

tar cvjf \
"/common/backup/`date +%Y%m%d`-$BUTYPE-$DIR.tar.bz2" -X
$DIR/.tar.exclude -g $DIR/.tar.snapshot $DIR

# } >> ~/backup.log 2>&1
-------------------------------------------------------------------------------
It uses the listed incremental options of tar to make full or
incremental backups of a directory dependant on there being a
file called .tar.snapshop in the directory of the one you are
backing up.
To use, save the bit between the lines to a file called bu, chmod
to be executable.  Change to the parent directory of the one you
want to backup and type bu directory_name_to_backup.  This will
create the backup file in /common/backup/filename_of_backup,
change the path as required.  The first time this is run it will
make a full backup, subsequent times will make an incremental
backup.  To make another full backup, delete the file
.tar.snapshot from the directory.

I actually run this script from another script which is executed
by cron in the early hours, which basically cd's to a series of
directories and performs the bu script on subdirectories.

The .tar.exclude file can be used to exclude directories from
being backed up, useful for excluding internet caches, etc.

regards

Steve

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic