#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2001 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id: backup-blocks,v 1.2.2.1 2001/06/05 11:51:44 pudge Exp $

# First version by Brian, brian@tangent.org

use strict;
use File::Basename;
use Getopt::Std;
use DBIx::Password;

(my $VERSION) = ' $Revision: 1.2.2.1 $ ' =~ /\$Revision:\s+([^\s]+)/;
my $PROGNAME = basename($0);

my %opts;
# Remember to doublecheck these match usage()!
usage() unless getopts('hvu:', \%opts);
usage() if ($opts{'h'} || !keys %opts);
version() if $opts{'v'};
$opts{'u'} ||= 'slash';

{
	my $dbh = DBIx::Password->connect($opts{'u'});

	my $get = $dbh->prepare("SELECT bid,block FROM blocks");
	my $delete = $dbh->prepare("DELETE FROM backup_blocks");
	my $insert  = $dbh->prepare("INSERT INTO backup_blocks (bid,block) VALUES (?,?)");

	$get->execute();
	$delete->execute();
	while (my @row = $get->fetchrow_array){
		$insert->execute(@row);
	}

	$dbh->disconnect();
}

sub usage {
	print "*** $_[0]\n" if $_[0];
	# Remember to doublecheck these match getopts()!
	print <<EOT;

Usage: $PROGNAME [OPTIONS]

Populate the backup_blocks table.  Will delete existing data
and insert the data from the blocks table.

	-h	Help (this message)
	-v	Version
	-u	Virtual user (default is "slash")

EOT
	exit;
}

sub version {
	print <<EOT;

$PROGNAME $VERSION

This code is a part of Slash, and is released under the GPL.
Copyright 1997-2001 by Open Source Development Network. See README
and COPYING for more information, or see http://slashcode.com/.

EOT
	exit;
}

__END__
