Page 1 of 2

NagiosXI restore problem

Posted: Wed Mar 05, 2014 11:01 pm
by Fred Kroeger
Trying to restore from a XI_backup and have come across a problem

I backup Nagios using

Code: Select all

/usr/local/nagiosxi/scripts/backup_xi.sh -n `/bin/hostname -s`
This creates a file OK that has my hostname in it instead of the timestamp.
Problem is that I can't restore from this. It appears the problem lies with the backup script however.
Looking at my backup file nagios-server.tar.gz I see

Code: Select all

tar -tzOf /store/backups/nagiosxi/nagios-server.tar.gz
1394071014/
1394071014/nagiosql.tar.gz
1394071014/mrtg.cfg
1394071014/nagiosxi.tar.gz
1394071014/httpd/
1394071014/httpd/nagios.conf
1394071014/httpd/nagiosxi.conf
1394071014/httpd/nagiosql.conf
1394071014/nagios.tar.gz
1394071014/mysql/
1394071014/mysql/nagiosql.sql
1394071014/mysql/nagios.sql
1394071014/mrtg.tar.gz
1394071014/pgsql/
1394071014/pgsql/nagiosxi.sql
1394071014/nagiosql-etc.tar.gz
1394071014/logrotate/
1394071014/logrotate/nagiosxi
The Restore script fails because it is expecting to see

Code: Select all

nagios-server/
nagios-server/nagiosql.tar.gz
nagios-server/mrtg.cfg
nagios-server/nagiosxi.tar.gz
nagios-server/httpd/
...
Fred

Re: NagiosXI restore problem

Posted: Thu Mar 06, 2014 10:54 am
by lmiltchev
What happens when you simply run:

Code: Select all

cd /usr/local/nagiosxi/scripts
./backup_xi.sh
Can you restore from this backup?

http://assets.nagios.com/downloads/nagi ... ing_XI.pdf

Re: NagiosXI restore problem

Posted: Thu Mar 06, 2014 8:02 pm
by Fred Kroeger
Everything works fine when I just run the standard Backup as per the docs - Both Backupo & Restore

The problem I'm describing is when I use the -n option and change the name of the backup file.
The Backup completes OK. However when the backup runs it stores all the backup files in a folder that is named using the Timestamp.

When you run the restore command & supply the file name, it is expecting the filename to also be the name of the folder.
So it fails at the very start when it tries to extract the version

Re: NagiosXI restore problem

Posted: Fri Mar 07, 2014 11:19 am
by lmiltchev
So it fails at the very start when it tries to extract the version
It's interesting - I think I followed the same steps, but was not able to recreate the issue.

Code: Select all

[root@localhost scripts]# hostname
localhost.localdomain
cd /usr/local/nagiosxi/scripts
./backup_xi.sh -n `/bin/hostname -s`
[root@localhost scripts]# cd /store/backups/nagiosxi/
[root@localhost nagiosxi]# ll
total 67328
-rw-r--r-- 1 root root 34470838 Mar  7 15:56 1394207655.tar.gz
-rw-r--r-- 1 root root 34471120 Mar  7 15:57 localhost.tar.gz
[root@localhost nagiosxi]# tar -tzOf localhost.tar.gz
1394207830/
1394207830/nagiosql-etc.tar.gz
1394207830/mrtg.cfg
1394207830/pgsql/
1394207830/pgsql/nagiosxi.sql
1394207830/mrtg.tar.gz
1394207830/nagios.tar.gz
1394207830/logrotate/
1394207830/logrotate/nagiosxi
1394207830/httpd/
1394207830/httpd/nagiosql.conf
1394207830/httpd/nagios.conf
1394207830/httpd/nagiosxi.conf
1394207830/mysql/
1394207830/mysql/nagiosql.sql
1394207830/mysql/nagios.sql
1394207830/nagiosxi.tar.gz
1394207830/nagiosql.tar.gz
Next, I deleted all of the hosts/services but localhost from the CCM and applied configuration. Then I was able to restore successfully from the "localhost.tar.gz" backup and get all of the deleted hosts/services back...

Code: Select all

[root@localhost nagiosxi]# cd -
/usr/local/nagiosxi/scripts
[root@localhost scripts]# pwd
/usr/local/nagiosxi/scripts
./restore_xi.sh /store/backups/nagiosxi/localhost.tar.gz
...bla-bla
Restarting database servers...
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
Stopping postgresql service:                               [  OK  ]
Starting postgresql service:                               [  OK  ]
Restoring logrotate config files...
Restoring Apache config files...
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
NPCD started.
Starting ndo2db: done.
Starting nagios: done.

