6 Replies Latest reply on Apr 17, 2019 1:34 PM by sraposo

    AF database export xml and import xml

    lingpl

      Hi,

      How do i use pisystem.exportxml and then pisystem.importxml to replicate a database from one AF server to another?

        • Re: AF database export xml and import xml
          VAshok

          Hi ,

           

          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

           

          ExportJpG.PNG

           

          In the target AF system, create the database and connect to it before importing the XML file, please find the below screen shot

           

          IMPORTJpG.PNG

          This should help you in getting all the elements from one AF Server to Other.

          • Re: AF database export xml and import xml
            sraposo

            Hi Ping,

             

            What are you trying to replicate? Elements, attributes, event frames, security, contacts, ... ?

             

            Thanks,

            Seb

              • Re: AF database export xml and import xml
                lingpl

                Hi Sebastien,

                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?

                  • Re: AF database export xml and import xml
                    VAshok

                    HI Ping,

                    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.

                      • Re: AF database export xml and import xml
                        sraposo

                        Hi Vinayak,

                         

                        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"]

                        $AFServer_2.ImportXml($null,1,$XMLExport)

                         

                        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.


                        Thanks,

                        Seb

                        1 of 1 people found this helpful
                      • Re: AF database export xml and import xml
                        sraposo

                        Hi Ping,

                         

                        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.