Initial commit.
authorRafał Długołęcki <kontakt@dlugolecki.net.pl>
Tue, 26 Feb 2013 04:44:43 +0000 (05:44 +0100)
committerRafał Długołęcki <kontakt@dlugolecki.net.pl>
Tue, 26 Feb 2013 04:44:43 +0000 (05:44 +0100)
prj-import-db.pl [new file with mode: 0755]
prj-upload-db.pl [new file with mode: 0755]

diff --git a/prj-import-db.pl b/prj-import-db.pl
new file mode 100755 (executable)
index 0000000..ad956e9
--- /dev/null
@@ -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 (executable)
index 0000000..d49479c
--- /dev/null
@@ -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."