[LON-CAPA-cvs] cvs: loncom /metadata_database parse_activity_log.pl

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 16 Dec 2004 15:03:29 -0000


matthew		Thu Dec 16 10:03:29 2004 EDT

  Modified files:              
    /loncom/metadata_database	parse_activity_log.pl 
  Log:
  Gzip activity log backup files.
  
  
Index: loncom/metadata_database/parse_activity_log.pl
diff -u loncom/metadata_database/parse_activity_log.pl:1.5 loncom/metadata_database/parse_activity_log.pl:1.6
--- loncom/metadata_database/parse_activity_log.pl:1.5	Wed Sep 15 17:11:06 2004
+++ loncom/metadata_database/parse_activity_log.pl	Thu Dec 16 10:03:29 2004
@@ -2,7 +2,7 @@
 #
 # The LearningOnline Network
 #
-# $Id: parse_activity_log.pl,v 1.5 2004/09/15 21:11:06 matthew Exp $
+# $Id: parse_activity_log.pl,v 1.6 2004/12/16 15:03:29 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -117,15 +117,16 @@
 ##
 my $sourcefilename;   # activity log data
 my $newfilename;      # $sourcefilename will be renamed to this
-my $sql_filename;     # the mysql backup data file name.
+my $gz_sql_filename;  # the gzipped mysql backup data file name.
 my $error_filename;   # Errors in parsing the activity log will be written here
 if ($file) {
     $sourcefilename = $file;
 } else {
     $sourcefilename = &get_filename($course,$domain);
 }
-$sql_filename = $sourcefilename;
+my $sql_filename = $sourcefilename;
 $sql_filename =~ s|[^/]*$|activity.log.sql|;
+$gz_sql_filename = $sql_filename.'.gz';
 $error_filename = $sourcefilename;
 $error_filename =~ s|[^/]*$|activity.log.errors|;
 $logthis->('Beginning logging '.time);
@@ -274,7 +275,7 @@
 
 if ($drop) { &drop_tables(); $logthis->('dropped tables'); }
 
-if (-s $sql_filename) {
+if (-s $gz_sql_filename) {
     # if ANY one of the tables does not exist, load the tables from the
     # backup.
     my @Current_Tables = &Apache::lonmysql::tables_in_db();
@@ -289,7 +290,7 @@
     foreach my $table (@Activity_Table,@ID_Tables) {    
         if (! $Found{$table->{'id'}}) {
             $time_this->();
-            &load_backup_tables($sql_filename);
+            &load_backup_tables($gz_sql_filename);
             $time_this->('load backup tables');
             last;
         }
@@ -328,7 +329,7 @@
     } elsif ($result > 0) {
         $time_this->();
         $logthis->('process_courselog returned '.$result.' backup up tables');
-        &backup_tables($sql_filename);
+        &backup_tables($gz_sql_filename);
         $time_this->('write backup tables');
     }
 }
@@ -579,14 +580,14 @@
 ## Use mysqldump to store backups of the tables
 ##
 sub backup_tables {
-    my ($sql_filename) = @_;
+    my ($gz_sql_filename) = @_;
     my $command = qq{mysqldump --opt loncapa };
                              
     foreach my $table (@ID_Tables,@Activity_Table) {
         my $tablename = $table->{'id'};
         $command .= $tablename.' ';
     }
-    $command .= '>'.$sql_filename;
+    $command .= '| gzip >'.$gz_sql_filename;
     $logthis->($command);
     system($command);
 }
@@ -595,13 +596,15 @@
 ## Load in mysqldumped files
 ##
 sub load_backup_tables {
-    my ($sql_filename) = @_;
-    return undef if (! -e $sql_filename);
-    # Check for .my.cnf
-    my $command = 'mysql -e "SOURCE '.$sql_filename.'" loncapa';
-    $logthis->('loading previously saved sql table'.$/.$command);
-    system($command);
-    $logthis->('finished loading old data');
+    my ($gz_sql_filename) = @_;
+    if (-s $gz_sql_filename) {
+        &logthis('loading data from gzipped sql file');
+        my $command='gzip -dc activity.log.sql.gz | mysql --database=loncapa';
+        system($command);
+        $logthis->('finished loading gzipped data');;
+    } else {
+        return undef;
+    }
 }
 
 ##