Export & Import Data
Overview
Two scripts are provided with N2ACD to manage data from the command line:
export_entities.plexports N2ACD data in either or both of TOML and plain text format.import_entities.plimports exported data into the N2ACD database.
Running either program with the --help command line option will show usage instructions.
Exporting Entities
Entities may be exported with the following syntax:
perl /usr/share/n2acd/bin/export_entities.pl --db-* [parameters] --type <type> [--<id|key> <identifier> | --all]
Export Parameters
The following parameters are supported when exporting entities:
| Parameter | Type | Description |
|---|---|---|
--typeor -t |
String | [Required] The type of entity to export, case-insensitive. |
--idor -i |
Integer | [Conditional] The internal database ID of an entity of the specified type to export. May be specified multiple times. At least one of --id, --key, or --all is required. |
--keyor -k |
Strung | [Conditional] The key of an entity of the specified type to export, case-sensitive. May be specified multiple times. At least one of --id, --key, or --all is required. |
--allor -a |
Switch | [Conditional] If specified, all entities of the given type will be exported. Overrides --id and --key. At least one of --id, --key, or --all is required. |
--shallowor -s |
Switch | If specified, any child records of exported entities will not be included. (Default: not set, export all related child records) |
--outputor -o |
String | The output file name and path for TOML output suitable for importing. (Default: do not produce TOML output) |
--quietor -q |
Switch | If specified, disables “pretty” (non-TOML) output of exported data to STDOUT. Header and summary information will always be printed. Pretty output cannot be used to import exported entities. (Default: show exported data) |
--db-hostor -h |
String | N2ACD source database host name or IP address. (Default: localhost) |
--db-portor -p |
Integer | N2ACD source database port. (Default: 5432) |
--db-nameor -n |
String | N2ACD source database name. (Default: n2in) |
--db-connector -b |
String | Alternative to --db-host, --db-port, and --db-name. Specified as a PostgreSQL connection string. See PostgreSQL Connection Strings for more information.(Default: generated from --db-host, --db-port, and --db-name) |
--db-useror -u |
String | N2ACD source database user name. (Default: n2acd_owner) |
--db-passwordor -P |
String | N2ACD source database user password. (Default: use details from ~/.pgpass) |
Export Entity Types
The following options are available when specifying the entity type to export. For each entity type,
the applicable target for the key parameter is also given.
| N2ACD Entity Type | Type Value | Child Of | Key Target |
|---|---|---|---|
| Customers | customer |
- | Customer name |
| Services | service |
Customer | Service digits |
| Flows (including versions) | flow |
Customer | Flow name |
| Announcements | announcement |
Customer | Announcement name |
| Geography sets | geography |
Customer | Geography set name |
| Holiday sets | holiday |
Customer | Holiday set name |
| Speed Dial sets | sd |
Customer | Speed Dial set name |
| Flow Node Restriction sets | fnr |
Customer | Flow Node Restriction set name |
| Termination Number Range sets | tnr |
Customer | Termination Number Range set name |
| Account Code sets | ac |
Customer | Account Code set name |
| Prefix Mapping sets | prefix |
- | Prefix Mapping set name |
| Alternative Termination Numbers | atn |
Customer | Source number |
| Flow Version Schedules | schedule |
Customer | Service digits |
Importing Entities
Entities may be imported from a generated export with the following syntax:
perl /usr/share/n2acd/bin/import_entites.pl -i <path to import file> [options]
All entities within the specified file will be imported.
Note that:
- Database IDs are not preserved on import. New IDs will be assigned in all cases.
- Existing entities will not be overwritten or updated.
Import Parameters
The following parameters are supported when importing entities:
| Parameter | Type | Description |
|---|---|---|
--inputor -i |
String | [Required] The import file name and path. |
--actualor -a |
Switch | If specified, actually performs the import process. If not specified, a dry-run will be performed and a summary of the expected outcome given. No database insertion or rollback will occur. Note that a dry run containing multiple record types may report failures if a later entity depends on a previous one, e.g. a flow version using a holiday set that is only created by this import. In such cases, export the entity types separately or split the TOML import file manually. (Default: perform a dry-run) |
--skip-existingor -s |
Switch | If specified, any existing records in the target database matching import data or duplicate records in the import data will be skipped. Otherwise, any existing data will cause the import process to halt. Note that skipped entities may still have other owned import data added to the database. (Default: halt and rollback on duplicate data) |
--skip-bad-refor -r |
Switch | If specified, any records in the import data that have a reference to an entity that is not in the target database or import data will be ignored. Otherwise, any non-existent reference will cause the import process to halt. (Default: halt and rollback on invalid references) |
--skip-invalidor -v |
Switch | If specified, any records in the import data that are invalid (e.g. missing a required field) will be skipped. Otherwise, any invalid import data will cause the import process to halt.. (Default: halt and rollback on invalid import data) |
--commit-allor -c |
Switch | If specified, database commit (if not a dry run) will occur only after all import data has been processed. Otherwise, imported entities are committed to the database individually in the following order:
(Default: commit entities individually) |
--import-useror -U |
String | Database record creation user for auditing. (Default: Entity Import) |
--quietor -q |
Switch | If specified, per-entity validation and insertion results will not be shown. The pre-import header, import warnings, and the post-import summary will always be displayed. (Default: show imported data) |
--db-hostor -h |
String | N2ACD source database host name or IP address. (Default: localhost) |
--db-portor -p |
Integer | N2ACD source database port. (Default: 5432) |
--db-nameor -n |
String | N2ACD source database name. (Default: n2in) |
--db-connector -b |
String | Alternative to --db-host, --db-port, and --db-name. Specified as a PostgreSQL connection string. See PostgreSQL Connection Strings for more information.(Default: generated from --db-host, --db-port, and --db-name) |
--db-useror -u |
String | N2ACD source database user name. (Default: n2acd_owner) |
--db-passwordor -P |
String | N2ACD source database user password. (Default: use details from ~/.pgpass) |