]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/brestore/brestore.pl
Implement PopUp YES/NO dialog for bat.
[bacula/bacula] / gui / brestore / brestore.pl
index e327e6794c45732359b6d7d996110c61203fcdf5..31359ab54206c26370b8ed54a09bbec9f131cd68 100755 (executable)
@@ -71,7 +71,7 @@ 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+\.\d+)/);
+our ($VERSION) = ('$Revision$' =~ /(\d+)/);
 
 package Pref;
 use DBI;
@@ -137,6 +137,7 @@ sub write_config
 {
     my ($self) = @_;
     
+    $self->{error} = '';
     my %parameters;
 
     for my $k (@{ $self->{entry_keyword} }) { 
@@ -154,8 +155,9 @@ sub write_config
     }
     else
     {
-       # TODO : Display a message
+       $self->{error} = "Can't write configuration $!";
     }
+    return $self->{error};
 }
 
 sub connect_db
@@ -189,6 +191,7 @@ sub connect_db
                          $self->{connection_string} ."' $!";
        return 0;
     }
+    $self->{is_mysql} = ($self->{connection_string} =~ m/dbi:mysql/i);
     $self->{dbh}->{RowCacheSize}=100;
     return 1;
 }
@@ -365,11 +368,11 @@ sub on_applybutton_clicked
        $pref->{$k} = $w->get_active();
     }
 
-    $pref->write_config();
-    if ($pref->connect_db()) {
+    if (!$pref->write_config() && $pref->connect_db()) {
         $self->{dlgresto}->set_status('Preferences updated');
        $self->{dlgresto}->init_server_backup_combobox();
        $self->{dlgresto}->set_status($pref->{error});
+
     } else {
        $self->{dlgresto}->set_status($pref->{error});
     }
@@ -401,7 +404,7 @@ sub on_cancelbutton_clicked
 1;
 
 ################################################################
-
+# Display all file revision in a separated window
 package DlgFileVersion;
 
 sub on_versions_close_clicked
@@ -420,15 +423,18 @@ sub fileview_data_get
     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
        };
 
@@ -439,7 +445,7 @@ sub new
     $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(
@@ -459,8 +465,8 @@ sub new
                                                       );
     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) {
@@ -487,6 +493,7 @@ sub on_forward_keypress
 
 1;
 ################################################################
+# Display a warning message
 package DlgWarn;
 
 sub new
@@ -548,9 +555,9 @@ 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});
@@ -653,12 +660,89 @@ To follow it, you must use bconsole (or install/configure bweb)");
     }
 }
 
+sub on_use_regexp_toggled
+{
+    my ($self,$widget) = @_;
+    my $act = $widget->get_active();
+
+    foreach my $w ('entry_launch_where') {
+       $self->{glade}->get_widget($w)->set_sensitive(!$act);
+    }
+
+    foreach my $w ('entry_add_prefix', 'entry_strip_prefix', 
+                  'entry_add_suffix','entry_rwhere','chk_use_regexp')
+    {
+       $self->{glade}->get_widget($w)->set_sensitive($act);
+    }
+
+    if ($act) { # if we activate file relocation, we reset use_regexp
+       $self->{glade}->get_widget('entry_rwhere')->set_sensitive(0);
+       $self->{glade}->get_widget('chk_use_regexp')->set_active(0);
+    }
+}
+
+
+sub on_use_rwhere_toggled
+{
+    my ($self,$widget) = @_;
+    my $act = $widget->get_active();
+
+    foreach my $w ('entry_rwhere') {
+       $self->{glade}->get_widget($w)->set_sensitive($act);
+    }
+
+    foreach my $w ('entry_add_prefix', 'entry_strip_prefix', 
+                  'entry_add_suffix')
+    {
+       $self->{glade}->get_widget($w)->set_sensitive(!$act);
+    }
+}
+
 sub on_cancel_resto_clicked
 {
     my ($self) = @_ ;
     $self->{glade}->get_widget('dlg_launch')->destroy();
 }
 
