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.

Parents
  • @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

     

Reply
  • @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

     

Children
No Data