2013-11-13 01:20:00 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Simba::CA;
|
|
|
|
use autodie;
|
|
|
|
|
|
|
|
my $basedir = $ARGV[0];
|
|
|
|
usage() unless $basedir;
|
|
|
|
|
|
|
|
my $ca = Simba::CA->new({
|
|
|
|
dbi_file => $ENV{SIMBA_DB_CONN} || "$ENV{HOME}/.dbi/simba",
|
|
|
|
log_fh => \*STDERR,
|
|
|
|
});
|
|
|
|
my $dbh = $ca->{dbh};
|
|
|
|
|
|
|
|
my $sessions = $dbh->selectcol_arrayref("select id from sessions order by id");
|
|
|
|
for my $session_id (@$sessions) {
|
2013-11-26 22:50:11 +01:00
|
|
|
next if (-f "$basedir/$session_id.tsv"
|
|
|
|
|| -f "$basedir/$session_id.tsv.gz");
|
2013-11-13 01:20:00 +01:00
|
|
|
$ca->log(3, "exporting session $session_id");
|
|
|
|
my $sth
|
|
|
|
= $dbh->prepare(
|
|
|
|
qq{select sessions.id as "sessions.id", start_date, end_date, prefix,
|
|
|
|
instances.id as "instances.id", file_id, date, online,
|
|
|
|
versions2.id as "versions2.id", file_type, file_size, file_mtime, file_owner, file_group, file_acl, file_unix_bits, file_rdev, checksum, file_linktarget,
|
|
|
|
files.id as "files.id", path,
|
|
|
|
filesets.id as "filesets.id", host, dir, options, pid
|
|
|
|
from sessions, instances, versions2, files, filesets
|
|
|
|
where sessions.id=$session_id
|
|
|
|
and sessions.id=instances.session
|
|
|
|
and instances.version=versions2.id
|
|
|
|
and instances.file=files.id
|
|
|
|
and files.fileset=filesets.id
|
|
|
|
});
|
|
|
|
$sth->execute;
|
|
|
|
open my $fh, '>', "$basedir/$session_id.tsv";
|
|
|
|
print $fh join("\t", @{$sth->{NAME}}), "\n";
|
|
|
|
while (my $r = $sth->fetchrow_arrayref) {
|
|
|
|
no warnings 'uninitialized';
|
|
|
|
print $fh join("\t", @$r), "\n";
|
|
|
|
}
|
|
|
|
close($fh);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
print STDERR "Usage: $0 basedir\n";
|
|
|
|
exit(1);
|
|
|
|
}
|