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).

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

Perform the following steps for the backup operation:

Procedure


Step 1

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

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 backup_postgres.sh script using the following command:

Example:

 user@server:~/cnp_backups$ bash backup_postgres.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:

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

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 Using Crontab

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_postgres.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 Using Script

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

/ONP/Images/restore_postgres.sh

Execute the following command:

 $ sudo bash restore_postgres.sh DB backup archive file path.
For example:
$ 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.