Skip to content

Daily Backup

gaochan-1 edited this page Nov 6, 2018 · 1 revision

Daily Backup using NewRelic CLI


Daily backup

Daily backup NewRelic Synthetics monitors

It is easy to use the NewRelic CLI to implement daily backup functionality. Reference the following 3 steps to set up daily backup job. It will backup all monitors into a separated folder per day.

Step1
Get the NR CLI executable binary file. Access git repo to get the latest release files. https://github.com/IBM/newrelic-cli/releases

Step2
Download the shell scripts file for backup monitors backup_monitors.sh
Place a proper path according to your real case and change it to executable.
$ chmod a+x backup_monitors.sh

Step3
Create a new cron job in OS to schedule shell scripts you just created. Use crontab -e to add new schedule job. Like this:

0 0 */1 * * NEW_RELIC_APIKEY="xxx-xxxx-xxx" /<your_path>/backup-monitors.sh

NOTE:
Replace xxx-xxxx-xxx with your own NewRelic admin API key
How to get NewRelic admin API key, reference: Access to REST API keys

If you don't want to set the NR API key in cron job configuration. You can set key in backup_monitors.sh, comment out the export NEW_RELIC_APIKEY="xxx-xxxx-xxx" in script file, replace with your API key.

#!/bin/bash

## Can set the NEW_RELIC_APIKEY env here by comment out below export cmd
#export NEW_RELIC_APIKEY="xxx-xxxx-xxx"
...

Quick validation:
Before your cron job enabled, you can manually do a quick validation for backup.

  • 1 Enter the path where your shell script file placed.
  • 2 Execute export NEW_RELIC_APIKEY="xxx-xxxx-xxx" (use your own NR admin REST key)
  • 3 $ ./backup_monitors.sh

    The *.monitor.bak files would be generated under the directory like: ./backup_monitors/YYYYmmdd-HHMMSS

Daily backup NewRelic alert conditions

It similar with backup monitors, just 3 steps can complete. In step 2, use the backup-alert-conditions.sh shell script file. Download the shell scripts backup-alert-conditions.sh for alert conditions backup.

Step1
Get the NR CLI executable binary file. Access git repo to get the latest release files. NewRelic CLI releases

Step2
Download the shell scripts file for backup alert conditions backup-alert-conditions.sh
Place a proper path according to your real case and change it to executable.
$ chmod a+x backup-alert-conditions.sh

Step3
Create a new cron job in OS to schedule shell scripts you just created. Use crontab -e to add new schedule job. Like this:

0 0 */1 * * NEW_RELIC_APIKEY="xxx-xxxx-xxx" /<your_path>/backup-alert-conditions.sh

Daily backup NewRelic dashboards

It similar with backup monitors and alert conditions, just 3 steps can complete. In step 2, use the backup-dashboards.sh shell script file. Download the shell scripts backup-dashboards.sh for dashboards backup.

Clone this wiki locally