=cut
-use Gtk2; # auto-initialize Gtk2
-use Gtk2::GladeXML;
-use Gtk2::SimpleList; # easy wrapper for list views
-use Gtk2::Gdk::Keysyms; # keyboard code constants
use Data::Dumper qw/Dumper/;
my $debug=0; # can be on brestore.conf
our ($VERSION) = ('$Revision$' =~ /(\d+)/);
bconsole => 'bconsole', # path and arg to bconsole
bsr_dest => '', # destination url for bsr files
debug => 0, # debug level 0|1
- use_ok_bkp_only => 1, # dont use bad backup
+ use_ok_bkp_only => 1, # don't use bad backup
bweb => 'http://localhost/cgi-bin/bweb/bweb.pl', # bweb url
see_all_versions => 0, # display all file versions in FileInfo
mozilla => 'mozilla', # mozilla bin
1;
################################################################
-
+# Display all file revision in a separated window
package DlgFileVersion;
sub on_versions_close_clicked
my ($self, $widget, $context, $data, $info, $time,$string) = @_;
DlgResto::drag_set_info($widget,
- $self->{cwd},
+ $self->{pwd},
$data);
}
+#
+# new DlgFileVersion(Bvfs, "client", pathid, fileid, "/path/to/", "filename");
+#
sub new
{
- my ($class, $bvfs, $client, $path, $file, $cwd, $fn) = @_;
+ my ($class, $bvfs, $client, $pathid, $fileid, $path, $fn) = @_;
my $self = bless {
- cwd => $cwd,
+ pwd => $path,
version => undef, # main window
};
$glade_box->signal_autoconnect_from_package($self);
$glade_box->get_widget("version_label")
- ->set_markup("<b>File revisions : $client:$cwd$fn</b>");
+ ->set_markup("<b>File revisions : $client:$path$fn</b>");
my $widget = $glade_box->get_widget('version_fileview');
my $fileview = Gtk2::SimpleList->new_from_treeview(
);
DlgResto::init_drag_drop($fileview);
- my @v = $bvfs->get_all_file_versions($path,
- $file,
+ my @v = $bvfs->get_all_file_versions($pathid,
+ $fileid,
$client,
1);
for my $ver (@v) {
1;
################################################################
+# Display a warning message
package DlgWarn;
sub new
my $self = bless {
bsr_file => $arg{bsr_file}, # /path/to/bsr on director
- pref => $arg{pref}, # Pref ref
- glade => undef, # GladeXML ref
- bconsole => undef, # Bconsole ref
+ pref => $arg{pref}, # Pref ref
+ glade => undef, # GladeXML ref
+ bconsole => undef, # Bconsole ref
};
my $console = $self->{bconsole} = get_bconsole($arg{pref});
# using regexp
if ($self->{glade}->get_widget('chk_use_regexp')->get_active()) {
- return ('rwhere',
+ return ('regexwhere',
$self->{glade}->get_widget('entry_rwhere')->get_active());
}
}
if ($add_suffix) {
- push @ret,"!([^/])$!\$1$add_prefix!";
+ push @ret,"!([^/])\$!\$1$add_suffix!";
}
- return ('rwhere', join(',', @ret));
+ return ('regexwhere', join(',', @ret));
} else { # using where
return ('where',
# display Mb/Gb/Kb
sub human
{
- my @unit = qw(b Kb Mb Gb Tb);
+ my @unit = qw(B KB MB GB TB);
my $val = shift;
my $i=0;
my $format = '%i %s';
fileattrib => {}, # cache file
fileview => undef, # fileview widget SimpleList
fileinfo => undef, # fileinfo widget SimpleList
- cwd => '/',
+ cwd => '/',
client_combobox => undef, # client_combobox widget
restore_backup_combobox => undef, # date combobox widget
list_client => undef, # Gtk2::ListStore
list_backup => undef, # Gtk2::ListStore
cache_ppathid => {}, #
- bvfs => undef,
+ bvfs => undef, # Bfvs object
};
$self->{bvfs} = new Bvfs(conf => $pref);
if ($pref->{dbh}) {
$self->init_server_backup_combobox();
- $self->{bvfs}->create_brestore_tables();
+ if ($self->{bvfs}->create_brestore_tables()) {
+ new DlgWarn("brestore can't find brestore_xxx tables on your database. I will create them.");
+ }
}
$self->set_status($pref->{error});
$file_count++;
# $file = [filenameid,listfiles.id,listfiles.Name,File.LStat,File.JobId]
listview_push($fileview,
- $bvfs->{cwd},
+ $bvfs->{cwdid},
$file->[0],
$file->[2],
$file->[4],
foreach my $i (@sel)
{
my ($pid, $fid, $file, $jobid, $type, undef) = @{$i};
- $file = $self->{cwd} . '/' . $file;
+ $file = $self->{cwd} . $file;
$self->add_selected_file_to_list($pid, $fid, $file, $jobid, $type);
}
}
SELECT Job.JobId, Job.VolsessionId, Job.VolsessionTime, JobMedia.StartFile,
JobMedia.EndFile, JobMedia.FirstIndex, JobMedia.LastIndex,
JobMedia.StartBlock, JobMedia.EndBlock, JobMedia.VolIndex,
- Media.Volumename, Media.MediaType
+ Media.VolumeName, Media.MediaType
FROM Job, JobMedia, Media
WHERE Job.JobId = JobMedia.JobId
AND JobMedia.MediaId = Media.MediaId
# path, volsessiontime DESC (get the most recent file...)
# The array rows look like this :
# complete_path,is_dir,fileindex,
- #\81 ref->(jobid,VolsessionId,VolsessionTime,File,FirstIndex,
+ # ref->(jobid,VolsessionId,VolsessionTime,File,FirstIndex,
# LastIndex,StartBlock-EndBlock,VolIndex,Volumename,MediaType)
@temp_list = sort {$a->[0] cmp $b->[0]
|| $b->[3]->[2] <=> $a->[3]->[2]
or $prev_volfile ne $volfile)
{
# We have to create a new section in the bsr...
- #\81Â\81 We print the previous one ...
+ # We print the previous one ...
# (before that, save the current range ...)
if ($first_of_current_range != $prev_fileindex)
{
- #\81Â\81 we are in a range
+ # we are in a range
push @fileindex_ranges,
("$first_of_current_range-$prev_fileindex");
}
{
my ($self) = @_;
- my $query = "SELECT JobId from Job WHERE JobId NOT IN (SELECT JobId FROM brestore_knownjobid) order by JobId";
+ $self->{conf}->{dbh}->begin_work();
+
+ my $query = "
+ SELECT JobId from Job
+ WHERE JobId NOT IN (SELECT JobId FROM brestore_knownjobid) AND JobStatus IN ('T', 'f', 'A') ORDER BY JobId";
my $jobs = $self->dbh_selectall_arrayref($query);
$self->update_brestore_table(map { $_->[0] } @$jobs);
+
+ $self->{conf}->{dbh}->commit();
+ $self->{conf}->{dbh}->begin_work();
+
+ print STDERR "Cleaning path visibility\n";
+
+ my $nb = $self->dbh_do("
+ DELETE FROM brestore_pathvisibility
+ WHERE NOT EXISTS
+ (SELECT 1 FROM Job WHERE JobId=brestore_pathvisibility.JobId)");
+
+ print STDERR "$nb rows affected\n";
+ print STDERR "Cleaning known jobid\n";
+
+ $nb = $self->dbh_do("
+ DELETE FROM brestore_knownjobid
+ WHERE NOT EXISTS
+ (SELECT 1 FROM Job WHERE JobId=brestore_knownjobid.JobId)");
+
+ print STDERR "$nb rows affected\n";
+
+ $self->{conf}->{dbh}->commit();
}
sub get_root
sub ch_dir
{
my ($self, $pathid) = @_;
- $self->{cwd} = $pathid;
+ $self->{cwdid} = $pathid;
}
sub up_dir
{
my ($self) = @_ ;
- my $query =
- "SELECT PPathId FROM brestore_pathhierarchy WHERE PathId IN ($self->{cwd}) ";
+ my $query = "
+ SELECT PPathId
+ FROM brestore_pathhierarchy
+ WHERE PathId IN ($self->{cwdid}) ";
my $all = $self->dbh_selectall_arrayref($query);
return unless ($all); # already at root
my $dir = join(',', map { $_->[0] } @$all);
if ($dir) {
- $self->{cwd} = $dir;
+ $self->ch_dir($dir);
}
}
sub pwd
{
my ($self) = @_;
- return $self->get_path($self->{cwd});
+ return $self->get_path($self->{cwdid});
}
sub get_path
return undef unless ($self->{curjobids});
my $inclause = $self->{curjobids};
- my $inlistpath = $self->{cwd};
+ my $inlistpath = $self->{cwdid};
my $query =
"SELECT File.FilenameId, listfiles.id, listfiles.Name, File.LStat, File.JobId
return undef unless ($self->{curjobids});
- my $pathid = $self->{cwd};
+ my $pathid = $self->{cwdid};
my $jobclause = $self->{curjobids};
# Let's retrieve the list of the visible dirs in this dir ...
AND File.FileIndex >= JobMedia.FirstIndex
AND File.FileIndex <= JobMedia.LastIndex
AND JobMedia.MediaId = Media.MediaId
+ AND Job.Type = 'B'
AND Client.Name = '$client'";
$self->debug($query);
if ($ref->[8])
{
# The file has a md5. We compare his md5 to other known md5...
- #\81 We take size into account. It may happen that 2 files
+ # We take size into account. It may happen that 2 files
# have the same md5sum and are different. size is a supplementary
# criterion
# we never met this one before...
$allready_seen_by_md5{$ref->[8] .'-'. $ref->[6]}=1;
}
- #\81 Even if it has a md5, we should also work with mtimes
+ # Even if it has a md5, we should also work with mtimes
# We allready have a (better) version
next if ( (not $see_all)
and $allready_seen_by_mtime{$ref->[5] .'-'. $ref->[6]});
}
}
-sub cleanup_brestore_table
-{
- my ($self) = @_;
-
- my $query = "SELECT JobId from brestore_knownjobid";
- my @jobs = @{$self->dbh_selectall_arrayref($query)};
-
- foreach my $jobentry (@jobs)
- {
- my $job = $jobentry->[0];
- $query = "SELECT FileId from File WHERE JobId = $job LIMIT 1";
- my $result = $self->dbh_selectall_arrayref($query);
- if (scalar(@{$result}))
- {
- # There are still files for this jobid
- print STDERR "$job still exists. Not cleaning...\n";
-
- } else {
- $query = "DELETE FROM brestore_pathvisibility WHERE JobId = $job";
- $self->dbh_do($query);
- $query = "DELETE FROM brestore_knownjobid WHERE JobId = $job";
- $self->dbh_do($query);
- }
- }
-}
-
sub parent_dir
{
my ($path) = @_;
sub create_brestore_tables
{
my ($self) = @_;
-
+ my $ret = 0;
my $verif = "SELECT 1 FROM brestore_knownjobid LIMIT 1";
unless ($self->dbh_do($verif)) {
- new DlgWarn("brestore can't find brestore_xxx tables on your database. I will create them.");
+ $ret=1;
- $self->{error} = "Creating internal brestore tables";
my $req = "
CREATE TABLE brestore_knownjobid
(
$verif = "SELECT 1 FROM brestore_pathhierarchy LIMIT 1";
unless ($self->dbh_do($verif)) {
+ $ret=1;
my $req = "
CREATE TABLE brestore_pathhierarchy
(
$verif = "SELECT 1 FROM brestore_pathvisibility LIMIT 1";
unless ($self->dbh_do($verif)) {
+ $ret=1;
my $req = "
CREATE TABLE brestore_pathvisibility
(
ON brestore_pathvisibility (JobId)";
$self->dbh_do($req);
}
+ return $ret;
}
# Get metadata
storage => $arg{storage} || '',
fileset => $arg{fileset} || '',
where => $arg{where} || '',
- rwhere => $arg{rwhere} || '',
+ regexwhere => $arg{regexwhere} || '',
priority=> $arg{prio} || '',
replace => $arg{replace},
action => 'run',
}
1;
+################################################################
package main;
exit 1;
}
-my $file_conf = "$ENV{HOME}/.brestore.conf" ;
+my $file_conf = (exists $ENV{HOME})? "$ENV{HOME}/.brestore.conf" : undef ;
my $batch_mod;
GetOptions("conf=s" => \$file_conf,
"debug" => \$debug,
"help" => \&HELP_MESSAGE) ;
+if (! defined $file_conf) {
+ print STDERR "Could not detect default config and no config file specified\n";
+ HELP_MESSAGE();
+}
+
my $p = new Pref($file_conf);
if (! -f $file_conf) {
if ($batch_mod) {
my $vfs = new Bvfs(conf => $p);
if ($p->connect_db()) {
+ if ($vfs->create_brestore_tables()) {
+ print "Creating brestore tables\n";
+ }
$vfs->update_cache();
}
exit (0);
}
-$glade_file = $p->{glade_file};
+# load Gtk libraries only in non batch mode
+eval "
+ use Gtk2;
+ use Gtk2::GladeXML;
+ use Gtk2::SimpleList;
+ use Gtk2::Gdk::Keysyms;
+";
+
+$glade_file = $p->{glade_file} || $glade_file;
foreach my $path ('','.','/usr/share/brestore','/usr/local/share/brestore') {
if (-f "$path/$glade_file") {
$bvfs->ch_dir(123496);
$dirs = $bvfs->ls_dirs();
$bvfs->ls_files();
-map { $bvfs->debug($_) } $bvfs->get_all_file_versions($bvfs->{cwd},312433, "exw3srv3", 1);
+map { $bvfs->debug($_) } $bvfs->get_all_file_versions($bvfs->{cwdid},312433, "exw3srv3", 1);