|
| 1 | +# Configuration Backup |
| 2 | + |
| 3 | +Validity supports device configurations backups to remote **Git** or **S3** server(s). |
| 4 | + |
| 5 | +## Backup provisioning |
| 6 | + |
| 7 | +1. Follow the steps described in the [Quickstart: Polling](../quickstart_polling.md) article to set up all the entities required for device polling. |
| 8 | + |
| 9 | +2. Polling is done when the Data Source is synced. In most cases it will be the default **Validity Polling** Data Source, but you are free to create your own one with the type *device_polling*. |
| 10 | + |
| 11 | +3. Create a [Backup Point](../entities/backuppoints.md) which describes a place where the Data Source with the configs have to be uploaded. |
| 12 | + |
| 13 | +Example using pynetbox: |
| 14 | + |
| 15 | +```python |
| 16 | +import pynetbox |
| 17 | + |
| 18 | +nb = pynetbox.api('http://localhost:8000', token=nb_token) |
| 19 | + |
| 20 | +validity_polling = nb.core.data_sources.get(name="Validity Polling") |
| 21 | + |
| 22 | +nb.plugins.validity.backup_points.create( |
| 23 | + name='my_github_repo', |
| 24 | + data_source=data_source.id, |
| 25 | + upload_url='https://github.com/amyasnikov/my_repo', |
| 26 | + method='git', |
| 27 | + parameters={"username": "amyasnikov", "password": github_token} |
| 28 | +) |
| 29 | +``` |
| 30 | + |
| 31 | +## Backing Up |
| 32 | + |
| 33 | +There are several options to trigger the backup process: |
| 34 | + |
| 35 | +* Press "Back Up" button on the Backup Point page. |
| 36 | + |
| 37 | +* Specify `Backup After Sync: True` in the Backup Point settings. This will trigger the backup process each time the respective data source is being synced (no matter via button, API or somehow else). |
| 38 | + |
| 39 | +* Execute [RunTests](../entities/scripts.md#run-tests) script with `Sync Data Sources: True` option (`Backup After Sync: True` is required as well). |
| 40 | + |
| 41 | + |
| 42 | +### Options for periodic backup |
| 43 | + |
| 44 | +There are several options to provision periodic configuration backup process (e.g. daily, each 6 hours, etc): |
| 45 | + |
| 46 | +1. Provision [RunTests](../entities/scripts.md#run-tests) script to execute on a regular basis using **Interval** script parameter. This will run everything at once: |
| 47 | + * poll the devices (perform data source sync) |
| 48 | + * execute compliance tests |
| 49 | + * back up the data source |
| 50 | + |
| 51 | + |
| 52 | +2. If you don't want to run the tests via scheduler and want backup only, you can create tiny [custom script](https://netboxlabs.com/docs/netbox/en/stable/customization/custom-scripts/) inside your NetBox and configure it to run periodically. |
| 53 | + |
| 54 | +```python |
| 55 | +from core.models import DataSource |
| 56 | +from extras.scripts import Script, ObjectVar |
| 57 | + |
| 58 | +class SyncDataSource(Script): |
| 59 | + data_source = ObjectVar(model=DataSource) |
| 60 | + |
| 61 | + def run(self, data, commit): |
| 62 | + data['data_source'].sync() |
| 63 | + |
| 64 | +``` |
| 65 | + |
| 66 | +Execution of this script triggers the sync of the DataSource (and hence the backup process for bound Backup points with `Backup After Sync: True`). |
| 67 | + |
| 68 | +3. Wait till periodic Data Source sync is implemented in the core NetBox. There is an [issue](https://github.com/netbox-community/netbox/issues/18287) for it, upvotes are appreciated. |
0 commit comments