What's the best way to copy historical data from one PIPoint to another (on the same archive)?

This could be doable with a custom program, but are there any out of the box tools for this, such as a command-line utility? Since both PI Points are on the same archive, I figured PI-to-PI would be out of the question.

  • @gmalek I personally would use a PowerShell script to accomplish this. Here it is:

    <#
        This script gets the timestamps and values from a source tag and writes them to a destination tag. Useful in cases where a new tag with no
        history is created to replace a pi tag that does have history for the same measurement.  
    #>
    
    #~ CONFIGURATION ITEMS:
        #~ For Use With Multiple Years of Data:
        # $startArray = @("1-Jan-2023 00:00:00","1-Jan-2022 00:00:00","1-Jan-2021 00:00:00","1-Jan-2020 00:00:00","1-Jan-2019 00:00:00","1-Jan-2018 00:00:00")    
        # $endArray = @("1-Jan-24 00:00:00","1-Jan-2023 00:00:00","1-Jan-2022 00:00:00","1-Jan-2021 00:00:00","1-Jan-2020 00:00:00","1-Jan-2019 00:00:00")
    
        #~ For Use with Less than a Year's worth of Data:
        $startTime = "2-Apr-2024 00:00:00"
        $endTime = "10-Oct-2024 12:00:00"
        $piServerName = "YOUR_PI_SERVER_NAME_HERE"
        $sourcePIPoint = "YOUR_SOURCE_PI_TAG_NAME_HERE"
        $destinationPIPoint = "YOUR_DESTINATION_PI_TAG_NAME_HERE"
    
    #~ CONNECT TO THE TARGET PI SERVER:
        $piConn = Connect-PIDataArchive -PIDataArchiveMachineName $piServerName
    
    #~ FOR LOOP THROUGH ANNUAL TIME RANGES:
    For ($i=0; $i -le $endArray.Count; $i++)  
    { 
        #~ GET COMPRESSED DATA:
           # Multiple Years: 
           # $results = Get-PIValue -PIPoint (Get-PIPoint -Name $sourcePIPoint -Connection $piConn) -StartTime $startArray[$i] -EndTime $endArray[$i]
           
           # Less Than A Year:
           $results = Get-PIValue -PIPoint (Get-PIPoint -Name $sourcePIPoint -Connection $piConn) -StartTime $startTime -EndTime $endTime
           ForEach ($result in $results)
           {
                #~ GET SOURCE TAG TIMESTAMP AND VALUE:
                $piTime = $result.TimeStamp.ToUniversalTime()
                $piTime.ToString("MM/dd/yyyy HH:mm:ss")
                $comma = ","
                $resultValue = $result.Value
                #~Write-Host $piTime$comma$resultValue
    
                #~ WRITE TIMESTAMP AND VALUE TO DESTINATION TAG:
                Add-PIValue -PointName $destinationPIPoint -Time $piTime -Value $resultValue -WriteMode Replace -Connection $piConn
    
                #~ Remove-PIValue -PointName $destinationPIPoint -Time $piTime -Value $resultValue -Connection $piConn        
           }
           Write-Host "End of Loop:" $i
           Sleep 5
           $result = ""
           $results = ""
    }
       $results = ""
       $nowTime = Get-Date -DisplayHint Time
       Write-Host "Backfilling Complete For: " $destinationPIPoint " On " $piServerName " at " $nowTime
    #~ DISCONNECT FROM PI SERVER:
        Disconnect-PIDataArchive -Connection $piConn

     

  • While ​ has provided a custom code solution, I have an important question: is this to be a one-time copy, or once-a-day, or continually?

     

    I am sure you are well versed in (A) the MaxArcCollect limit, (B) know something about the data rate of the tag(s) in question, and (C) know how wide of a time range you are interested in. For a big copy, A, B, and C all are factors on what you can do.

     

    If it is a one-time copy and there are less than 1.5 million values, you can use SMT's Archive Editor to copy values from the source tag and paste into the target tag. For a small amount of tags, this is easy enough but for a huge amount of tags there can be a lot of inconvenient scrolling as well as very long wait times. But SMT is a build-in tool to help you achieve your goal.

     

    If you wanted continual (event-triggered) or periodic updates, you can do this with an Asset Analysis. It would be a very simple Expression, and Analytics is considered a build-in tool. There is a limitation on how far back in history you can go, so you may need to catch-up on history to present before using Analytics to perform perpetual updates.

  • ​ The copy paste method is fairly easy one, however pasting didn't work in archive editor window (may be missed something).

    ​ there is another option, using datalink, export the compressed values of original tag into CSV file and back fill to new tag using PI piconfig script.