Private GIT

Skip to content
Snippets Groups Projects
Commit 0f09f9ec authored by Kevin Duret's avatar Kevin Duret
Browse files

Make backup only on central server

parent 7c63a352
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,8 @@ sub print_help(); ...@@ -55,7 +55,8 @@ sub print_help();
sub print_usage(); sub print_usage();
sub trim($); sub trim($);
my $CENTREON_ETC = '@CENTREON_ETC@'; #my $CENTREON_ETC = '@CENTREON_ETC@';
my $CENTREON_ETC = '/etc/centreon';
my @licfiles; my @licfiles;
# Require DB configuration files # Require DB configuration files
...@@ -744,25 +745,6 @@ sub monitoringengineBackup() { ...@@ -744,25 +745,6 @@ sub monitoringengineBackup() {
my $today = sprintf("%d-%02d-%02d",(1900+$year),($mon+1),$mday); my $today = sprintf("%d-%02d-%02d",(1900+$year),($mon+1),$mday);
print "[" . sprintf("%4d-%02d-%02d %02d:%02d:%02d", (1900+$year), ($mon+1), $mday, $hour, $min, $sec) . "] Start monitoring engine backup processus\n"; print "[" . sprintf("%4d-%02d-%02d %02d:%02d:%02d", (1900+$year), ($mon+1), $mday, $hour, $min, $sec) . "] Start monitoring engine backup processus\n";
my $query = "SELECT * FROM cfg_nagios WHERE nagios_activate = '1'";
my $dbh = DBI->connect("DBI:mysql:database=".$mysql_database_oreon.";host=".$mysql_host.";port=".$mysql_port, $mysql_user, $mysql_passwd,{'RaiseError' => 0, 'PrintError' => 0});
if (!$dbh) {
print STDERR sprintf("Couldn't connect: %s", $DBI::errstr) . "\n";
}
my $sth = $dbh->prepare($query);
if (!$sth) {
print STDERR "Error: " . $dbh->errstr . "\n";
}
if (!$sth->execute()) {
print STDERR "Error: " . $dbh->errstr . "\n";
}
if ($sth->rows == 0) {
print STDERR "Unable to get informations about poller form ".$mysql_database_oreon." database" . "\n";
} else {
# Create path # Create path
mkpath($TEMP_POLLERS, {mode => 0755, error => \my $err_list}); mkpath($TEMP_POLLERS, {mode => 0755, error => \my $err_list});
if (@$err_list) { if (@$err_list) {
...@@ -776,23 +758,20 @@ sub monitoringengineBackup() { ...@@ -776,23 +758,20 @@ sub monitoringengineBackup() {
} }
} }
while (my $poller = $sth->fetchrow_hashref) { my $sth2 = $dbh->prepare("SELECT n.nagios_name, n.cfg_dir, n.log_file, n.log_archive_path, ns.* FROM nagios_server ns, cfg_nagios n WHERE ns.id = n.nagios_server_id AND n.nagios_activate = '1' AND ns.localhost = '1';");
my $poller_name = $poller->{nagios_name};
#########################################################
# Get information about poller from nagios_server table #
#########################################################
my $sth2 = $dbh->prepare("SELECT * FROM nagios_server WHERE id = '".$poller->{nagios_server_id}."' AND localhost = '1';");
if (!$sth2->execute()) { if (!$sth2->execute()) {
print STDERR "Error: " . $dbh->errstr . "\n"; print STDERR "Error: " . $dbh->errstr . "\n";
return 1;
} }
my $nagios_server; my $nagios_server;
my $poller_name;
if ($sth2->rows == 0) { if ($sth2->rows == 0) {
print STDERR "Unable to get informations about poller form " . $mysql_database_oreon . " database\n"; print STDERR "Unable to get informations about poller form " . $mysql_database_oreon . " database\n";
return 1;
} else { } else {
$nagios_server = $sth2->fetchrow_hashref; $nagios_server = $sth2->fetchrow_hashref;
$poller_name = $nagios_server->{nagios_name};
$sth2->finish(); $sth2->finish();
} }
...@@ -839,6 +818,7 @@ sub monitoringengineBackup() { ...@@ -839,6 +818,7 @@ sub monitoringengineBackup() {
print STDERR "Unable to copy plugins\n"; print STDERR "Unable to copy plugins\n";
} }
} }
######## ########
# Logs # # Logs #
######## ########
...@@ -854,8 +834,8 @@ sub monitoringengineBackup() { ...@@ -854,8 +834,8 @@ sub monitoringengineBackup() {
} }
} }
copy($poller->{log_file}, ($ACTUAL_POLLER_BCK_DIR."/logs/centengine.log")); copy($nagios_server->{log_file}, ($ACTUAL_POLLER_BCK_DIR."/logs/centengine.log"));
my $logs_archive_directory = substr($poller->{log_archive_path}, 0, rindex($poller->{log_archive_path}, "/")); my $logs_archive_directory = substr($nagios_server->{log_archive_path}, 0, rindex($nagios_server->{log_archive_path}, "/"));
mkpath($ACTUAL_POLLER_BCK_DIR."/logs/archives", {mode => 0755, error => \my $err_list}); mkpath($ACTUAL_POLLER_BCK_DIR."/logs/archives", {mode => 0755, error => \my $err_list});
if (@$err_list) { if (@$err_list) {
for my $diag (@$err_list) { for my $diag (@$err_list) {
...@@ -886,7 +866,7 @@ sub monitoringengineBackup() { ...@@ -886,7 +866,7 @@ sub monitoringengineBackup() {
} }
} }
} }
`cp -pr $poller->{cfg_dir }/* $ACTUAL_POLLER_BCK_DIR/etc/`; `cp -pr $nagios_server->{cfg_dir}/* $ACTUAL_POLLER_BCK_DIR/etc/`;
if ($? != 0) { if ($? != 0) {
print STDERR "Unable to copy Monitoring Engine configuration files\n"; print STDERR "Unable to copy Monitoring Engine configuration files\n";
} }
...@@ -941,7 +921,7 @@ sub monitoringengineBackup() { ...@@ -941,7 +921,7 @@ sub monitoringengineBackup() {
print STDERR "No ssh keys for Monitoring Engine\n"; print STDERR "No ssh keys for Monitoring Engine\n";
} }
################# ##################
# Make archives # # Make archives #
################# #################
`cd $TEMP_DIR && cd .. && tar -czf $BACKUP_DIR/$today-Monitoring-Engine.tar.gz backup`; `cd $TEMP_DIR && cd .. && tar -czf $BACKUP_DIR/$today-Monitoring-Engine.tar.gz backup`;
...@@ -968,8 +948,6 @@ sub monitoringengineBackup() { ...@@ -968,8 +948,6 @@ sub monitoringengineBackup() {
} }
} }
} }
}
}
$sth->finish(); $sth->finish();
$dbh->disconnect; $dbh->disconnect;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment