export_tables.in 1.08 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
4

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
6
7
8
# All rights reserved.
#

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
#
# export_tables - Create an SQL file with the contents of selected tables 
# that should more or less be the same across all sites.
#

use English;

#
# Configure variables
#
use lib '@prefix@/lib';
use libdb;
my $DBNAME = '@TBDBNAME@';

my $mysqldump = "mysqldump";

#
# Build a list of tables to export
#
my $result = DBQueryFatal("select table_name from exported_tables");
my $table_names;
while (my ($table_name) = $result->fetchrow()) {
    $table_names .= "$table_name ";
}

#
# Run mysqldump, and read its stdout
#
open(FH,"$mysqldump -t $DBNAME $table_names |") or
    die "Unable to run $mysqldump: $!\n";

#
# Change INSERT to REPLACE, so that the resulting SQL can be used to update
# existing databases.
#
while (<FH>) {
    s/^INSERT/REPLACE/g;
46
47
48
49
50
51
52
    #
    # Kinda hackish, but gets the job done...
    #
    # Don't put any temporary entries from state_triggers out
    if (/INTO state_triggers VALUES \(\'([^\']*)\',/i &&
	$1 ne '*') { next; }

53
54
    print;
}