Amanda-Users

Re: Pre/Post backup scripts on clients ?

2005-05-05 22:20:28
Subject: Re: Pre/Post backup scripts on clients ?
From: Bert_De_Ridder AT peopleware DOT be
To: Geert Uytterhoeven <geert AT linux-m68k DOT org>
Date: Fri, 6 May 2005 03:58:41 +0200

Amanda – Control other processes - Mini How-To

This is a mini-howto explaining how to control other running tasks on a server where the amanda software is used to backup data.

Problem : Lots of software is picky about their datafiles being backed up while the files are in use.
It sometimes is even necessary to know the state of the datafiles at the moment of backup so that when restoring you know exactly *what* you are restoring. And most of the time there are dependencies between the datafiles as well (for instance, the pure datafiles and the controlfiles of an Oracle database.)

The solution is actually quite simple; you just use a custom made backupscript in stead of the standard tar command. Inside this tar command, you do some necessary processing before executing the tar command and – if necessary – do some more processing.
This way, you can easily stop an Oracle database, tar the files, send them to the tape server and restart the Oracle database. This of course is just an example, anything you can do in a shell script can be done.

Step 1 : Create the script

This is the most important step, this script is the work horse of the solution.
I've called it /bin/amandatar. You can call it whatever you want though.
It's a Perl script, it may not be very pretty code, but it does the job.
In the script, an example is given for the backup of a Lotus Notes Domino server.

#!/usr/bin/perl

# Tar wrapper for Amanda's tar.
#

use Getopt::Long qw(:config pass_through);

# Obtain directory and file information from the command line.

$result = GetOptions (
 'directory=s' => \$dir,
 'file=s' => \$file
);

# Check whether Amanda wants to do some administrative task (eg. indexinfo
# or obtain the number of bytes to be backed up)
# if file = /dev/null it's an administrative task and most of the time, no extra
#   processing is necessary.

# What you see here is just a log of the backup start time, and – more important
#   the stopping of the domino server

if ( $file ne '/dev/null' )
{
  if ( $dir eq '/local/notesdata' )
  {
    system "echo 'Start backup notes at ' >> /var/lib/amanda/runtime" ;
    system "date >> /var/lib/amanda/runtime";
    system ( "/etc/init.d/domino stop >> /var/lib/amanda/runtime" );
  }
}

# The command line is being 'reconstructed'. Necessary because the GetOptions
#   call above has stripped the file and directory information.
# This is what I meant with 'ugly'  code ;-)

while ( $ARGV[0] ne '' )
{
  $val = $ARGV[0] ;
  unshift ( @NEWARGV, $val, ) ;
  shift @ARGV;
}

while ( $NEWARGV[0] ne '' )
{
  $val = $NEWARGV[0] ;
  unshift ( @ARGV, $val ) ;
  shift @NEWARGV;
}

if ( $dir ne '' )
{
  unshift ( @ARGV, '--directory', $dir );
}
if ( $file ne '' )
{
  unshift ( @ARGV, '--file', $file );
}

if ( $file ne '/dev/null' )
{
  system "echo 'Backing up directory ' $dir >> /var/lib/amanda/runtime" ;
}

# And finally make sure tar is called :-)
#   (path may differ on your installation)
unshift ( @ARGV , "/bin/tar" ) ;

system ( @ARGV ) ;

# Postprocessing
#
# If Notes backup was requested, restart the server.
# Log the backup end time.
#

if ( $file ne '/dev/null' )
{
  if ( $dir eq '/local/notesdata' )
  {
    system ( "/etc/init.d/domino start >> /var/lib/amanda/runtime" );
    system "echo 'End backup notes at ' >> /var/lib/amanda/runtime" ;
    system "date >> /var/lib/amanda/runtime";
  }
}

exit 0;

# End script

On some systems it may be necessary to setuid root the script.

Step 2 : Rebuild Amanda so that it uses your newly created script.

Download the sources, untar them to a directory. I'm sure there are lots of documents already available on how to do this, so I won't go in to too much detail.

fast path :
/usr/local/src # tar -xvzf amanda-source.tar.gz
/usr/local/src # cd amanda-version
/usr/local/src/amanda-version # ./configure \
  --with-user=amanda \
  --prefix=/usr/local \
  --exec-prefix=/usr \
  --bindir=/usr/bin \
  --sbindir=/usr/sbin \
  --libexecdir=/usr/lib/amanda \
  --with-configdir=/etc/amanda \
  --with-group=disk \
  --with-gnutar=/bin/amandatar \
  --with-gnutar-listdir=/var/lib/amanda/gnutar-lists \
  --with-tmpdir=/tmp/amanda \
  --with-smbclient=/usr/bin/smbclient \
  --mandir=/usr/local/man

Here, it may be necessary to adjust some paths to match your installation. This setup works on SuSE Linux (also SLES) and MacOSX although you may have to use another binary tar.

As you see, you can also 'replace' the smbclient if necessary.
I haven't yet tested it though. I'll leave it as an exercise for the reader <g>

/usr/local/src/amanda-version # make
/usr/local/src/amanda-version # make instal

Now proceed as with a 'normal' installation.



Kind regards,

Bert De Ridder

PeopleWare NV - Head Office

Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66


PeopleWare NV - Branch Office Geel

Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25


http://www.peopleware.be


Geert Uytterhoeven <geert AT linux-m68k DOT org>
Sent by: owner-amanda-users AT amanda DOT org

05/05/2005 03:52 PM

To
Guy Dallaire <clepeterd AT gmail DOT com>
cc
amanda-users AT amanda DOT org
Subject
Re: Pre/Post backup scripts on clients ?





On Thu, 5 May 2005, Guy Dallaire wrote:
> I was wondering: Is amdump called on the clients as well via a crontab
> entry ? I taught the crontab entry was on the server, and that it
> contacted the client via the network when it's ready to backup it. My
> problem is that I have to execute the pre/post backup scripts on
> CLIENT machines.

So your crontab on the server has to use e.g. ssh with pub/priv key pair to run
the required commands on the client.

> 2005/5/5, Jon LaBadie <jon AT jgcomp DOT com>:
> > On Wed, May 04, 2005 at 10:51:10PM -0400, Guy Dallaire wrote:
> > > Is there a way to call some sort of script before and after the backup
> > > begins on the clients ? I want to make sure my oracle hot backups are
> > > completed before I start backuping my clients. I also need to shut
> > > down the database for cold backups and restart it after the backup is
> > > done.
> >
> > Crontab entry calling amdump can be a shell script calling your
> > stop and restart commands wrapped around the call to amdump.
> >
> > If that is too coarse you can replace your actual backup program
> > (some dump or gnutar) with a similar wrapper that differentiates
> > which DLE is being called and if it called for estimate phase
> > or backup phase.  Then the stop and start commands only need
> > be wrapped around one shorter instance.

Gr{oetje,eeting}s,

                                                                                                     Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert AT linux-m68k DOT org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                                                                                                          -- Linus Torvalds