From fde4aed663e958e4ed5f932c7cf41435250d6ff0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Tue, 26 Feb 2013 05:44:43 +0100 Subject: [PATCH] Initial commit. --- prj-import-db.pl | 42 ++++++++++++++++++++++++++++++++++++++ prj-upload-db.pl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100755 prj-import-db.pl create mode 100755 prj-upload-db.pl diff --git a/prj-import-db.pl b/prj-import-db.pl new file mode 100755 index 0000000..ad956e9 --- /dev/null +++ b/prj-import-db.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Config::General; +use Net::SSH::Perl; +use Net::SCP; +use Growl::NotifySend; + +my $conf = new Config::General("config"); +my %config = $conf->getall; + +print "Logging to $config{remote_host}...\n"; +my $ssh = Net::SSH::Perl->new($config{remote_host}, debug=>0); +$ssh->login($config{remote_user}, $config{remote_pass}); + +print "Dumping DB...\n"; +my ($stdout, $stderr, $exit) = $ssh->cmd("mysqldump -u$config{remote_db_user} -p$config{remote_db_pass} $config{remote_db_name} > $config{remote_db_name}.sql"); +print $stdout; + +print "Compressing DB...\n"; +($stdout, $stderr, $exit) = $ssh->cmd("tar czvf $config{remote_db_name}.tar.gz $config{remote_db_name}.sql"); +print $stdout; + +# Download DB + +print "Downloading DB...\n"; +my $scp = Net::SCP->new($config{remote_host}, $config{remote_user}); +$scp->get("$config{remote_db_name}.tar.gz"); + +print "Unpacking DB...\n"; +`tar -xzvf $config{remote_db_name}.tar.gz`; + +print "Loading DB...\n"; +`mysql -u$config{local_db_user} -p$config{local_db_pass} $config{local_db_name} < $config{remote_db_name}.sql`; +print "Finished!\n"; + + +Growl::NotifySend->show( + summary => "DB Import", + body => "Finished", +); diff --git a/prj-upload-db.pl b/prj-upload-db.pl new file mode 100755 index 0000000..d49479c --- /dev/null +++ b/prj-upload-db.pl @@ -0,0 +1,52 @@ +#!/usr/bin/env perl + +# Uploads local database to the remote server using ssh + +use strict; +use warnings; +use Config::General; +use Net::SSH::Perl; +use Net::SCP; +use Growl::NotifySend; + +my $conf = new Config::General("config"); +my %config = $conf->getall; + +# backup local db +print "Dumping Local DB...\n"; +`mysqldump -C -u$config{local_db_user} -p$config{local_db_pass} $config{local_db_name} > $config{remote_db_name}.sql`; + +print "Compressing DB...\n"; +`tar -xzvf $config{remote_db_name}.tar.gz`; + +# upload db +print "Uploading DB...\n"; +my $scp = Net::SCP->new($config{remote_host}, $config{remote_user}); +$scp->put("$config{remote_db_name}.tar.gz"); + +print "Logging to $config{remote_host}...\n"; +my $ssh = Net::SSH::Perl->new($config{remote_host}, debug=>0); +$ssh->login($config{remote_user}, $config{remote_pass}); + +print "Unpacking DB...\n"; +my ($stdout, $stderr, $exit) = $ssh->cmd("tar -xzvf $config{remote_db_name}.tar.gz"); +print $stdout; + +print "Loading DB...\n"; +($stdout, $stderr, $exit) = $ssh->cmd("mysql -u$config{remote_db_user} -p$config{remote_db_pass} $config{remote_db_name} < $config{remote_db_name}.sql"); + +print "$stdout\n"; +print "$stderr\n"; +print "Finished!\n"; + +Growl::NotifySend->show( + summary => "DB Upload", + body => "Finished", +); +#if [ $? -eq 255 ]; then +# notify-send "Aktualizacja bazy danych nieudana" \ +# "Skrypt aktualizacyjny bazę na serwerze zdalnym\nzakończył swoją pracę z błędem." +# exit +#fi +# +#notify-send "Powodzenie wgrywania bazy danych" "Skrypt aktualizacyjny bazę na serwerze zdalnym\nzakończył swoją pracę z sukcesem." -- 2.30.2