File:
[LON-CAPA] /
loncom /
debugging_tools /
archive_coursedata_tables.pl
Revision
1.1:
download - view:
text,
annotated -
select for diffs
Thu Dec 30 22:04:29 2004 UTC (19 years, 9 months ago) by
matthew
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_X,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
Small script to backup/restore loncoursedata tables. Stores tables in
debug/sql_backups.
1: #!/usr/bin/perl -w
2: #
3: # The LearningOnline Network
4: #
5: # $Id: archive_coursedata_tables.pl,v 1.1 2004/12/30 22:04:29 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>