How do i use pisystem.exportxml and then pisystem.importxml to replicate a database from one AF server to another?
You can connect to the database in your source AF and open PI Systeem Explorer -> FIle -> Export to File, select the appropriate option as shown in figure below
In the target AF system, create the database and connect to it before importing the XML file, please find the below screen shot
This should help you in getting all the elements from one AF Server to Other.
What are you trying to replicate? Elements, attributes, event frames, security, contacts, ... ?
My apologies for not being specific enough. I am interested in replicating Elements, attribute and event frames, from one server to another using AF SDK(pisystem.exportxml and pisystem.importxml).
Also, If a database wasn't created in the 2nd server, will the import create the database?
You have to create a new database at the target AF Server. The Elemenst,Attributes and Event frames can be replicated using export xml in PI System Explorer.
The AF SDK exposes some methods to export and import AFObjects stored in XML or CSV format. For example, the below PowerShell script uses the AF SDK assembly to export an AFDatabase from one AFServer and imports it in another AF Server.
[Reflection.Assembly]::LoadWithPartialName("OSIsoft.AFSDK") | Out-Null
[OSIsoft.AF.PISystems] $AFServers = New-Object OSIsoft.AF.PISystems
[OSIsoft.AF.PISystem] $AFServer_1 = $AFServers["AFServer_1"]
[OSIsoft.AF.AFDatabase] $db = $AFServer_1.Databases["AFDatabase"]
$XMLExport = $AFServer_1.ExportXml($DB,0)
[OSIsoft.AF.PISystem] $AFServer_2 = $AFServers["AFServer_2"]
Please note that this script isn't production ready. It's only meant to be used as an example to show the AF SDK methods.
The import will create the AFDatabase if is the AFObject that is being imported. Otherwise, if you only want to import some AFObjects of an AFDatabase, you will need to create the AFDatabase on the target machine and import the AFObjects there.
Retrieving data ...