cronjob of scheduled backup

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
mansonli
Posts: 60
Joined: Wed Aug 05, 2020 1:54 am

cronjob of scheduled backup

Post by mansonli »

What's the path of cronjob to schedule systems backup locally as shown in attached screenshot?
You do not have the required permissions to view the files attached to this post.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: cronjob of scheduled backup

Post by ssax »

There is no cronjob associated with it, the values are stored in the database as PHP serialized strings:

Code: Select all

mysql -h 127.0.0.1 -uroot -pnagiosxi nagiosxi -e "select * from xi_options where name like 'scheduled%backups';"
It essentially will run this (based on your output):

Code: Select all

/usr/local/nagiosxi/scripts/backup_xi.sh -d /nagios/backups
mansonli
Posts: 60
Joined: Wed Aug 05, 2020 1:54 am

Re: cronjob of scheduled backup

Post by mansonli »

Can enable to receive backup job notification by email in XI admin interface? If there's no such option, is it possible to add this feature by script? Current XI version is 5.4.13.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: cronjob of scheduled backup

Post by ssax »

There isn't currently a built-in way to do this but that's a great idea, I've created a feature request on your behalf:

FR: XI - Add scheduled backups notifications and include the backup job status/logs/size in the notification

Please keep in mind that the decision to implement the enhancement is at the discretion of our development team.

Since there isn't a way to hook into the built-in scheduled backups functionality the only option you have would be to disable your scheduled backups and then write a custom cron job script that does the backup and then mails you the logs/status/etc.
mansonli
Posts: 60
Joined: Wed Aug 05, 2020 1:54 am

Re: cronjob of scheduled backup

Post by mansonli »

ssax wrote:There is no cronjob associated with it, the values are stored in the database as PHP serialized strings:

Code: Select all

mysql -h 127.0.0.1 -uroot -pnagiosxi nagiosxi -e "select * from xi_options where name like 'scheduled%backups';"
It essentially will run this (based on your output):

Code: Select all

/usr/local/nagiosxi/scripts/backup_xi.sh -d /nagios/backups
How to understand the following value for local backup which's output of above command?

67 | scheduled_local_backups | a:9:{s:6:"active";i:1;s:4:"freq";s:5:"daily";s:3:"day";s:1:"0";s:5:"hours";s:2:"02 ";s:4:"mins";s:2:"00";s:3:"dir";s:16:"/nagios/backups/";s:5:"limit";s:1:"7";s:7:"lastrun";i:1606068000;s:7:"nextrun";i:160 6154400;} |
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: cronjob of scheduled backup

Post by benjaminsmith »

Hi,
How to understand the following value for local backup which's output of above command?
It looks like there are some field identifiers in there that are of use to developers. You can see Unix timestamps for the last and next run in that string along with the time settings.
"lastrun";i:1606068000;s:7:"nextrun";i:1606154400;} |
That next run is also available in the GUI.

Regards,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
mansonli
Posts: 60
Joined: Wed Aug 05, 2020 1:54 am

Re: cronjob of scheduled backup

Post by mansonli »

A table nagios.nagios_notifications crashed twice since last month, leading scheduled backup failed to complete. Why it's crashed frequenly than other tables? How to prevent it from crash again?

