Backup and Restore Cisco ONP Database

Database backups

A database backup is a data protection mechanism that

  • allows system administrators to schedule full database backups at daily, weekly, or monthly intervals,

  • lets only system administrators access backup folders and perform restorations, and

  • stores all backup archives on a highly durable NFS share.

Archive types

Archive types available for database backups include:

  • Daily 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 to meet specific retention needs.

Setup Backup

Before you begin

  • Ensure that a 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 as defined by the Cisco ONP network and configure the appropriate Access Control List (ACL) to permit or deny access to the storage as needed.

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 such as NFS.

Step 3

Copy backup, rotation, and setup backup scripts from ONP/images folder to the new folder created in step 2.

Example:

 $ cd 
$ mkdir cnp_backups
$ tree ~/cnp_backups/
 /home/ciscocnp/cnp_backups/
├── backup_postgres.sh
└── rotation.sh
└── setup_backup.sh

Ensure that all scripts have necessary permissions:

 $ chmod +x backup_postgres.sh 
 $ chmod +x rotation.sh
 $ chmod +x setup_backup.sh
$ ls -l | grep .sh
 -rwxrwxr-x 1 ciscocnp ciscocnp 518 Jan 16 05:23 backup_postgres.sh
-rwxrwxr-x 1 ciscocnp ciscocnp 1412 Feb 1 05:50 rotation.sh

Step 4

Copy restore_postgres.sh from /ONP/images/.


Perform manual backup

Follow these steps to back up the Cisco ONP database.

Procedure


Step 1

Browse to the location where the backup_postgres.sh script is stored.

Step 2

Use the bash rotation.sh command to execute the rotation.sh script.

Example:

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

This command creates the necessary folder structure.

Step 3

Use the bash backup_postgres.sh command to execute the script.

Example:

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

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


Backup scheduling methods

You can schedule a backup using either of these methods:

Schedule a backup using script

Follow these steps to schedule the backup operation using a script.
Procedure

Step 1

Log in to the Cisco ONP server.

Step 2

Use the command bash rotation.sh to execute the rotation.sh script.

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

This command creates the necessary folder structure.

Step 3

Use the command bash setup_backup.sh to execute the setup_backup.sh script.

Example:
 user@server:~/cnp_backups$ bash setup_backup.sh

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

Step 4

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

Backup files are stored in your required file path as shown in this example.
Example:
/user-defined path/backups/backup.daily

Schedule a backup with Crontab

Follow these steps to schedule the backup operation using Crontab.
Procedure

Step 1

Log in to the Cisco ONP server.

Step 2

Use the command sudo crontab -e to configure the Crontab job.

user@server~/cnp_backups$ sudo crontab -e

Step 3

Update the Crontab.shscript with the required cron job entries using the Syntax to schedule the backup using Crontab, to schedule backup operations.

Example:

This example shows the scheduling of the backup operation at 3:00 a.m daily.

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

Syntax to schedule the backup using Crontab

Use this syntax to schedule a backup in Crontab:

m h dom mon dow

Where:

  • m: Minutes (0–59)

  • h: Hours (1–23)

  • dom: Day of the month (1–31)

  • mon: Month of the year (1–12)

  • dow: Day of the week (0–6, where 0 represents Sunday)

To specify the time, you can provide exact values for the minute (m), hour (h), day of the month (dom), month (mon), and day of the week (dow). Alternatively, you can use the wildcard character * in these fields to indicate "any value."


Note


The backup jobs are initiated according to the system daemon's understanding of time and time zones as defined by the cron scheduler.


Restore the database manually

Follow these steps to restore the database manually.

Procedure


Step 1

Check the Cisco ONP Database.

Example:

$ postgres 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:

Example:

```
$ postgres 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 PostgresDB container's volume:

Example:

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

Step 4

Restore the database and check.

Example:

 $ docker exec -t cnp_postgres.1.$(docker service ps -f 'name=cnp_postgres.1' -f 'desired-state=running' cnp_postgres -q) bash -c "postgresrestore -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 a script, which is available at this location:

/ONP/Images/restore_postgres.sh

Follow these steps to restore the database using a script:

Procedure


Use the command sudo bash restore_postgres.sh to restore the database

Example:

 $ sudo bash restore_postgres.sh DB backup archive file path.
$ sudo bash restore_postgres.sh /backups/backup.daily/2019-05-05-23-58.archive
The database backup is created and a confirmation prompt appears asking to delete the database.
!!! WARNING! Complete Restore Operation will replace Existing Database with Backup Database (Recommended) !!!
Do you want Complete Restore? (Yes/No) [default - Yes]

Enter Yes to delete the database and restore the database with backup file.

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


Syntax to schedule the backup using Crontab

Use this syntax to schedule a backup in Crontab:

m h dom mon dow

Where:

  • m: Minutes (0-59)

  • h: Hours (1-23)

  • dom: Day of the month (1-31)

  • mon: Month of the year (1-12)

  • dow: Day of the week (0-6, where 0 represents Sunday)

To specify the time, you can provide exact values for the minute (m), hour (h), day of the month (dom), month (mon), and day of the week (dow); alternatively, you can use the wildcard character * in these fields to indicate "any value."


Note


The backup jobs are initiated according to the system daemon's understanding of time and time zones as defined by the cron scheduler.


Database overload notification

This section describes the databse overloand notification in the Cisco Optical Network Planner tool.
  • Whenever the database is fully overloaded with networks, the subsequent network operations becomes slower such as like opening a network, saving a network, etc.

  • Database overload notification appears whenever these operations are performed. You can take necessary backup of unused networks and delete them.

  • These notifications are enabled by default. These can be disabled via feature.properties file.

  • Two levels of warning notifications appear – Slowness Detected and CONP Server DB capacity Exceeded. Take necessary actions appropriately.

Modify the threshold for database notifications

Use this task to modify the threshold for database notifications.

Procedure


Step 1

Open the feature.properties file.

Step 2

Search for hibernate.slowQuery.logging.enabled and set it to true.

By default, this property is disabled.

Step 3

Modify the properties inside the hibernate.slowQuery.logging.enabled property as follows.

Properties

Description

hibernate.slowQuery.logging.med.threshold.ms Threshold for maximum network count. 5000 is default.
hibernate.slowQuery.logging.high.threshold.ms Threshold for maximum network count. 10000 is default.
hibernate.slowQuery.logging.min.network.count Threshold for maximum network count. 5000 is default.
hibernate.slowQuery.logging.min.sites.count Threshold for maximum sites count. 150000 is default.

The database notification will now appear based on the threshold values that you have set.

Clean the database manually

Use this task to manually clean up the database.

To delete the database, admins or users should manually delete the old networks.

Procedure


Step 1

Choose File > Delete.

The Select Network(s) to Delete window opens.

Step 2

Select the networks as follows.

Options

Description

Search bar

Search for the network to delete.

Select All check box

Select all the networks.

Check box list

Select the old networks.

Step 3

Click Delete.

Warning message appears.

Step 4

Click Yes.


The selected network is deleted.