Fixed too long password for mysql. Fixed no enable-drupal target. Fixed no email...
[prj-utils.git] / prj-import-db.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Config::General;
6 use Net::SSH::Perl;
7 use Net::SCP;
8 use Growl::NotifySend;
9
10 my $conf = new Config::General("config");
11 my %config = $conf->getall;
12
13 print "Logging to $config{remote_host}...\n";
14 my $ssh = Net::SSH::Perl->new($config{remote_host}, debug=>0);
15 $ssh->login($config{remote_user}, $config{remote_pass});
16
17 print "Dumping DB...\n";
18 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");
19 print $stdout;
20
21 print "Compressing DB...\n";
22 ($stdout, $stderr, $exit) = $ssh->cmd("tar czvf $config{remote_db_name}.tar.gz $config{remote_db_name}.sql");
23 print $stdout;
24
25 # Download DB
26
27 print "Downloading DB...\n";
28 my $scp = Net::SCP->new($config{remote_host}, $config{remote_user});
29 $scp->get("$config{remote_db_name}.tar.gz");
30
31 print "Unpacking DB...\n";
32 `tar -xzvf $config{remote_db_name}.tar.gz`;
33
34 print "Loading DB...\n";
35 `mysql -u$config{local_db_user} -p$config{local_db_pass} $config{local_db_name} < $config{remote_db_name}.sql`;
36 print "Finished!\n";
37
38
39 Growl::NotifySend->show(
40     summary => "DB Import",
41     body    => "Finished",
42 );