#!/usr/bin/perl -w

# $Id: rotate_db.pl,v 1.1 2005-12-08 21:11:27 akarp Exp $
use strict;

# This script performs a hot backup of the database in a directory
# marked by today's date. It also rotates earlier backups so that
# we always have a fixed number of days worth of backups.

use constant DAYS => 7;

use Date::Calc qw(Add_Delta_Days Today);

my $target = make_target(0);
system("/nmi/nwo/scripts/db_backup.sh $target");

$target = make_target(DAYS);
if (-e $target) {
  print "$0: removing $target ... \n";
  system("rm -rf $target")
}

sub make_target {
  my $days = $_[0];
  return join '-', '/nmi/db/hotbackup', Add_Delta_Days(Today(), -$days);
}
