Backup and Restore Cisco ONP Database

Backup Database

Based on the database backup configuration on the server, as set by the system admins, you can take the backup of the complete database on a daily, weekly, or monthly basis. Only system admins can access the backup folders and restore them. Backup archive is stored on highly durable NFS share. The following backup archives are available:

  • Archives for the last 7 days

  • Weekly archives for the last 4 weeks

  • Monthly archives for the last 6 months


Note


You can change the duration for monthly archives.


Setup Backup

Before you begin

  • Ensure that highly durable 2 TB NFS storage is available to store database archives.

  • Ensure that the storage is accessible from the Cisco ONP environment. Set up rules that are defined by the Cisco ONP network and appropriate ACL (Access Control List) to permit or deny access to the storage.

Procedure


Step 1

Log into the Cisco ONP server, where you have installed Cisco ONP by using the tar archive.

Step 2

Create a folder for backup. Ideally it should be mounted on a reliable object storage (like NFS).


Perform Manual Backup

Perform the following steps for the backup operation:

Procedure


Step 1

Browse to the location, where the backup_mongo.sh script is stored.

Step 2

Execute the backup_mongo.sh script using the following command:

Example:

 user@server:~/cnp_backups$ bash backup_mongo.sh

The backup file gets stored in the daily backup folder (backup.daily) with the current time stamp.


Schedule a Backup

Schedule a Backup Using Script

Use this task to schedule the backup operation using script:
Procedure

Step 1

Log in to the Cisco ONP server.

Step 2

Execute the rotation.sh script using the following command:

user@server:~/cnp_backups$ bash rotation.sh

This command creates necessary folder structure.

Step 3

Execute the setup_backup.sh script using the following command:

Example:

The backup file gets stored in the daily backup folder (backup.daily) with the current time stamp.

Step 4

Enter the path in the user prompt to store the file.

Backup files are stored in your required file path as following:
/user-defined path/backups/backup.daily

Schedule a Backup

Use this task to schedule the backup operation using Crontab:
Procedure

Step 1

Log in to the Cisco ONP server.

Step 2

Configure the Crontab job using the following command.

user@server~/cnp_backups$ sudo crontab -e

Step 3

Modify the Crontab.sh script to schedule the backup.

Example:

The following example shows the scheduling of the backup operation, at 3 a.m daily.

 0 3 * * * /home/ciscocnp/cnp_backups/backup_mongo.sh

Syntax to Schedule the Backup Using Crontab

Use the following syntax to schedule backup in Crontab:

m h dom mon dow

Where:

  • m—Minutes (0–59)

  • h—Hours (1–23)

  • dom—Day of the month

  • mon—Month of the year

  • dow—Day of the week

To define the time, you can provide concrete values for minute (m), hour (h), day of the month (dom), month (mon), and day of the week (dow), or use the wildcard, '*' in these fields (for 'any').


Note


The backup jobs start based on the cron's system daemon's notion of time and time zones.

Restore Database Manually

Use this task to restore the database manually:

Procedure


Step 1

Check the Cisco ONP Database.

$ mongo CnpDB

MongoDB shell version: 2.6.10

connecting to: CnpDB

Server has startup warnings:

2019-01-31T12:17:39.354+0000 I STORAGE [initandlisten]

2019-01-31T12:17:39.354+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine.

2019-01-31T12:17:39.354+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten]

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten]

> show collections

NetworkEntity

SystemLog

BOM

fs.files

Users

fs.chunks

ErrorInfo

NetworkObject

UserGroups

TaskInfo

ActionGroups

Roles

>

```

Step 2

Remove the Cisco ONP back-end and front-end Docker services,"docker service rm cnp_cnp cnp_cnp_frontend" and check again:

```

$ mongo CnpDB

MongoDB shell version: 2.6.10

connecting to: CnpDB

Server has startup warnings:

2019-01-31T12:17:39.354+0000 I STORAGE [initandlisten]

2019-01-31T12:17:39.354+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS file system is strongly recommended with the WiredTiger storage engine.

2019-01-31T12:17:39.354+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten]

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.

2019-01-31T12:17:40.013+0000 I CONTROL [initandlisten]

> show collections

>

```

Step 3

Copy the database to the folder that is mapped to MongoDB container's volume:

 $ sudo cp backups/2019-02-01-04-29.archive /var/lib/mongodb_cnp/

```

Step 4

Restore the database and check.

 $ docker exec -t cnp_mongo.1.$(docker service ps -f 'name=cnp_mongo.1' -f 'desired-state=running' cnp_mongo -q) bash -c "mongorestore -u \$(cat \$MONGO_INITDB_ROOT_USERNAME_FILE) -p \$(cat \$MONGO_INITDB_ROOT_PASSWORD_FILE) --authenticationDatabase admin --port 27017 -h localhost --db CnpDB --gzip --archive=/data/db/2019-02-01-04-29.archive"

Restore Database Using Script

You can restore the database using script, which is available at the following location:

Images/DB_backup/restore_mongo.sh

Execute the following command:

 $ sudo bash restore_mongo.sh DB backup archive file path.
For example:
$ sudo bash restore_mongo.sh /backups/backup.daily/2019-05-05-23-58.archive

Enter No to not delete the database and apply only missing data(s) from backup file.