diff --git a/lib/Simba/CA.pm b/lib/Simba/CA.pm index 55413a9..f5f7702 100644 --- a/lib/Simba/CA.pm +++ b/lib/Simba/CA.pm @@ -150,6 +150,7 @@ sub run { for (sort keys %{ $self->{times} }) { $self->log(3, " $_: $self->{times}{$_} s"); } + $self->export(); } sub backup2disk { @@ -822,6 +823,44 @@ sub adjust_partitions { } } +sub export { + my ($self) = @_; + my $dbh = $self->{dbh}; + my $exportdir = $self->basedir . "/export"; + + my $sessions = $dbh->selectcol_arrayref("select id from sessions order by id"); + for my $session_id (@$sessions) { + next if (-f "$exportdir/$session_id.tsv" + || -f "$exportdir/$session_id.tsv.gz"); + $self->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, '>', "$exportdir/$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); + rename "$exportdir/$session_id.tsv.$$", "$exportdir/$session_id.tsv"; + system "gzip", "$exportdir/$session_id.tsv"; + } + +} + sub DESTROY { my ($self) = @_; $self->{dbh}->disconnect();