+sub get_where
+{
+    my ($self) = @_ ;
+
+    if ($self->{glade}->get_widget('chk_file_relocation')->get_active()) {
+       # using regexp
+       if ($self->{glade}->get_widget('chk_use_regexp')->get_active()) {
+
+           return ('regexwhere', 
+                   $self->{glade}->get_widget('entry_rwhere')->get_active());
+       }
+           
+       # using regexp utils
+       my @ret;
+       my ($strip_prefix, $add_prefix, $add_suffix) = 
+           ($self->{glade}->get_widget('entry_strip_prefix')->get_text(),
+            $self->{glade}->get_widget('entry_add_prefix')->get_text(),
+            $self->{glade}->get_widget('entry_add_suffix')->get_text());
+           
+       if ($strip_prefix) {
+           push @ret,"!$strip_prefix!!i";
+       }
+       
+       if ($add_prefix) {
+           push @ret,"!^!$add_prefix!";
+       }
+
+       if ($add_suffix) {
+           push @ret,"!([^/])\$!\$1$add_suffix!";
+       }
+
+       return ('regexwhere', join(',', @ret));
+
+    } else { # using where
+       return ('where', 
+               $self->{glade}->get_widget('entry_launch_where')->get_text());
+    }
+}
+
 sub on_submit_resto_clicked
 {
     my ($self) = @_ ;
@@ -677,7 +761,8 @@ sub on_submit_resto_clicked
     my $storage = $glade->get_widget('combo_launch_storage')
                               ->get_active_text();
 
-    my $where = $glade->get_widget('entry_launch_where')->get_text();
+    my ($where_cmd, $where) = $self->get_where();
+    print "$where_cmd => $where\n";
 
     my $job = $glade->get_widget('combo_launch_job')
                               ->get_active_text();
@@ -704,7 +789,7 @@ sub on_submit_resto_clicked
                                       client  => $client,
                                       storage => $storage,
                                       fileset => $fileset,
-                                      where   => $where,
+                                      $where_cmd => $where,
                                       replace => $replace,
                                       priority=> $prio,
                                       bootstrap => $r);
@@ -881,7 +966,7 @@ sub fill_combo
 # 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';
@@ -962,13 +1047,13 @@ sub new
        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);
@@ -1018,7 +1103,7 @@ sub new
                                              'Size'          => 'text',
                                              'Date'          => 'text');
     init_drag_drop($fileview);
-    $fileview->set_search_column(4); # search on File Name
+    $fileview->set_search_column(6); # search on File Name
 
     # Connect glade-restore_list to Gtk2::SimpleList
     $widget = $glade->get_widget('restorelist');
@@ -1070,7 +1155,9 @@ sub new
 
     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});
@@ -1278,18 +1365,17 @@ sub on_list_client_changed
                              set_job_ids_for_date($self->dbh(),
                                                   $self->current_client,
                                                   $self->current_date,
-                                                  $self->{pref}->{use_ok_bkp_only})
+                                                  $self->{conf}->{use_ok_bkp_only})
                              ];
 
     my $fs = $self->{bvfs};
     $fs->set_curjobids(@{$self->{CurrentJobIds}});
-    $fs->update_brestore_table(@{$self->{CurrentJobIds}});
     $fs->ch_dir($fs->get_root());
     # refresh_fileview will be done by list_backup_changed
 
 
     my @endtimes=$self->get_all_endtimes_for_job($self->current_client,
-                                                $self->{pref}->{use_ok_bkp_only});
+                                                $self->{conf}->{use_ok_bkp_only});
 
     foreach my $endtime (@endtimes)
     {
@@ -1395,7 +1481,7 @@ sub refresh_fileview
        $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],
