Export & Import Data

Overview

Two scripts are provided with N2ACD to manage data from the command line:

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
--type
or -t
String [Required] The type of entity to export, case-insensitive.
--id
or -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.
--key
or -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.
--all
or -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.
--shallow
or -s
Switch If specified, any child records of exported entities will not be included.
(Default: not set, export all related child records)
--output
or -o
String The output file name and path for TOML output suitable for importing.
(Default: do not produce TOML output)
--quiet
or -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-host
or -h
String N2ACD source database host name or IP address.
(Default: localhost)
--db-port
or -p
Integer N2ACD source database port.
(Default: 5432)
--db-name
or -n
String N2ACD source database name.
(Default: n2in)
--db-connect
or -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-user
or -u
String N2ACD source database user name.
(Default: n2acd_owner)
--db-password
or -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:

Import Parameters

The following parameters are supported when importing entities:

Parameter Type Description
--input
or -i
String [Required] The import file name and path.
--actual
or -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-existing
or -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-ref
or -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-invalid
or -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-all
or -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:
  1. Customers
  2. Announcements
  3. Geography sets (with all entries)
  4. Holiday sets (with all entries)
  5. Speed dial sets (with all entries)
  6. Flow node restriction sets (with all entries)
  7. Termination number range sets (with all entries)
  8. Account code sets (with all entries)
  9. Alternative termination numbers
  10. Flows (without scheduling)
  11. Services (including barring, without scheduling)
  12. Flow version schedules
Note that this order means that if a top-level FNRS or TNRS is required to be created for an imported customer, the set must be created in a separate import.
(Default: commit entities individually)
--import-user
or -U
String Database record creation user for auditing.
(Default: Entity Import)
--quiet
or -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-host
or -h
String N2ACD source database host name or IP address.
(Default: localhost)
--db-port
or -p
Integer N2ACD source database port.
(Default: 5432)
--db-name
or -n
String N2ACD source database name.
(Default: n2in)
--db-connect
or -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-user
or -u
String N2ACD source database user name.
(Default: n2acd_owner)
--db-password
or -P
String N2ACD source database user password.
(Default: use details from ~/.pgpass)