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");
27 print "Logging to $config{remote_host}...\n";
28 my $ssh = Net::SSH::Perl->new($config{remote_host}, debug=>0);
29 $ssh->login($config{remote_user}, $config{remote_pass});
31 print "Unpacking DB...\n";
32 my ($stdout, $stderr, $exit) = $ssh->cmd("tar -xzvf $config{remote_db_name}.tar.gz");
35 print "Loading DB...\n";
36 ($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");
42 Growl::NotifySend->show(
43 summary => "DB Upload",
46 #if [ $? -eq 255 ]; then
47 # notify-send "Aktualizacja bazy danych nieudana" \
48 # "Skrypt aktualizacyjny bazę na serwerze zdalnym\nzakończył swoją pracę z błędem."
52 #notify-send "Powodzenie wgrywania bazy danych" "Skrypt aktualizacyjny bazę na serwerze zdalnym\nzakończył swoją pracę z sukcesem."