===============
RESTORE COMPLETE
===============
BTW, did you run the backup and restore scripts WITHIN the "scripts" directory, or you used the full path?

Re: NagiosXI restore problem

Posted: Sun Mar 09, 2014 10:24 pm
by Fred Kroeger
I create the backup file
/usr/local/nagiosxi/scripts/backup_xi.sh -n `/bin/hostname -s`

Code: Select all

# tar tzf my-hostname.tar.gz
1394419887/
1394419887/nagiosql.tar.gz
1394419887/mrtg.cfg
1394419887/nagiosxi.tar.gz
1394419887/httpd/

I copy it to the DR server /store/backups/nagiosxi directory
I'm in the /store/backups/nagiosxi directory

Code: Select all

/usr/local/nagiosxi/scripts/restore_xi.sh my-hostname.tar.gz
tar: my-hostname/nagios.tar.gz: Not found in archive
tar: Exiting with failure status due to previous errors

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
WARNING: you are trying to restore a  backup on a 64-bit system
         Plugins and other binaries will NOT be restored.

Are you sure you want to continue? [y/N]
We must be using different versions of restore_xi ? (-rwxr-x--- 1 nagios nagios 5342 Jan 24 09:59 /usr/local/nagiosxi/scripts/restore_xi.sh )

The first step which fails above is when it tries to determine the architecture.

Code: Select all

backuparch=$(tar -xzOf $backupfile $(basename $backupfile .tar.gz)/nagios.tar.gz | tar -xzOf - usr/local/nagios/bin/nagios | file - | grep -Eo '(32|64)-bit')
It is expecting the tar file to look like my-hostname/nagios.tar.gz but as you saw from above it is actually saved as 1394419887/nagios.tar.gz



regards... Fred

Re: NagiosXI restore problem

Posted: Mon Mar 10, 2014 10:49 am
by lmiltchev
I have the exact same line in the "restore_xi.sh":

Code: Select all

backuparch=$(tar -xzOf $backupfile $(basename $backupfile .tar.gz)/nagios.tar.gz | tar -xzOf - usr/local/nagios/bin/nagios | file - | grep -Eo '(32|64)-bit')
I can PM you the "restore_xi.sh" that I am using if you want to take a look at it. Nothing has been modified - it is a new, clean install of Nagios XIR2.9.

Re: NagiosXI restore problem

Posted: Mon Mar 10, 2014 8:58 pm
by Fred Kroeger
Thanks - I'm running 2.8c but if you have the same line then I don't understand why it works for you. Perhaps you can also send the backup script?
I did some hacking on the backup script, so that it uses the filename instead of the timestamp when it creates the backup folder.
This allows the restore script to work as expected.

BTW I remember now that I am using a patched version of the backup script that was posted here because of some SQL password problems?

Fred

Re: NagiosXI restore problem

Posted: Tue Mar 11, 2014 11:25 am
by abrist
Are those edits still present in your backup script? I ask because there is a chance the script is overwritten on an XI update.

Re: NagiosXI restore problem

Posted: Tue Mar 11, 2014 6:23 pm
by Fred Kroeger
The patched backup script was supplied by Nagios so not sure what the "edits" are.

Code: Select all

# ls -la /usr/local/nagiosxi/scripts/backup_xi*
-rwxr-x--- 1 root   root   4874 Mar  6 12:54 /usr/local/nagiosxi/scripts/backup_xi-new.sh
-rwxr-x--- 1 nagios nagios 4710 Feb  3 10:10 /usr/local/nagiosxi/scripts/backup_xi.sh
-rwxr-xr-x 1 root   root   4710 Feb  3 10:09 /usr/local/nagiosxi/scripts/backup_xi.sh-new
-rwxr-x--- 1 nagios nagios 4652 Jan 24 09:59 /usr/local/nagiosxi/scripts/backup_xi.sh-org
Ignore backup_xi-new.sh as this is my hacked script for using the -n optin option as described previously
backup_xi.sh is what gets run every night

So what's the difference between the current script and then original mscript ? - Not much...

Code: Select all

# diff /usr/local/nagiosxi/scripts/backup_xi.sh /usr/local/nagiosxi/scripts/backup_xi.sh-org
3,4d2
< BASEDIR=$(dirname $0)
<
6,8c4,6
< php $BASEDIR/import_xiconfig.php > $BASEDIR/config.dat
< . $BASEDIR/config.dat
< rm -rf $BASEDIR/config.dat
---
> php import_xiconfig.php > config.dat
> . ./config.dat
> rm -rf config.dat
189d186
<

Re: NagiosXI restore problem

Posted: Wed Mar 12, 2014 11:53 am
by lmiltchev
I sent you a PM.