Skip to main content

Overview

A complete NMIS backup includes configuration files, MongoDB database, and RRD performance data. This guide covers backup procedures, automation, and disaster recovery.

What to Back Up

Critical Data

  1. Configuration Files
    • Location: /usr/local/nmis9/conf/
    • Includes: Config.nmis, Access.nmis, Table-*.nmis, custom configurations
    • Size: Typically < 10 MB
  2. MongoDB Database
    • Database: nmisng
    • Contains: Node configs, events, inventory, operational data
    • Size: Varies (100 MB - 100+ GB depending on nodes and retention)
  3. RRD Files
    • Location: /usr/local/nmis9/database/ or custom database_root
    • Contains: Historical performance data
    • Size: Varies greatly (GB - TB depending on nodes and history)

Optional Data

  1. Custom Scripts and Models
    • Location: /usr/local/nmis9/models/, /usr/local/nmis9/conf/plugins/
    • Custom device models and plugin scripts
  2. Logs (for troubleshooting)
    • Location: /usr/local/nmis9/logs/
    • Recent logs may be useful for issue diagnosis
  3. Web Customizations
    • Location: /usr/local/nmis9/htdocs/, /usr/local/nmis9/menu/
    • Custom dashboards and menu items

Backup Procedures

Configuration Backup

NMIS provides a built-in configuration backup command:
/usr/local/nmis9/bin/nmis-cli act=config-backup
This creates a timestamped backup in /usr/local/nmis9/conf/config-backups/.
1

Manual configuration backup

sudo tar czf /backup/nmis-config-$(date +%Y%m%d-%H%M%S).tar.gz \
  /usr/local/nmis9/conf/
2

Verify backup

tar tzf /backup/nmis-config-*.tar.gz | head -20

Database Backup

Using mongodump

1

Create database backup

sudo mongodump \
  --db nmisng \
  --username nmisng \
  --password '<password>' \
  --out /backup/mongodb/$(date +%Y%m%d-%H%M%S)
2

Compress backup

cd /backup/mongodb
sudo tar czf nmisng-$(date +%Y%m%d-%H%M%S).tar.gz $(date +%Y%m%d-%H%M%S)/
sudo rm -rf $(date +%Y%m%d-%H%M%S)/
3

Verify backup

tar tzf /backup/mongodb/nmisng-*.tar.gz | head -20

With Authentication

If MongoDB requires authentication:
sudo mongodump \
  --host localhost:27017 \
  --db nmisng \
  --username nmisng \
  --password '<password>' \
  --authenticationDatabase nmisng \
  --gzip \
  --archive=/backup/mongodb/nmisng-$(date +%Y%m%d-%H%M%S).gz

Database Backup with Credentials from Config

