#!/usr/bin/perl -w # # EMULAB-COPYRIGHT # Copyright (c) 2000-2003 University of Utah and the Flux Group. # All rights reserved. # # # 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 () { s/^INSERT/REPLACE/g; # # 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; } print; }