Tenants and tenant groups can be exported as ABL code that can be used to load the tenants and tenant groups into a different database.

The following code generates code to create a tenant domains, tenant groups and partitions in a database. Note that the reference to domains will also generate code to create users of the domains:

tenant = service:GetTenant("MyTenant").               tenant:ExportTree("mytenant.p","domains,tenantgroups,partitions").

The following code generates code to create a tenant group with partitions in a database:

tenantGroup = service:GetTenantGroup("MyTenantGroup").               tenantGroup:ExportTree("mytenant.p","partitions").

You can generate code that also adds tenants to a tenant group as follows. In this case the code that generates the corresponding tenant should not include the tenant groups:

tenantGroup = service:GetTenantGroup("MyTenantGroup").               tenantGroup:ExportTree("mytenant.p","tenants,partitions").