From: Frank Brehm Date: Wed, 8 Aug 2007 12:06:10 +0000 (+0000) Subject: Initialen Import von KReceips begonnen X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=7ad22a035effb2c480b63344c06bab7a6fb5eb89;p=cookbook.git Initialen Import von KReceips begonnen git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@7 191103c4-1d37-0410-b3e5-d8c2315c0aac --- diff --git a/cookbook.yml b/cookbook.yml index c2f5dab..8409f10 100644 --- a/cookbook.yml +++ b/cookbook.yml @@ -1,2 +1,14 @@ --- -name: CookBook +name: Kochbuch +database: + host: localhost + port: 3306 + schema: cookbook + user: cookbook + # passwd: +kreceipes-database: + host: localhost + port: 3306 + schema: rezepte + user: cookbook + # passwd: diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl new file mode 100755 index 0000000..fc693ae --- /dev/null +++ b/sbin/initial_import.pl @@ -0,0 +1,110 @@ +#!/usr/bin/perl + +# $Id: show_sessions.pl 74 2007-06-28 09:28:55Z fbrehm $ +# $URL$ + +use strict; +use warnings; + +use File::Spec; +use Cwd 'abs_path'; +use YAML 'LoadFile'; +use Data::Dumper; + +$Data::Dumper::Indent = 1; +$Data::Dumper::Sortkeys = 1; + +# Own modules +use FindBin; +use lib "$FindBin::Bin/../lib"; + +use CookBook::Common; + +################## + +my $debug = $ENV{'COOKBOOK_DEBUG'} ? 1 : 0; + +my $home_dir = abs_path( File::Spec->canonpath( $FindBin::Bin . "/.." ) ); +print "Home-Dir: '$home_dir'\n"; + +my $global_conf_file = $home_dir . "/cookbook.yml"; +my $local_conf_file = $home_dir . "/cookbook_local.yml"; + +my $global_conf = {}; +my $local_conf = {}; + +unless ( -f $global_conf_file ) { + warn "Konfigurationsdatei '$global_conf_file' nicht gefunden.\n"; + exit 1; +} + +# Konfiguration einlesen ... +print "Lese globale Konfiguration '$global_conf_file' ein ... "; +eval { ($global_conf) = LoadFile($global_conf_file); }; +if ($@) { + print "NOT OK\n"; + warn $@ . "\n"; + exit 5; +} +print "OK\n"; +print "Globale Konfiguration: " . Dumper($global_conf) if $debug; + +if ( -f $local_conf_file ) { + print "Lese lokale Konfiguration '$local_conf_file' ein ... "; + eval { ($local_conf) = LoadFile($local_conf_file); }; + if ($@) { + print "NOT OK\n"; + warn $@ . "\n"; + exit 5; + } + print "OK\n"; +} ## end if ( -f $local_conf_file ) +print "Lokale Konfiguration: " . Dumper($local_conf) if $debug; + +# DSN's und Nutzerangaben ermitteln: + +my ( $target_dsn, $target_user, $target_passwd, $source_dsn, $source_user, $source_passwd ); + +my $port; + +$target_dsn = 'dbi:mysql:host=%s;database=%s'; +$target_dsn = sprintf( $target_dsn, + ( $local_conf->{'database'}{'host'} || $global_conf->{'database'}{'host'} || 'localhost' ), + ( $local_conf->{'database'}{'schema'} || $global_conf->{'database'}{'schema'} || 'cookbook' ) ); +$port = 3306; +$port = to_int( $global_conf->{'database'}{'port'} ) if $global_conf->{'database'}{'port'} and to_int( $global_conf->{'database'}{'port'} ); +$port = to_int( $local_conf->{'database'}{'port'} ) if $local_conf->{'database'}{'port'} and to_int( $local_conf->{'database'}{'port'} ); + +$target_dsn .= ';port=' . $port unless $port == 3306; + +$source_dsn = 'dbi:mysql:host=%s;database=%s'; +$source_dsn = sprintf( $source_dsn, + ( $local_conf->{'kreceipes-database'}{'host'} || $global_conf->{'kreceipes-database'}{'host'} || 'localhost' ), + ( $local_conf->{'kreceipes-database'}{'schema'} || $global_conf->{'kreceipes-database'}{'schema'} || 'cookbook' ) ); +$port = 3306; +$port = to_int( $global_conf->{'kreceipes-database'}{'port'} ) + if $global_conf->{'kreceipes-database'}{'port'} and to_int( $global_conf->{'kreceipes-database'}{'port'} ); +$port = to_int( $local_conf->{'kreceipes-database'}{'port'} ) + if $local_conf->{'kreceipes-database'}{'port'} and to_int( $local_conf->{'kreceipes-database'}{'port'} ); + +$source_dsn .= ';port=' . $port unless $port == 3306; + +$target_user = $local_conf->{'database'}{'user'} || $global_conf->{'database'}{'user'} || 'cookbook'; +$source_user = $local_conf->{'kreceipes-database'}{'user'} || $global_conf->{'kreceipes-database'}{'user'} || 'cookbook'; + +$target_passwd = ''; +$target_passwd = $global_conf->{'database'}{'passwd'} if defined $global_conf->{'database'}{'passwd'}; +$target_passwd = $local_conf->{'database'}{'passwd'} if defined $local_conf->{'database'}{'passwd'}; + +$source_passwd = ''; +$source_passwd = $global_conf->{'kreceipes-database'}{'passwd'} if defined $global_conf->{'kreceipes-database'}{'passwd'}; +$source_passwd = $local_conf->{'kreceipes-database'}{'passwd'} if defined $local_conf->{'kreceipes-database'}{'passwd'}; + +if ($debug) { + printf "Quell-Datenbank: DSN='%s', User='%s', Pwd='%s'\n", $source_dsn, $source_user, $source_passwd; + printf "Ziel-Datenbank: DSN='%s', User='%s', Pwd='%s'\n", $target_dsn, $target_user, $target_passwd; +} + +print "\n"; + +exit 0;