#!/usr/bin/perl

use strict;
use lib '/app/tools/common/lib';
use Common::RSDB;

foreach my $clientID (keys %Common::RSDB::CLIENT_DB)
{
    my $clientData = $Common::RSDB::CLIENT_DB{$clientID};
    my $host = $clientData->{host_id};
    next unless ('rps01' eq $host || 'rps02' eq $host);

    print "getting client $clientID (".$clientData->{db_name} .") on host $host\n";

    my $extractCommand = "'perl /home/knott/rps_md_dump.pl $clientID > /home/knott/$clientID.md'";
    my $compressCommand = "/bin/gzip /home/knott/$clientID.md";
    my $copyCommand = "/usr/bin/scp knott@".$host.":/home/knott/$clientID.md.gz .";
    my $deleteCommand = "/bin/rm /home/knott/$clientID.md.gz";

    print "\t$extractCommand\n";
    system("ssh knott@".$host." $extractCommand");

    print "\t$compressCommand\n";
    system("ssh knott@".$host." $compressCommand");

    print "\t$copyCommand\n";
    system($copyCommand);

    print "\t$deleteCommand\n";
    system("ssh knott@".$host." $deleteCommand");
    
}
