use BackupPC::Lib;
use BackupPC::View;
use Data::Dumper;
-use Getopt::Std;
+use Getopt::Long::Descriptive;
use Time::HiRes qw/time/;
use File::Pid;
use POSIX qw/strftime/;
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
-my %opt;
-
-if ( !getopts("cdm:v:ijfq", \%opt ) ) {
- print STDERR <<EOF;
-usage: $0 [-c|-d] [-m num] [-v|-v level] [-i|-j|-f]
-
-Options:
- -c create database on first use
- -d delete database before import
- -m num import just num increments for one host
- -v num set verbosity (debug) level (default $debug)
- -i update Hyper Estraier full text index
- -j update full text, don't check existing files
- -f don't do anything with full text index
- -q be quiet for hosts without changes
-
-Option -j is variation on -i. It will allow faster initial creation
-of full-text index from existing database.
-
-Option -f will create database which is out of sync with full text index. You
-will have to re-run $0 with -i to fix it.
-
-EOF
- exit 1;
-}
-
-if ($opt{v}) {
- print "Debug level at $opt{v}\n";
- $debug = $opt{v};
-} elsif ($opt{f}) {
- print "WARNING: disabling full-text index update. You need to re-run $0 -j !\n";
- $index_node_url = undef;
-}
+my ($opt,$usage) = describe_options(
+"%c %o",
+[ 'create|c', "create database on first use" ],
+[ 'delete|d', "delete database before import" ],
+[ 'max|m=i', "import just max increments for one host" ],
+[ 'host|h=s@', "import just host(s)" ],
+[],
+[ 'verbose|v:i', 'set verbosity (debug) level' ],
+[ 'index|i', 'update full text index' ],
+[ 'junk|j', "update full text, don't check existing files" ],
+[ 'fast|f', "don't do anything with full text index" ],
+[ 'quiet|q', "be quiet for hosts without changes" ],
+[ 'help', "show help" ],
+);
+
+print($usage->text), exit if $opt->help;
+
+warn "hosts: ",dump( $opt->host );
#---- subs ----
my ($host_id, $share_id, $num) = @_;
- my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n";
+ my $skip_check = $opt->junk && print STDERR "Skipping check for existing files -- this should be used only with initital import\n";
print curr_time," updating fulltext:";
## update index ##
-if ( ( $opt{i} || $opt{j} ) && !$opt{c} ) {
+if ( ( $opt->index || $opt->junk ) && !$opt->create ) {
# update all
print "force update of Hyper Estraier index ";
- print "by -i flag" if ($opt{i});
- print "by -j flag" if ($opt{j});
+ print "by -i flag" if ($opt->index);
+ print "by -j flag" if ($opt->junk);
print "\n";
hest_update();
}
## create tables ##
-if ($opt{c}) {
+if ($opt->create) {
sub do_index {
my $index = shift || return;
my ($table,$col,$unique) = split(/:/, $index);
$dbh->do( qq{ CREATE SEQUENCE $seq } );
}
+=for later
+
print " creating triggers ";
$dbh->do( <<__END_OF_TRIGGER__ );
__END_OF_TRIGGER__
+=cut
+
print "...\n";
$dbh->commit;
}
## delete data before inseting ##
-if ($opt{d}) {
+if ($opt->delete) {
print "deleting ";
foreach my $table (qw(files dvds backups shares hosts)) {
print "$table ";
my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";
- $sth->{hosts_by_name}->execute($hosts->{$host_key}->{'host'});
+ next if $opt->host && ! grep { m/^$hostname$/ } @{ $opt->host };
+
+ $sth->{hosts_by_name}->execute($hostname);
unless (($hostID) = $sth->{hosts_by_name}->fetchrow_array()) {
$sth->{insert_hosts}->execute(
($#hosts + 1),
$incs
);
- print $host_header unless ($opt{q});
+ print $host_header unless $opt->quiet;
my $inc_nr = 0;
$beenThere = {};
foreach my $backup (@backups) {
$inc_nr++;
- last if (defined $opt{m} && $inc_nr > $opt{m});
+ last if defined $opt->max && $inc_nr > $opt->max;
my $backupNum = $backup->{'num'};
my @backupShares = ();
strftime($t_fmt,localtime($backup->{startTime})),
fmt_time($backup->{endTime} - $backup->{startTime})
);
- print $share_header unless ($opt{q});
+ print $share_header unless $opt->quiet;
my $files = BackupPC::View->new($bpc, $hostname, \@backups, { only_first => 1 });
next if ($count > 0);
# dump host and share header for -q
- if ($opt{q}) {
+ if ( $opt->quiet ) {
if ($host_header) {
print $host_header;
$host_header = undef;