3 # Uploads local database to the remote server using ssh
10 use Growl::NotifySend;
12 my $conf = new Config::General("config");
13 my %config = $conf->getall;
16 print "Dumping Local DB...\n";
17 `mysqldump -C -u$config{local_db_user} -p$config{local_db_pass} $config{local_db_name} > $config{remote_db_name}.sql`;
19 print "Compressing DB...\n";
20 `tar -czvf $config{remote_db_name}.tar.gz $config{remote_db_name}.sql`;
23 print "Uploading DB...\n";
24 my $scp = Net::SCP->new($config{remote_host}, $config{remote_user});
25 $scp->put("$config{remote_db_name}.tar.gz") or die $scp->{errstr};
27 print "Logging to $config{remote_host}...\n";
29 $params{port} = $config{remote_port};
32 my $ssh = Net::SSH::Perl->new($config{remote_host}, %params);
33 $ssh->login($config{remote_user}, $config{remote_pass});
35 print "Unpacking DB...\n";
36 my ($stdout, $stderr, $exit) = $ssh->cmd("tar -xzvf $config{remote_db_name}.tar.gz");
41 print "Loading DB...\n";
42 ($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");
48 Growl::NotifySend->show(
49 summary => "DB Upload",
52 #if [ $? -eq 255 ]; then
53 # notify-send "Aktualizacja bazy danych nieudana" \
54 # "Skrypt aktualizacyjny bazę na serwerze zdalnym\nzakończył swoją pracę z błędem."
58 #notify-send "Powodzenie wgrywania bazy danych" "Skrypt aktualizacyjny bazę na serwerze zdalnym\nzakończył swoją pracę z sukcesem."