nagios.nagios_acknowledgements OK
nagios.nagios_commands OK
nagios.nagios_commenthistory OK
nagios.nagios_comments OK
nagios.nagios_configfiles OK
nagios.nagios_configfilevariables OK
nagios.nagios_conninfo OK
nagios.nagios_contact_addresses OK
nagios.nagios_contact_notificationcommands OK
nagios.nagios_contactgroup_members OK
nagios.nagios_contactgroups OK
nagios.nagios_contactnotificationmethods OK
nagios.nagios_contactnotifications OK
nagios.nagios_contacts OK
nagios.nagios_contactstatus OK
nagios.nagios_customvariables OK
nagios.nagios_customvariablestatus OK
nagios.nagios_dbversion OK
nagios.nagios_downtimehistory OK
nagios.nagios_eventhandlers OK
nagios.nagios_externalcommands OK
nagios.nagios_flappinghistory OK
nagios.nagios_host_contactgroups OK
nagios.nagios_host_contacts OK
nagios.nagios_host_parenthosts OK
nagios.nagios_hostchecks OK
nagios.nagios_hostdependencies OK
nagios.nagios_hostescalation_contactgroups OK
nagios.nagios_hostescalation_contacts OK
nagios.nagios_hostescalations OK
nagios.nagios_hostgroup_members OK
nagios.nagios_hostgroups OK
nagios.nagios_hosts OK
nagios.nagios_hoststatus OK
nagios.nagios_instances OK
nagios.nagios_logentries OK
nagios.nagios_notifications
warning : Table is marked as crashed and last repair failed
error : Found key at page -1 that points to record outside datafile
error : Corrupt
nagios.nagios_objects OK
nagios.nagios_processevents OK
nagios.nagios_programstatus OK
nagios.nagios_runtimevariables OK
nagios.nagios_scheduleddowntime OK
nagios.nagios_service_contactgroups OK
nagios.nagios_service_contacts OK
nagios.nagios_service_parentservices OK
nagios.nagios_servicechecks OK
nagios.nagios_servicedependencies OK
nagios.nagios_serviceescalation_contactgroups OK
nagios.nagios_serviceescalation_contacts OK
nagios.nagios_serviceescalations OK
nagios.nagios_servicegroup_members OK
nagios.nagios_servicegroups OK
nagios.nagios_services OK
nagios.nagios_servicestatus OK
nagios.nagios_statehistory OK
nagios.nagios_systemcommands OK
nagios.nagios_timedeventqueue OK
nagios.nagios_timedevents OK
nagios.nagios_timeperiod_timeranges OK
nagios.nagios_timeperiods OK
nagios.tbl_command OK
nagios.tbl_contact OK
nagios.tbl_contactgroup OK
nagios.tbl_contacttemplate OK
nagios.tbl_domain OK
nagios.tbl_host OK
nagios.tbl_hostdependency OK
nagios.tbl_hostescalation OK
nagios.tbl_hostextinfo OK
nagios.tbl_hostgroup OK
nagios.tbl_hosttemplate OK
nagios.tbl_info OK
nagios.tbl_lnkContactToCommandHost OK
nagios.tbl_lnkContactToCommandService OK
nagios.tbl_lnkContactToContactgroup OK
nagios.tbl_lnkContactToContacttemplate OK
nagios.tbl_lnkContactToVariabledefinition OK
nagios.tbl_lnkContactgroupToContact OK
nagios.tbl_lnkContactgroupToContactgroup OK
nagios.tbl_lnkContacttemplateToCommandHost OK
nagios.tbl_lnkContacttemplateToCommandService OK
nagios.tbl_lnkContacttemplateToContactgroup OK
nagios.tbl_lnkContacttemplateToContacttemplate OK
nagios.tbl_lnkContacttemplateToVariabledefinition OK
nagios.tbl_lnkHostToContact OK
nagios.tbl_lnkHostToContactgroup OK
nagios.tbl_lnkHostToHost OK
nagios.tbl_lnkHostToHostgroup OK
nagios.tbl_lnkHostToHosttemplate OK
nagios.tbl_lnkHostToVariabledefinition OK
nagios.tbl_lnkHostdependencyToHost_DH OK
nagios.tbl_lnkHostdependencyToHost_H OK
nagios.tbl_lnkHostdependencyToHostgroup_DH OK
nagios.tbl_lnkHostdependencyToHostgroup_H OK
nagios.tbl_lnkHostescalationToContact OK
nagios.tbl_lnkHostescalationToContactgroup OK
nagios.tbl_lnkHostescalationToHost OK
nagios.tbl_lnkHostescalationToHostgroup OK
nagios.tbl_lnkHostgroupToHost OK
nagios.tbl_lnkHostgroupToHostgroup OK
nagios.tbl_lnkHosttemplateToContact OK
nagios.tbl_lnkHosttemplateToContactgroup OK
nagios.tbl_lnkHosttemplateToHost OK
nagios.tbl_lnkHosttemplateToHostgroup OK
nagios.tbl_lnkHosttemplateToHosttemplate OK
nagios.tbl_lnkHosttemplateToVariabledefinition OK
nagios.tbl_lnkServiceToContact OK
nagios.tbl_lnkServiceToContactgroup OK
nagios.tbl_lnkServiceToHost OK
nagios.tbl_lnkServiceToHostgroup OK
nagios.tbl_lnkServiceToServicegroup OK
nagios.tbl_lnkServiceToServicetemplate OK
nagios.tbl_lnkServiceToVariabledefinition OK
nagios.tbl_lnkServicedependencyToHost_DH OK
nagios.tbl_lnkServicedependencyToHost_H OK
nagios.tbl_lnkServicedependencyToHostgroup_DH OK
nagios.tbl_lnkServicedependencyToHostgroup_H OK
nagios.tbl_lnkServicedependencyToService_DS OK
nagios.tbl_lnkServicedependencyToService_S OK
nagios.tbl_lnkServiceescalationToContact OK
nagios.tbl_lnkServiceescalationToContactgroup OK
nagios.tbl_lnkServiceescalationToHost OK
nagios.tbl_lnkServiceescalationToHostgroup OK
nagios.tbl_lnkServiceescalationToService OK
nagios.tbl_lnkServicegroupToService OK
nagios.tbl_lnkServicegroupToServicegroup OK
nagios.tbl_lnkServicetemplateToContact OK
nagios.tbl_lnkServicetemplateToContactgroup OK
nagios.tbl_lnkServicetemplateToHost OK
nagios.tbl_lnkServicetemplateToHostgroup OK
nagios.tbl_lnkServicetemplateToServicegroup OK
nagios.tbl_lnkServicetemplateToServicetemplate OK
nagios.tbl_lnkServicetemplateToVariabledefinition OK
nagios.tbl_lnkTimeperiodToTimeperiod OK
nagios.tbl_logbook OK
nagios.tbl_mainmenu OK
nagios.tbl_service OK
nagios.tbl_servicedependency OK
nagios.tbl_serviceescalation OK
nagios.tbl_serviceextinfo OK
nagios.tbl_servicegroup OK
nagios.tbl_servicetemplate OK
nagios.tbl_session OK
nagios.tbl_session_locks OK
nagios.tbl_settings OK
nagios.tbl_submenu OK
nagios.tbl_timedefinition OK
nagios.tbl_timeperiod OK
nagios.tbl_user OK
nagios.tbl_variabledefinition OK
nagios.xi_auditlog OK
nagios.xi_commands OK
nagios.xi_eventqueue OK
nagios.xi_events OK
nagios.xi_incidents OK
nagios.xi_meta OK
nagios.xi_options OK
nagios.xi_sysstat OK
nagios.xi_usermeta OK
nagios.xi_users OK
test.cats OK
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: cronjob of scheduled backup

