Show
Ignore:
Timestamp:
09.11.2018 21:23:48 (20 months ago)
Author:
ak19
Message:

If rollback_on_cancel is turned on, then before the database connection happens, the (warning) message suggested by Dr Bainbridge is issued to the user with a 5 second sleep: to backup their archives and index folders to keep it in sync with what the GS SQL database will do on cancel (which is to rollback until before the import or buildcol script, whichever was run). Sample copy commands, specific to the user's OS, are displayed. When cancel is pressed, if a rollback is performed, then the final message is displayed reminding the user to restore their backed up archives and index folders.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/gsmysql.pm

    r32593 r32594  
    3232 
    3333use DBI; # the central package for this module used by GreenstoneSQL Plugout and Plugin 
     34use FileUtils; 
     35use gsprintf; 
    3436 
    3537################# 
     
    110112        print STDERR "   User cancelled: rolling back SQL database transaction.\n"; 
    111113        $_dbh_instance->rollback(); # will warn on failure, nothing more we can/want to do, 
     114 
     115        print STDERR "****************************\n"; 
     116        &gsprintf::gsprintf(STDERR, "{gsmysql.restore_backups_on_build_cancel_msg}\n"); 
     117        print STDERR "****************************\n"; 
    112118    } 
    113119    } 
     
    219225{ 
    220226    my $self= shift (@_); 
    221     my ($params_map) = @_; 
     227    my ($params_map) = @_; # map instead of named vars with an eye on gssql inheritance 
    222228     
    223229    $params_map->{'db_encoding'} = $self->{'db_encoding'}; 
     
    237243{ 
    238244    #my $self= shift (@_); # singleton method doesn't use self, but callers don't need to know that 
    239     my ($params_map) = @_; 
    240      
    241     if($params_map->{'verbosity'}) { 
    242     if(!defined $params_map->{'autocommit'}) { 
    243         print STDERR "  Autocommit parameter not defined\n"; 
    244     } 
    245     if($params_map->{'autocommit'}) { 
    246         print STDERR "   SQL DB CANCEL SUPPORT OFF.\n" if($params_map->{'verbosity'} > 2); 
    247     } else { 
    248         print STDERR "   SQL DB CANCEL SUPPORT ON.\n"; 
    249     } 
    250     } 
     245    my ($params_map) = @_;     
     246    
    251247     
    252248    return $_dbh_instance if($_dbh_instance); 
    253  
    254249    # or make the connection 
     250 
     251 
     252    # some useful user messages first 
     253    if(!defined $params_map->{'autocommit'} && $params_map->{'verbosity'}) { 
     254    print STDERR "  Autocommit parameter not defined\n"; 
     255    } 
     256    if($params_map->{'autocommit'}) { 
     257    print STDERR "   SQL DB CANCEL SUPPORT OFF.\n" if($params_map->{'verbosity'} > 2); 
     258    } else { # rollback on cancel support on     
     259    &issue_backup_on_build_message(); 
     260    }     
     261 
    255262     
    256263    # For proper utf8 support in MySQL, encoding should be 'utf8mb4' as 'utf8' is insufficient 
     
    779786} 
    780787 
     788# regular function, not method 
     789# Called when rollback_on_cancel is on. 
     790# Warns they user to make backups of their archives and index dir 
     791# and sleeps for 5 seconds so they can do that 
     792sub issue_backup_on_build_message 
     793{        
     794    # warn the user they'll need to backup their archives (and index?) folders 
     795    # plugout stores archivedir in $self->{'output_dir'}, but not available in plugin 
     796    # But we're only making an example copy command anyway: 
     797    my $archivesdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "archives"); 
     798    my $archives_rollbackdir = $archivesdir.".rollback"; 
     799     
     800    # Assume user knows what they're doing if a rollback directory already exists 
     801    # instead of wasting time waiting for sleep to terminate 
     802    return if FileUtils::directoryExists("$archives_rollbackdir"); 
     803     
     804    my $indexdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "index"); 
     805     
     806     
     807    # use rsync command on unix 
     808    my $example_copy_cmds = "rsync -pavH $archivesdir $archivesdir.rollback\n"; 
     809    $example_copy_cmds .= "rsync -pavH $indexdir $indexdir.rollback\n"; 
     810     
     811    if (($ENV{'GSDLOS'} =~ /^windows$/i) && ($^O ne "cygwin")) { 
     812    # https://stackoverflow.com/questions/4601161/copying-all-contents-of-folder-to-another-folder-using-batch-file 
     813    $example_copy_cmds = "xcopy /EVI $archivesdir $archivesdir.rollback\n"; 
     814    $example_copy_cmds .= "xcopy /EVI $indexdir $indexdir.rollback\n"; 
     815     
     816    } 
     817    print STDERR "****************************\n"; 
     818    &gsprintf::gsprintf(STDERR, "{gsmysql.backup_on_build_msg}\n", $example_copy_cmds); 
     819    print STDERR "****************************\n";       
     820    sleep 5; # 5s    
     821} 
     822 
    7818231;