Merge branch 'ent-9124-paradas-planificadas-no-se-borran-de-db' into 'develop'
Delete old data from tplanned_downtime. See merge request artica/pandorafms!5091
This commit is contained in:
commit
35ee6936d6
|
@ -40,6 +40,9 @@ my $version = "7.0NG.764 Build 220927";
|
||||||
# Pandora server configuration
|
# Pandora server configuration
|
||||||
my %conf;
|
my %conf;
|
||||||
|
|
||||||
|
# History DB configuration
|
||||||
|
my $h_conf;
|
||||||
|
|
||||||
# Long operations are divided in XX steps for performance
|
# Long operations are divided in XX steps for performance
|
||||||
my $BIG_OPERATION_STEP = 100; # 100 is default
|
my $BIG_OPERATION_STEP = 100; # 100 is default
|
||||||
|
|
||||||
|
@ -73,8 +76,8 @@ sub log_message ($$;$) {
|
||||||
########################################################################
|
########################################################################
|
||||||
# Delete old data from the database.
|
# Delete old data from the database.
|
||||||
########################################################################
|
########################################################################
|
||||||
sub pandora_purgedb ($$) {
|
sub pandora_purgedb ($$$) {
|
||||||
my ($conf, $dbh) = @_;
|
my ($conf, $dbh, $h_conf) = @_;
|
||||||
|
|
||||||
# 1) Obtain last value for date limit
|
# 1) Obtain last value for date limit
|
||||||
# 2) Delete all elements below date limit
|
# 2) Delete all elements below date limit
|
||||||
|
@ -141,13 +144,13 @@ sub pandora_purgedb ($$) {
|
||||||
|
|
||||||
# Delete sessions data
|
# Delete sessions data
|
||||||
pandora_delete_old_session_data (\%conf, $dbh, $ulimit_timestamp);
|
pandora_delete_old_session_data (\%conf, $dbh, $ulimit_timestamp);
|
||||||
|
|
||||||
# Delete old inventory data
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log_message ('PURGE', 'days_purge is set to 0. Old data will not be deleted.');
|
log_message ('PURGE', 'days_purge is set to 0. Old data will not be deleted.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pandora_delete_old_tplanned_downtime(\%conf, $dbh, $h_conf);
|
||||||
|
|
||||||
# String data deletion
|
# String data deletion
|
||||||
if (!defined($conf->{'_string_purge'})){
|
if (!defined($conf->{'_string_purge'})){
|
||||||
$conf->{'_string_purge'} = 7;
|
$conf->{'_string_purge'} = 7;
|
||||||
|
@ -1024,6 +1027,33 @@ sub pandora_delete_old_export_data {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Delete old data from tplanned_downtime.
|
||||||
|
##############################################################################
|
||||||
|
sub pandora_delete_old_tplanned_downtime {
|
||||||
|
my ($conf, $dbh, $h_conf) = @_;
|
||||||
|
|
||||||
|
# Use the configuration from the history DB if available, which should be
|
||||||
|
# less restrictive.
|
||||||
|
my $days_purge = $conf->{'_days_purge'};
|
||||||
|
if (defined($h_conf) &&
|
||||||
|
defined($h_conf->{'_days_purge'}) &&
|
||||||
|
$h_conf->{'_days_purge'} > 0) {
|
||||||
|
$days_purge = $h_conf->{'_days_purge'};
|
||||||
|
}
|
||||||
|
|
||||||
|
# _days_purge was not configured.
|
||||||
|
return unless $days_purge > 0;
|
||||||
|
|
||||||
|
my $ulimit_timestamp = time() - (86400 * $days_purge);
|
||||||
|
|
||||||
|
log_message ('PURGE', "Deleting data older than $days_purge days from tplanned_downtime.");
|
||||||
|
|
||||||
|
db_do($dbh, "DELETE FROM tplanned_downtime
|
||||||
|
WHERE type_execution = 'once'
|
||||||
|
AND date_to < ?", $ulimit_timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Delete old session data.
|
# Delete old session data.
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
@ -1114,13 +1144,13 @@ sub pandoradb_history ($$) {
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Main
|
# Main
|
||||||
###############################################################################
|
###############################################################################
|
||||||
sub pandoradb_main ($$$;$) {
|
sub pandoradb_main {
|
||||||
my ($conf, $dbh, $history_dbh) = @_;
|
my ($conf, $dbh, $h_conf, $history_dbh) = @_;
|
||||||
|
|
||||||
log_message ('', "Starting at ". strftime ("%Y-%m-%d %H:%M:%S", localtime()) . "\n");
|
log_message ('', "Starting at ". strftime ("%Y-%m-%d %H:%M:%S", localtime()) . "\n");
|
||||||
|
|
||||||
# Purge
|
# Purge
|
||||||
pandora_purgedb ($conf, $dbh);
|
pandora_purgedb ($conf, $dbh, $h_conf);
|
||||||
|
|
||||||
# Consistency check
|
# Consistency check
|
||||||
pandora_checkdb_consistency ($conf, $dbh);
|
pandora_checkdb_consistency ($conf, $dbh);
|
||||||
|
@ -1223,6 +1253,7 @@ if (defined($conf{'_history_db_enabled'}) && $conf{'_history_db_enabled'} eq '1'
|
||||||
eval {
|
eval {
|
||||||
$conf{'encryption_key'} = enterprise_hook('pandora_get_encryption_key', [\%conf, $conf{'encryption_passphrase'}]);
|
$conf{'encryption_key'} = enterprise_hook('pandora_get_encryption_key', [\%conf, $conf{'encryption_passphrase'}]);
|
||||||
$history_dbh = db_connect ($conf{'dbengine'}, $conf{'_history_db_name'}, $conf{'_history_db_host'}, $conf{'_history_db_port'}, $conf{'_history_db_user'}, pandora_output_password(\%conf, $conf{'_history_db_pass'}));
|
$history_dbh = db_connect ($conf{'dbengine'}, $conf{'_history_db_name'}, $conf{'_history_db_host'}, $conf{'_history_db_port'}, $conf{'_history_db_user'}, pandora_output_password(\%conf, $conf{'_history_db_pass'}));
|
||||||
|
$h_conf = pandoradb_load_history_conf($history_dbh);
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
if (is_offline(\%conf)) {
|
if (is_offline(\%conf)) {
|
||||||
|
@ -1271,12 +1302,11 @@ if ($lock == 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
pandoradb_main(\%conf, $dbh, $history_dbh);
|
pandoradb_main(\%conf, $dbh, $h_conf, $history_dbh);
|
||||||
|
|
||||||
# history_dbh is unset in pandoradb_main if not in use.
|
# history_dbh is unset in pandoradb_main if not in use.
|
||||||
if (defined($history_dbh)) {
|
if (defined($history_dbh)) {
|
||||||
log_message('', " [>] DB Tool running on historical database.\n");
|
log_message('', " [>] DB Tool running on historical database.\n");
|
||||||
my $h_conf = pandoradb_load_history_conf($history_dbh);
|
|
||||||
|
|
||||||
# Keep base settings.
|
# Keep base settings.
|
||||||
$h_conf->{'_onlypurge'} = $conf{'_onlypurge'};
|
$h_conf->{'_onlypurge'} = $conf{'_onlypurge'};
|
||||||
|
|
Loading…
Reference in New Issue