Post by ssax »

Please send me a copy of your profile, you can download it from Admin > System Profile by clicking the Download Profile button.

Send the output of this command (as root):

Code: Select all

sar
What do you have set for all three Optimize Intervals in Admin > Performance Settings > Databases tab?

Additionally, please send the output of these commands:
- NOTE: You may need to adjust the -h 127.0.0.1, the -uroot, and -pnagiosxi in the first command if your DB is offloaded to another server and/or you've changed the root mysql password

Code: Select all

echo "SELECT table_name AS 'Table', round(((data_length + index_length) / 1024 / 1024), 2) 'Size in MB' FROM information_schema.TABLES WHERE table_schema IN ('nagios', 'nagiosql', 'nagiosxi');" | mysql -h 127.0.0.1 -uroot -pnagiosxi --table
This next command may fail, that's okay, not all systems run postgresql, send the output anyways:

Code: Select all

echo "SELECT relname as Table, pg_size_pretty(pg_total_relation_size(relid)) As Size, pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as ExternalSize FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;" | psql nagiosxi nagiosxi
mansonli
Posts: 60
Joined: Wed Aug 05, 2020 1:54 am

Re: cronjob of scheduled backup

Post by mansonli »

Pls read PM message I submitted.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: cronjob of scheduled backup

Post by ssax »