#!/bin/bash
# Extract credentials from NMIS config
DB_USER=$(perl -ne 'print $1 if /db_username.*=>.*["'\''](.*?)["'\'']/;' \
  /usr/local/nmis9/conf/Config.nmis)
DB_PASS=$(perl -ne 'print $1 if /db_password.*=>.*["'\''](.*?)["'\'']/;' \
  /usr/local/nmis9/conf/Config.nmis)

mongodump \
  --db nmisng \
  --username "$DB_USER" \
  --password "$DB_PASS" \
  --gzip \
  --archive=/backup/mongodb/nmisng-$(date +%Y%m%d).gz
For encrypted passwords in Config.nmis, you’ll need to decrypt them first or use the NMIS API.

RRD Data Backup

RRD files can be very large. Consider selective backup strategies:

Full RRD Backup

sudo tar czf /backup/rrd/nmis-rrd-$(date +%Y%m%d).tar.gz \
  /usr/local/nmis9/database/ \
  --exclude='*.tmp' \
  --exclude='*.log'

Incremental RRD Backup

Using rsync for incremental backups:
sudo rsync -av --delete \
  /usr/local/nmis9/database/ \
  /backup/rrd/nmis-database/

Critical Nodes Only

Back up only critical node data:
sudo tar czf /backup/rrd/nmis-rrd-critical-$(date +%Y%m%d).tar.gz \
  $(find /usr/local/nmis9/database/ -type d -name "core-*" -o -name "critical-*")

Complete System Backup

Full backup of all NMIS data:
#!/bin/bash
BACKUP_DIR="/backup/nmis"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BACKUP_PATH="$BACKUP_DIR/$TIMESTAMP"

mkdir -p "$BACKUP_PATH"

# Configuration
tar czf "$BACKUP_PATH/config.tar.gz" /usr/local/nmis9/conf/

# Database
mongodump \
  --db nmisng \
  --username nmisng \
  --password '<password>' \
  --gzip \
  --archive="$BACKUP_PATH/database.gz"

# RRD files (optional - can be very large)
# tar czf "$BACKUP_PATH/rrd.tar.gz" /usr/local/nmis9/database/

# Create manifest
echo "NMIS Backup - $TIMESTAMP" > "$BACKUP_PATH/backup.manifest"
echo "Configuration: $(ls -lh $BACKUP_PATH/config.tar.gz)" >> "$BACKUP_PATH/backup.manifest"
echo "Database: $(ls -lh $BACKUP_PATH/database.gz)" >> "$BACKUP_PATH/backup.manifest"

# Cleanup old backups (keep 7 days)
find "$BACKUP_DIR" -type d -mtime +7 -exec rm -rf {} \;

echo "Backup completed: $BACKUP_PATH"

Automated Backups

Cron Job for Daily Backups

Create /etc/cron.d/nmis-backup:
# Daily NMIS backups at 2 AM
0 2 * * * root /usr/local/nmis9/admin/backup-nmis.sh >> /var/log/nmis-backup.log 2>&1

Backup Script Example

Create /usr/local/nmis9/admin/backup-nmis.sh:
#!/bin/bash
set -e

# Configuration
BACKUP_BASE="/backup/nmis"
RETENTION_DAYS=30
NOTIFY_EMAIL="[email protected]"

# Logging
LOG_FILE="/var/log/nmis-backup.log"
exec 1> >(tee -a "$LOG_FILE")
exec 2>&1

echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting NMIS backup"

# Create timestamped backup directory
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BACKUP_DIR="$BACKUP_BASE/$TIMESTAMP"
mkdir -p "$BACKUP_DIR"

# Backup configuration
echo "Backing up configuration..."
tar czf "$BACKUP_DIR/nmis-config.tar.gz" \
  /usr/local/nmis9/conf/ \
  /usr/local/nmis9/models/ \
  /usr/local/nmis9/menu/ \
  2>/dev/null || echo "Warning: Some config files may be missing"

# Backup database
echo "Backing up database..."
DB_USER=$(awk -F\" '/db_username/ {print $2}' /usr/local/nmis9/conf/Config.nmis)
mongodump \
  --db nmisng \
  --username "$DB_USER" \
  --password "$DB_PASS" \
  --gzip \
  --archive="$BACKUP_DIR/nmis-database.gz" \
  2>&1 | grep -v "warning: using a password"

# Backup critical nodes RRD data (optional)
# Uncomment if needed:
# echo "Backing up RRD data..."
# tar czf "$BACKUP_DIR/nmis-rrd.tar.gz" /usr/local/nmis9/database/

# Create backup info file
cat > "$BACKUP_DIR/backup.info" <<EOF
Backup Date: $(date)
Hostname: $(hostname)
NMIS Version: $(/usr/local/nmis9/bin/nmis-cli --version 2>/dev/null || echo "Unknown")
Configuration Size: $(du -h "$BACKUP_DIR/nmis-config.tar.gz" | cut -f1)
Database Size: $(du -h "$BACKUP_DIR/nmis-database.gz" | cut -f1)
EOF

# Set permissions
chmod 600 "$BACKUP_DIR"/*

# Cleanup old backups
echo "Cleaning up backups older than $RETENTION_DAYS days..."
find "$BACKUP_BASE" -type d -name "20*" -mtime +$RETENTION_DAYS -exec rm -rf {} \; 2>/dev/null || true

# Calculate sizes
BACKUP_SIZE=$(du -sh "$BACKUP_DIR" | cut -f1)
TOTAL_SIZE=$(du -sh "$BACKUP_BASE" | cut -f1)

echo "[$(date '+%Y-%m-%d %H:%M:%S')] Backup completed successfully"
echo "Backup location: $BACKUP_DIR"
echo "Backup size: $BACKUP_SIZE"
echo "Total backup usage: $TOTAL_SIZE"

# Send notification email
if command -v mail &> /dev/null && [ -n "$NOTIFY_EMAIL" ]; then
  echo "NMIS backup completed successfully on $(hostname) at $(date)" | \
    mail -s "NMIS Backup Success" "$NOTIFY_EMAIL"
fi

exit 0
Make it executable:
sudo chmod +x /usr/local/nmis9/admin/backup-nmis.sh

Restore Procedures

Restore Configuration

1

Stop NMIS services

sudo systemctl stop nmis9d
2

Backup current configuration

sudo mv /usr/local/nmis9/conf /usr/local/nmis9/conf.old
3

Extract backup

sudo tar xzf /backup/nmis-config-20240115.tar.gz -C /
4

Fix permissions

sudo /usr/local/nmis9/bin/nmis-cli act=fixperms
5

Start NMIS services

sudo systemctl start nmis9d

Restore Database

Restoring the database will overwrite all current data. Ensure you have a current backup before proceeding.
1

Stop NMIS services

sudo systemctl stop nmis9d
2

Drop existing database (optional)

If you want a clean restore:
mongo nmisng --eval "db.dropDatabase()"
3

Restore from backup

For gzip archive:
sudo mongorestore \
  --db nmisng \
  --username nmisng \
  --password '<password>' \
  --gzip \
  --archive=/backup/mongodb/nmisng-20240115.gz
For directory dump:
sudo mongorestore \
  --db nmisng \
  --username nmisng \
  --password '<password>' \
  /backup/mongodb/20240115/nmisng/
4

Verify restore

mongo nmisng --eval "db.nodes.count()"
mongo nmisng --eval "db.events.count()"
5

Rebuild indexes

/usr/local/nmis9/bin/nmis-cli act=ensure-indexes
6

Start NMIS services

sudo systemctl start nmis9d

Restore RRD Data

1

Stop NMIS services

sudo systemctl stop nmis9d
2

Backup current RRD data

sudo mv /usr/local/nmis9/database /usr/local/nmis9/database.old
3

Extract RRD backup

sudo tar xzf /backup/rrd/nmis-rrd-20240115.tar.gz -C /
4

Fix permissions

sudo chown -R nmis:nmis /usr/local/nmis9/database
sudo chmod -R 775 /usr/local/nmis9/database
5

Start NMIS services

sudo systemctl start nmis9d

Complete System Restore

For disaster recovery:
1

Install NMIS

Install NMIS on new system (same version as backup).
2

Stop services

sudo systemctl stop nmis9d mongod
3

Restore configuration

sudo tar xzf /backup/config.tar.gz -C /
4

Restore database

sudo mongorestore \
  --db nmisng \
  --gzip \
  --archive=/backup/database.gz
5

Restore RRD data (if backed up)

sudo tar xzf /backup/rrd.tar.gz -C /
6

Fix permissions

sudo /usr/local/nmis9/bin/nmis-cli act=fixperms
7

Start services

sudo systemctl start mongod nmis9d
8

Verify system

/usr/local/nmis9/bin/nmis-cli act=status
sudo systemctl status nmis9d

Backup Verification

Regularly test your backups:

Verify Configuration Backup

# List contents
tar tzf /backup/nmis-config-latest.tar.gz

# Extract to temp directory
mkdir /tmp/verify-config
tar xzf /backup/nmis-config-latest.tar.gz -C /tmp/verify-config
ls -la /tmp/verify-config/usr/local/nmis9/conf/

Verify Database Backup

# Test restore to temporary database
mongorestore \
  --db nmisng_test \
  --gzip \
  --archive=/backup/mongodb/nmisng-latest.gz

# Verify data
mongo nmisng_test --eval "db.nodes.count()"

# Clean up
mongo nmisng_test --eval "db.dropDatabase()"

Automated Backup Testing

Create a monthly test restore job:
#!/bin/bash
# Test backup restore on 1st of each month
TEST_DB="nmisng_restore_test_$(date +%Y%m)"

# Restore to test database
mongorestore --db "$TEST_DB" --gzip --archive=/backup/mongodb/nmisng-latest.gz

# Verify
NODE_COUNT=$(mongo "$TEST_DB" --quiet --eval "db.nodes.count()")
EVENT_COUNT=$(mongo "$TEST_DB" --quiet --eval "db.events.count()")

echo "Backup test $(date): Nodes: $NODE_COUNT, Events: $EVENT_COUNT"

# Cleanup
mongo "$TEST_DB" --eval "db.dropDatabase()"

if [ $NODE_COUNT -gt 0 ]; then
  echo "Backup verification PASSED"
else
  echo "Backup verification FAILED" | mail -s "NMIS Backup Test Failed" [email protected]
fi

Offsite Backup

Rsync to Remote Server

# After local backup completes
rsync -avz --delete \
  /backup/nmis/ \
  backup-server:/backup/nmis-server1/

AWS S3 Backup

# Install AWS CLI first
aws s3 sync /backup/nmis/ s3://my-bucket/nmis-backups/$(hostname)/ \
  --storage-class STANDARD_IA \
  --exclude "*.tmp"

Encrypted Backup Transfer

# Encrypt before transfer
tar czf - /usr/local/nmis9/conf/ | \
  gpg --encrypt --recipient [email protected] | \
  ssh backup-server "cat > /backup/nmis-config-$(date +%Y%m%d).tar.gz.gpg"

Disaster Recovery Planning

Recovery Time Objective (RTO)

Typical restore times:
  • Configuration only: 5-10 minutes
  • Configuration + Database: 15-30 minutes
  • Complete system (including RRD): 1-4 hours (depending on data size)

Recovery Point Objective (RPO)

Depends on backup frequency:
  • Daily backups: Up to 24 hours of data loss
  • Hourly backups: Up to 1 hour of data loss
  • Continuous replication: Minimal data loss

DR Checklist

  1. Documented backup procedures
  2. Tested restore procedures
  3. Offsite backup copies
  4. Emergency contact list
  5. System requirements documentation
  6. License and credentials documentation
  7. Recovery timeline estimates

Best Practices

  1. Automate backups with cron jobs
  2. Test restores regularly (monthly minimum)
  3. Keep multiple backup generations (daily, weekly, monthly)
  4. Store backups offsite for disaster recovery
  5. Encrypt sensitive backups before transfer
  6. Monitor backup success with alerts
  7. Document procedures and keep updated
  8. Verify backup integrity with checksums
  9. Maintain backup retention policy (30-90 days typical)
  10. Include backup in monitoring system

Troubleshooting

Backup Failures

Insufficient disk space:
df -h /backup
du -sh /backup/nmis/*
MongoDB authentication failed:
  • Verify credentials in Config.nmis
  • Test manual connection with mongo client
  • Check MongoDB logs: /var/log/mongodb/mongod.log
Tar permission denied:
  • Run backup script as root or with sudo
  • Check directory permissions

Restore Failures

mongorestore errors:
  • Check MongoDB version compatibility
  • Verify database credentials
  • Ensure sufficient disk space
Missing files after restore:
  • Verify backup file integrity
  • Check tar extraction errors
  • Review backup script logs
Services won’t start after restore:
  • Run act=fixperms to fix file permissions
  • Check log files for specific errors
  • Verify MongoDB is running

See Also

Build docs developers (and LLMs) love