Annotation of loncom/debugging_tools/archive_coursedata_tables.pl, revision 1.1
1.1 ! matthew 1: #!/usr/bin/perl -w
! 2: #
! 3: # The LearningOnline Network
! 4: #
! 5: # $Id: parse_activity_log.pl,v 1.11 2004/12/22 20:42:39 matthew Exp $
! 6: #
! 7: # Copyright Michigan State University Board of Trustees
! 8: #
! 9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 10: #
! 11: # LON-CAPA is free software; you can redistribute it and/or modify
! 12: # it under the terms of the GNU General Public License as published by
! 13: # the Free Software Foundation; either version 2 of the License, or
! 14: # (at your option) any later version.
! 15: #
! 16: # LON-CAPA is distributed in the hope that it will be useful,
! 17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 19: # GNU General Public License for more details.
! 20: #
! 21: # You should have received a copy of the GNU General Public License
! 22: # along with LON-CAPA; if not, write to the Free Software
! 23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 24: #
! 25: # /home/httpd/html/adm/gpl.txt
! 26: #
! 27: # http://www.lon-capa.org/
! 28: #
! 29: use strict;
! 30: use Getopt::Long();
! 31: use lib '/home/httpd/lib/perl/';
! 32: use LONCAPA::Configuration();
! 33:
! 34: #
! 35: # Determine parameters
! 36: my ($help,$restore,$version);
! 37: &Getopt::Long::GetOptions("help" => \$help,
! 38: "restore" => \$restore);
! 39: if ($help || ! scalar(@ARGV)) {
! 40: print<<USAGE;
! 41: archive_class.pl
! 42: Store the MySQL tables associated with a given class to a backup file.
! 43: The gzipped backup file contains the MySQL commands needed to recreate the
! 44: coursedata tables.
! 45: Parameters:
! 46: course Multiple allowed LON-CAPA course id
! 47: restore optional if present, restore the tables from the
! 48: backup file, overwriting the current data.
! 49: help optional Print this help and exit
! 50: Examples:
! 51: archive_coursedata_tables.pl sfu_39251c2fbb33f47sful3 msu_12340987139587msul4
! 52: archive_coursedata_tables.pl -restore sfu_39251c2fbb33f47sful3
! 53: USAGE
! 54: exit;
! 55: }
! 56: ##
! 57: my %perlvar = %{&LONCAPA::Configuration::read_conf('loncapa.conf')};
! 58: my $targetdir = $perlvar{'lonDaemons'}.'/debug/sql_backups';
! 59: if (! -d $targetdir) {
! 60: if (! mkdir($targetdir)) {
! 61: print "Unable to create directory to store backups.".$/.
! 62: $targetdir.$/.
! 63: "Aborting".$/;
! 64: exit;
! 65: }
! 66: }
! 67:
! 68: while (my $course = shift(@ARGV)) {
! 69: my $targetfile = $targetdir.'/'.$course.'_coursedata.sql.gz';
! 70: #
! 71: my @tables;
! 72: foreach my $suffix ('symb','part','student','performance','parameters',
! 73: 'partdata','responsedata','timestampdata','weight') {
! 74: push(@tables,$course.'_'.$suffix);
! 75: }
! 76: #
! 77: if ($restore) {
! 78: print "Restoring from ".$targetfile.$/;
! 79: &load_backup_tables($targetfile);
! 80: } else {
! 81: print "Backing up to ".$targetfile.$/;
! 82: &backup_tables($targetfile,\@tables);
! 83: }
! 84: }
! 85: exit;
! 86:
! 87: ##############################################################
! 88: ##############################################################
! 89: sub backup_tables {
! 90: my ($gz_sql_filename,$tables) = @_;
! 91: my $command = qq{mysqldump --opt loncapa };
! 92: foreach my $table (@$tables) {
! 93: $command .= $table.' ';
! 94: }
! 95: $command .= '| gzip >'.$gz_sql_filename;
! 96: system($command);
! 97: }
! 98:
! 99: ##
! 100: ## Load in mysqldumped files
! 101: ##
! 102: sub load_backup_tables {
! 103: my ($gz_sql_filename) = @_;
! 104: if (-s $gz_sql_filename) {
! 105: my $command='gzip -dc '.$gz_sql_filename.' | mysql --database=loncapa';
! 106: system($command);
! 107: }
! 108: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>