Please go to Admin > Performance Settings > Databases and update ALL THREE Optimize Intervals to 300 and click the Update Settings button, this change will prevent crashing of tables since you have larger databases. If one optimize isn't finished before the next starts you can have crashing of tables.

I would also cleanup these tables to the smallest your able:

Code: Select all

| nagios_logentries | 1531.53 |
| nagios_notifications | 17024.00 |
That nagios_notifications table being so large is likely why you keep seeing it crash, please clean them up following the guide below:

See the below FAQ I wrote:

FAQ: Can I truncate the tables first before proceeding with database repair (if I have crashed tables)?​

You can truncate before repairing the DB, it's up to you. If you want to back it up first, you'll need to repair it. If you don't care, or already have a backup, truncate it first as it will speed up the DB repair process.

NOTE: You may need to adjust the -h 127.0.0.1, the -uroot, and -pnagiosxi in the commands if your DB is housed/stored/offloaded/contained on a different server and/or you've changed the root mysql password​

If you don't care about the data, or already have a backup, you can just truncate the tables which will essentially drop and recreate the table with zero data in it (removing all historical data for the respective reports):

nagios_logentries - Impacts Event Log report length

Code: Select all

mysql -uroot -pnagiosxi -h 127.0.0.1 -B nagios -e 'TRUNCATE TABLE nagios_logentries;'
nagios_statehistory - Impacts the State History report length

Code: Select all

mysql -uroot -pnagiosxi -h 127.0.0.1 -B nagios -e 'TRUNCATE TABLE nagios_statehistory;'
nagios_notifications - Impacts the Notifications report length

Code: Select all

mysql -uroot -pnagiosxi -h 127.0.0.1 -B nagios -e 'TRUNCATE TABLE nagios_notifications;'

These should technically work to clean the DB tables up manually (if the tables aren't crashed, if they ARE crashed, you will need to repair the database FIRST in order to run these queries):

nagios_logentries - Impacts Event Log report length

Code: Select all

mysql -uroot -pnagiosxi -h 127.0.0.1 -B nagios -e 'DELETE FROM nagios_logentries WHERE logentry_time <= (NOW() - INTERVAL 6 MONTH);'
nagios_statehistory - Impacts the State History report length

Code: Select all

mysql -uroot -pnagiosxi -h 127.0.0.1 -B nagios -e 'DELETE FROM nagios_statehistory WHERE state_time <= (NOW() - INTERVAL 6 MONTH);'
nagios_notifications - Impacts the Notifications report length

Code: Select all

mysql -uroot -pnagiosxi -h 127.0.0.1 -B nagios -e 'DELETE FROM nagios_notifications WHERE start_time <= (NOW() - INTERVAL 6 MONTH);'
Then you should go to Admin > Performance Settings > Databases tab and adjust ALL of the retention intervals to meet your business data policy standards to keep them cleaned up as these settings are for adjusting the retention on those DB tables.

I would lower them to the smallest possible level and utilize the XI backup/restore process and the Admin > Scheduled Backups process to offload the backups to another server. Since these XI backups contain database backups you can spin them up to grab the data and report on them if needed.

See here for more information:

https://assets.nagios.com/downloads/nag ... os-XI.pdf​

And here:​

https://assets.nagios.com/downloads/nag ... abase.pdf​
Locked