From: T F <tf...@ho...> - 2001-01-26 05:39:13
|
I put together a little perl script to deal with importing my modified sql data from the slashdb before upgrading the whole slash system/db from cvs. When I'd been dumping my modified templates (as an example) the tpid field was being dumped. That's nice, until you try to import that data back in and the tpid's conflict with the standard bender slashdb data. This script rips the id fields (auto_increment) out of the dump file for you. Here's how I've used it: mysqldump {db} -h {dbmachine} -u {dbuser} -p -t "-wsection='test'" templates > /tmp/it ./fixsqldump -f /tmp/it > /tmp/data2import This is my first attempt at using regex under perl. Please don't laugh when you read the code. Eventually I'd like to finish the script so that it'll rip specified data directly from the db, which is why it's using the slash stuff. But for now, it just comes in handy. --------<snip>-------- #!/usr/bin/perl -w use strict; use Slash; use Slash::DB; use Getopt::Std; use Cwd; my $VERSION = '0.1'; my $COPYRIGHT = 'Copyright (c) 2001 tf23\@hotmail.com for slash'; my %opts; usage('no options supplied to program') unless getopts('vf:?', \%opts); usage('help') if $opts{'?'}; usage('you did not supply the source filename') if ! $opts{'f'}; usage('too many options') if (@ARGV > 2); if ($opts{'v'}) { print "$0, Version $VERSION, $COPYRIGHT\n"; exit(); } convertmysqldumpdata($opts{'f'}); sub convertmysqldumpdata { my ($src)=@_; my @files; my $dirflag = 0; $dirflag = 1 if -d $src; if ($dirflag) { opendir(DIR, $src); while(my $tmpfile = readdir(DIR)) { next if $tmpfile =~ /\./; push(@files, $src . '/' . $tmpfile); } } elsif (-f $src) { push(@files,$src); } for my $file (@files) { my $newfile=$file; open(FILE, "<$file"); foreach (<FILE>) { my $line=$_; chomp $line; $line=~ s/\sVALUES\s\(\d+\,/$1 $2VALUES \($3/g; print "$line\n"; } close(FILE); } } sub usage { my ($message) = @_; print "ERROR: $message\n"; print <<EOT; Usage: fixsqldump [OPTIONS] OPTIONS -f <filenametoconvert> -v Version of this program EOT exit(); } --------<snip>-------- _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com |