@@ -1502,7 +1588,7 @@ sub on_bweb_activate
 {
     my $self = shift; 
     $self->set_status("Open bweb on your browser");
-    $self->{pref}->go_bweb('', "go on bweb");
+    $self->{conf}->go_bweb('', "go on bweb");
 }
 
 # Change the current working directory
@@ -1645,7 +1731,7 @@ sub fill_infoview
     my @v = $self->{bvfs}->get_all_file_versions($path, 
                                                 $file,
                                                 $self->current_client,
-                                                $self->{pref}->{see_all_versions});
+                                                $self->{conf}->{see_all_versions});
     for my $ver (@v) {
        my (undef,$pid,$fid,$jobid,$fileindex,$mtime,
            $size,$inchanger,$md5,$volname) = @{$ver};
@@ -1680,7 +1766,7 @@ sub on_list_backups_changed
                              set_job_ids_for_date($self->dbh(),
                                                   $self->current_client,
                                                   $self->current_date,
-                                                  $self->{pref}->{use_ok_bkp_only})
+                                                  $self->{conf}->{use_ok_bkp_only})
                              ];
     $self->{bvfs}->set_curjobids(@{$self->{CurrentJobIds}});
     $self->refresh_fileview();
@@ -1772,7 +1858,7 @@ sub context_add_to_filelist
     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);
     }
 }
@@ -1953,8 +2039,6 @@ WHERE Job.JobId = JobMedia.JobId
   AND Path.Path LIKE 
         (SELECT ". $self->dbh_strcat('Path',"'\%'") ." FROM Path 
           WHERE PathId IN ($dirid)
-    UNION 
-         SELECT " . $self->dbh_strcat('Path',"'\%'") ." FROM brestore_missing_path          WHERE PathId IN ($dirid)
         )
   AND File.JobId IN ($inclause) )";
                        push @select_queries,($query);
@@ -2065,7 +2149,7 @@ WHERE Job.JobId = JobMedia.JobId
        # path, volsessiontime DESC (get the most recent file...)
        # The array rows look like this :
        # complete_path,is_dir,fileindex,
