-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.pl
132 lines (105 loc) · 3.39 KB
/
dump.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/perl
use strict;
use warnings;
use configuration;
use messages;
my @all_dumps = qw(core classification tests verifiers testing);
my $default_restore = "tests";
@ARGV = configuration::keys_to_options(@ARGV);
configuration::config_read();
my $dumps = $configuration::config{"DataBase_Dumps"};
my $prefix = $configuration::config{"DataBase_DumpCmd_Prefix"};
my $ps = $configuration::config{"PathSeparator_System"};
my $psl = $configuration::config{"PathSeparator_DataBase"};
my ($cmd, $type) = @ARGV;
if ( ! defined $cmd ) {
die "Command expected. Try '$0 help' for more info.";
}
if ( $cmd eq "create" ) {
if ( ! defined $type or $type eq "all" ) {
messages::verbose("Creating all dumps");
for ( @all_dumps ) {
dump_create($_);
}
} else {
dump_create($type);
}
} elsif ( $cmd eq "restore" ) {
if ( ! defined $type ) {
$type = $default_restore;
}
dump_restore($type);
} elsif ( $cmd eq "help" ) {
usage();
} else {
die "Unknown command: '$cmd'. Try '$0 help' for more info";
}
sub dump_create {
my ($type) = @_;
messages::verbose("Creating '$type' dump");
my $cmd = $dumps . $ps . $prefix . "dump_cmd_" . $type;
$cmd =~ s/$psl/$ps/g;
if ( ! -e "$cmd" ) {
die "No such dump cmd file: '$cmd'";
}
my $dump = $dumps . $ps . "dump_" . $type . ".sql";
$dump =~ s/$psl/$ps/g;
if ( ! -e "$dump" ) {
die "No such dump file: '$dump'";
}
if ( $configuration::config{"DataBase_Type"} eq "SQLite" ) {
my $db = $configuration::config{"DataBase_SQLite_File"};
$db =~ s/$psl/$ps/g;
my $bin = $configuration::config{"DataBase_SQLite_Bin"};
$bin =~ s/$psl/$ps/g;
messages::debug("'$bin' '$db' < '$cmd' > '$dump'");
`"$bin" "$db" < "$cmd" > "$dump"`;
} else {
die "Unknown database type: '" . $configuration::config{"DataBase_Type"} . "'";
}
}
sub dump_restore {
my ($type) = @_;
messages::verbose("Restoring '$type' dump");
my $dump = $dumps . $ps . "dump_" . $type . ".sql";
$dump =~ s/$psl/$ps/g;
if ( ! -e "$dump" ) {
die "No such dump file: '$dump'";
}
if ( $configuration::config{"DataBase_Type"} eq "SQLite" ) {
my $db = $configuration::config{"DataBase_SQLite_File"};
$db =~ s/$psl/$ps/g;
if ( -e "$db" ) {
unlink($db);
}
my $bin = $configuration::config{"DataBase_SQLite_Bin"};
$bin =~ s/$psl/$ps/g;
messages::debug("'$bin' '$db' < '$dump'");
`"$bin" "$db" < "$dump"`;
} else {
die "Unknown database type: '" . $configuration::config{"DataBase_Type"} . "'";
}
}
sub usage {
print "Usage:\n";
print " $0 [KEYS] create [TYPE]\n";
print " $0 [KEYS] restore [TYPE]\n";
print " $0 help\n";
print "\n";
print "Commands:\n";
print " create create a dump of specified type (all dumps if type is ommited)\n";
print " restore restore the database from the dump ('tests' dump is default)\n";
print "\n";
print "Dump types:\n";
print " core just table schemas\n";
print " classification dump of classification\n";
print " tests dump of classification and tests\n";
print " verifiers dump of classification, tests and verifiers\n";
print " testing complete dump of the database\n";
print " all select all dumps (for 'create' command only)\n";
print "\n";
print "Keys:\n";
print " -v, --verbose verbose mode\n";
print " --debug additional debug information\n";
print " --debug-lib additional debug information from libraries\n";
}