-       # ref->(jobid,VolsessionId,VolsessionTime,File,FirstIndex,
+       #\81 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]
@@ -2173,11 +2257,11 @@ WHERE Job.JobId = JobMedia.JobId
                       or $prev_volfile ne $volfile)
                {
                        # We have to create a new section in the bsr...
-                       # We print the previous one ... 
+                       #\81Â\81 We print the previous one ... 
                        # (before that, save the current range ...)
                        if ($first_of_current_range != $prev_fileindex)
                        {
-                               # we are in a range
+                               #\81Â\81 we are in a range
                                push @fileindex_ranges,
                                    ("$first_of_current_range-$prev_fileindex");
                        }
@@ -2290,17 +2374,49 @@ sub get_pathid
 {
     my ($self, $dir) = @_;
     my $query = 
-       "SELECT PathId FROM Path WHERE Path = ?
-          UNION 
-         SELECT PathId FROM brestore_missing_path WHERE Path = ?";
+       "SELECT PathId FROM Path WHERE Path = ?";
     my $sth = $self->dbh_prepare($query);
-    $sth->execute($dir,$dir);
+    $sth->execute($dir);
     my $result = $sth->fetchall_arrayref();
     $sth->finish();
     
     return join(',', map { $_->[0] } @$result);
 }
 
+
+sub update_cache
+{
+    my ($self) = @_;
+
+    $self->{conf}->{dbh}->begin_work();
+
+    my $query = "
+  SELECT JobId from Job 
+   WHERE JobId NOT IN (SELECT JobId FROM brestore_knownjobid) ORDER BY JobId";
+    my $jobs = $self->dbh_selectall_arrayref($query);
+
+    $self->update_brestore_table(map { $_->[0] } @$jobs);
+
+    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
 {
     my ($self, $dir) = @_;
@@ -2310,28 +2426,30 @@ 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
@@ -2339,11 +2457,10 @@ sub get_path
     my ($self, $pathid) = @_;
     $self->debug("Call with pathid = $pathid");
     my $query = 
-       "SELECT Path FROM Path WHERE PathId IN (?)
-          UNION 
-         SELECT Path FROM brestore_missing_path WHERE PathId IN (?)";
+       "SELECT Path FROM Path WHERE PathId IN (?)";
+
     my $sth = $self->dbh_prepare($query);
-    $sth->execute($pathid,$pathid);
+    $sth->execute($pathid);
     my $result = $sth->fetchrow_arrayref();
     $sth->finish();
     return $result->[0];    
@@ -2353,6 +2470,7 @@ sub set_curjobids
 {
     my ($self, @jobids) = @_;
     $self->{curjobids} = join(',', @jobids);
+    $self->update_brestore_table(@jobids);
 }
 
 sub ls_files
@@ -2362,7 +2480,7 @@ sub ls_files
     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
@@ -2392,7 +2510,7 @@ sub ls_dirs
 
     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 ...
@@ -2405,46 +2523,28 @@ sub ls_dirs
     my $dir_filenameid = $result->[0];
      
     # Then we get all the dir entries from File ...
-    # It's ugly because there are records in brestore_missing_path ...
     $query = "
-SELECT PathId, Path, JobId, Lstat FROM(
-    (
-    SELECT Path.PathId, Path.Path, lower(Path.Path), 
-           listfile.JobId, listfile.Lstat
-    FROM (
-       SELECT DISTINCT brestore_pathhierarchy.PathId
-       FROM brestore_pathhierarchy
-       JOIN Path 
-           ON (brestore_pathhierarchy.PathId = Path.PathId)
-       JOIN brestore_pathvisibility 
-           ON (brestore_pathhierarchy.PathId = brestore_pathvisibility.PathId)
-       WHERE brestore_pathhierarchy.PPathId = $pathid
-       AND brestore_pathvisibility.jobid IN ($jobclause)) AS listpath
-    JOIN Path ON (listpath.PathId = Path.PathId)
-    LEFT JOIN (
-       SELECT File.PathId, File.JobId, File.Lstat FROM File
-       WHERE File.FilenameId = $dir_filenameid
-       AND File.JobId IN ($jobclause)) AS listfile
-       ON (listpath.PathId = listfile.PathId)
-    UNION
-    SELECT brestore_missing_path.PathId, brestore_missing_path.Path, 
-           lower(brestore_missing_path.Path), listfile.JobId, listfile.Lstat
+SELECT PathId, Path, JobId, Lstat FROM (
+    
+    SELECT Path1.PathId, Path1.Path, lower(Path1.Path),
+           listfile1.JobId, listfile1.Lstat
     FROM (
-       SELECT DISTINCT brestore_pathhierarchy.PathId
-       FROM brestore_pathhierarchy
-       JOIN brestore_missing_path 
-           ON (brestore_pathhierarchy.PathId = brestore_missing_path.PathId)
-       JOIN brestore_pathvisibility 
-           ON (brestore_pathhierarchy.PathId = brestore_pathvisibility.PathId)
-       WHERE brestore_pathhierarchy.PPathId = $pathid
-       AND brestore_pathvisibility.jobid IN ($jobclause)) AS listpath
-    JOIN brestore_missing_path ON (listpath.PathId = brestore_missing_path.PathId)
+        SELECT DISTINCT brestore_pathhierarchy1.PathId
+        FROM brestore_pathhierarchy AS brestore_pathhierarchy1
+        JOIN Path AS Path2
+            ON (brestore_pathhierarchy1.PathId = Path2.PathId)
+        JOIN brestore_pathvisibility AS brestore_pathvisibility1
+            ON (brestore_pathhierarchy1.PathId = brestore_pathvisibility1.PathId)
+        WHERE brestore_pathhierarchy1.PPathId = $pathid
+        AND brestore_pathvisibility1.jobid IN ($jobclause)) AS listpath1
+    JOIN Path AS Path1 ON (listpath1.PathId = Path1.PathId)
     LEFT JOIN (
-       SELECT File.PathId, File.JobId, File.Lstat FROM File
-       WHERE File.FilenameId = $dir_filenameid
-       AND File.JobId IN ($jobclause)) AS listfile
-       ON (listpath.PathId = listfile.PathId))
-ORDER BY 2,3 DESC ) As a";
+        SELECT File1.PathId, File1.JobId, File1.Lstat FROM File AS File1
+        WHERE File1.FilenameId = $dir_filenameid
+        AND File1.JobId IN ($jobclause)) AS listfile1
+        ON (listpath1.PathId = listfile1.PathId)
+     ) AS A ORDER BY 2,3 DESC
+";
     $self->debug($query);
     $sth=$self->dbh_prepare($query);
     $sth->execute();
@@ -2556,9 +2656,7 @@ sub estimate_restore_size
   WHERE Path.PathId = File.PathId
   AND File.JobId = Job.JobId
   AND Path.Path LIKE 
-        (SELECT Path || '%' FROM Path WHERE PathId IN ($dir)
-          UNION 
-         SELECT Path || '%' FROM brestore_missing_path WHERE PathId IN ($dir)
+        (SELECT " . $self->dbh_strcat('Path',"'\%'") . " FROM Path WHERE PathId IN ($dir)
         )
   AND File.JobId IN ($inclause)
   ORDER BY Path.Path, File.FilenameId, Job.StartTime DESC";
@@ -2680,7 +2778,7 @@ sub get_all_file_versions
        if ($ref->[8])
        {
            # The file has a md5. We compare his md5 to other known md5...
-           # 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
             
@@ -2714,6 +2812,8 @@ sub update_brestore_table
 {
     my ($self, @jobs) = @_;
 
+    $self->debug(\@jobs);
+
     foreach my $job (sort {$a <=> $b} @jobs)
     {
        my $query = "SELECT 1 FROM brestore_knownjobid WHERE JobId = $job";
@@ -2877,12 +2977,11 @@ sub build_path_hierarchy
 sub return_pathid_from_path
 {
     my ($self, $path) = @_;
-    my $query = "SELECT PathId FROM Path WHERE Path = ?
-                 UNION
-                 SELECT PathId FROM brestore_missing_path WHERE Path = ?";
+    my $query = "SELECT PathId FROM Path WHERE Path = ?";
+
     #print STDERR $query,"\n" if $debug;
     my $sth = $self->{conf}->{dbh}->prepare_cached($query);
-    $sth->execute($path,$path);
+    $sth->execute($path);
     my $result =$sth->fetchrow_arrayref();
     $sth->finish();
     if (defined $result)
@@ -2890,7 +2989,7 @@ sub return_pathid_from_path
        return $result->[0];
 
     } else {
-        # A bit dirty : we insert into path AND missing_path, to be sure
+        # A bit dirty : we insert into path, and we have to be sure
         # we aren't deleted by a purge. We still need to insert into path to get
         # the pathid, because of mysql
         $query = "INSERT INTO Path (Path) VALUES (?)";
@@ -2899,18 +2998,7 @@ sub return_pathid_from_path
        $sth->execute($path);
        $sth->finish();
         
-       $query = " INSERT INTO brestore_missing_path (PathId,Path)
-                  SELECT PathId,Path FROM Path WHERE Path = ?";
-       #print STDERR $query,"\n" if $debug;
-       $sth = $self->{conf}->{dbh}->prepare_cached($query);
-       $sth->execute($path);
-       $sth->finish();
-       $query = " DELETE FROM Path WHERE Path = ?";
-       #print STDERR $query,"\n" if $debug;
-       $sth = $self->{conf}->{dbh}->prepare_cached($query);
-       $sth->execute($path);
-       $sth->finish();
-       $query = "SELECT PathId FROM brestore_missing_path WHERE Path = ?";
+       $query = "SELECT PathId FROM Path WHERE Path = ?";
        #print STDERR $query,"\n" if $debug;
        $sth = $self->{conf}->{dbh}->prepare_cached($query);
        $sth->execute($path);
@@ -2924,13 +3012,12 @@ sub return_pathid_from_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
     (
@@ -2942,6 +3029,7 @@ sub create_brestore_tables
     
     $verif = "SELECT 1 FROM brestore_pathhierarchy LIMIT 1";
     unless ($self->dbh_do($verif)) {
+       $ret=1;
        my $req = "
    CREATE TABLE brestore_pathhierarchy
    (
@@ -2959,6 +3047,7 @@ sub create_brestore_tables
     
     $verif = "SELECT 1 FROM brestore_pathvisibility LIMIT 1";
     unless ($self->dbh_do($verif)) {
+       $ret=1;
        my $req = "
     CREATE TABLE brestore_pathvisibility
     (
@@ -2974,22 +3063,7 @@ sub create_brestore_tables
                           ON brestore_pathvisibility (JobId)";
        $self->dbh_do($req);
     }
-    
-    $verif = "SELECT 1 FROM brestore_missing_path LIMIT 1";
-    unless ($self->dbh_do($verif)) {
-       my $req = "
-    CREATE TABLE brestore_missing_path
-    (
-      PathId int4 NOT NULL,
-      Path text NOT NULL,
-      CONSTRAINT brestore_missing_path_pkey PRIMARY KEY (PathId)
-    )";
-       $self->dbh_do($req);
-
-       $req = "CREATE INDEX brestore_missing_path_path
-                          ON brestore_missing_path (Path)";
-       $self->dbh_do($req);
-    }
+    return $ret;
 }
 
 # Get metadata
@@ -3163,9 +3237,10 @@ sub run
                                client  => $arg{client},
                                storage => $arg{storage} || '',
                                fileset => $arg{fileset} || '',
-                               where   => $arg{where},
-                               replace => $arg{replace},
+                               where   => $arg{where}   || '',
+                               regexwhere  => $arg{regexwhere}  || '',
                                priority=> $arg{prio}    || '',
+                               replace => $arg{replace},
                                action  => 'run',
                                timeout => 10,
                                bootstrap => [$arg{bootstrap}],
@@ -3214,34 +3289,8 @@ sub list_client
 }
 
 1;
-
 ################################################################
 
-package Batch;
-use base qw/DlgResto/;
-
-sub new
-{
-    my ($class, $conf) = @_;
-    my $self = bless {info => $conf}, $class;
-
-    $self->{dbh} = $conf->{dbh};
-
-    return $self;
-}
-
-sub update_cache
-{
-    my ($self) = @_;
-
-    my $query = "SELECT JobId from Job WHERE JobId NOT IN (SELECT JobId FROM brestore_knownjobid) order by JobId";
-    my $jobs = $self->dbh_selectall_arrayref($query);
-
-    $self->{bvfs}->update_brestore_table(map { $_->[0] } @$jobs);
-}
-
-1;
-
 package main;
 
 use Getopt::Long ;
@@ -3267,10 +3316,12 @@ if (! -f $file_conf) {
 }
 
 if ($batch_mod) {
-    my $b = new Batch($p);
+    my $vfs = new Bvfs(conf => $p);
     if ($p->connect_db()) {
-       $b->set_dbh($p->{dbh});
-       $b->update_cache();
+       if ($vfs->create_brestore_tables()) {
+           print "Creating brestore tables\n";
+       }
+       $vfs->update_cache();
     }
     exit (0);
 }
@@ -3330,4 +3381,4 @@ my $dirs = $bvfs->ls_dirs();
 $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);