Seamless First-Time Production Migration in PI System: A Step-by-Step Guide
This guide walks you through migrating your AF hierarchy and PI Vision screens from development to production, including backfilling analyses. It covers best practices, AFSDK usage for migration and backfill, and precautions to avoid common pitfalls.
Roshan Soni
As a PI System engineer with 10 years of experience, I've learned that a smooth transition from development to production is crucial for success in any project. In this guide, I'll walk you through the process of migrating your AF hierarchy and PI Vision screens from a development environment to an empty production environment, including backfilling analyses. We'll cover best practices, advanced usage of AFSDK for migration and backfill, and a set of precautions to avoid common pitfalls.
This guide is perfect if you're preparing for your first production movement and want a structured, foolproof plan for success.
The Scenario
In this guide, we’ll focus on a scenario where:
- You’ve built an AF (Asset Framework) hierarchy in your development environment with 3000 elements.
- You’ve created 20 PI Vision screens.
- Your production environment is empty and ready for its first migration.
Key Considerations:
- Data Integrity: Make sure all historical and real-time data is preserved and correctly calculated in production.
- System Performance: Ensure your production environment can handle large-scale backfilling without impacting ongoing operations.
- Rollback Strategy: Even if production is empty, have a solid rollback plan in case of unexpected issues during the migration.
Step 1: Preparation and Backup
The first step is to ensure you have a full backup of your development environment. While your production environment is empty, having the ability to roll back to the development state ensures that you’re covered if anything goes wrong.
AF Hierarchy Backup
-
Using PI System Explorer:
- Navigate to the AF database in your development environment.
- Right-click on the AF hierarchy and choose Export to File.
- Save the file as an XML or .afarchive file in a secure backup location.
-
Programmatic Backup Using AFSDK: For more advanced automation, you can use AFSDK to export the AF hierarchy programmatically. Here’s a C# code snippet to export the AF hierarchy to a JSON file:
using OSIsoft.AF; using OSIsoft.AF.Asset; using System; using System.IO; using System.Text.Json; class Program { static void Main(string[] args) { PISystems piSystems = new PISystems(); PISystem piSystem = piSystems["YourAFServer"]; AFDatabase afDatabase = piSystem.Databases["YourAFDatabase"]; var rootElement = afDatabase.Elements["RootElement"]; ExportAFHierarchy(rootElement); } static void ExportAFHierarchy(AFElement rootElement) { var hierarchy = new { Name = rootElement.Name, Attributes = rootElement.Attributes, Children = ExportChildren(rootElement.Elements) }; string json = JsonSerializer.Serialize(hierarchy, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText("AFHierarchy.json", json); Console.WriteLine("AF Hierarchy exported successfully!"); } static object ExportChildren(AFElements elements) { var children = new List<object>(); foreach (AFElement childElement in elements) { var childHierarchy = new { Name = childElement.Name, Attributes = childElement.Attributes, Children = ExportChildren(childElement.Elements) }; children.Add(childHierarchy); } return children; } }
This programmatically exports the AF hierarchy as a JSON file, which can be used for later re-importing into production.
PI Vision Screens Backup
-
Using the PI Vision Export Tool:
- For PI Vision 2019 and later, export your PI Vision screens as
.pvsnfiles using the built-in Export Tool.
- For PI Vision 2019 and later, export your PI Vision screens as
-
Backup the PI Vision SQL Database:
- Use SQL Server Management Studio (SSMS) to back up the PI Vision SQL database, especially if you are working with an older version of PI Vision.
Step 2: Testing in the Development Environment
Before you migrate to production, it’s crucial to validate that everything in your development environment is working correctly. Identify and resolve any issues before migrating.
AF Hierarchy Validation
- Check templates, elements, and attributes to ensure everything is correctly configured.
- Validate AF analyses, making sure all calculations and schedules are correct.
- Test PI Data Archive references to ensure that elements correctly pull historical and real-time data.
PI Vision Screens Validation
- Open all PI Vision screens to ensure that they render data correctly from the PI Data Archive.
- Validate performance, ensuring that screens load quickly and without errors.
Step 3: Migrating to Production
AF Hierarchy Migration
Now that your development environment has been validated, you can migrate your AF hierarchy to the empty production environment using PI System Explorer or programmatically via AFSDK.
Option 1: Using PI System Explorer
- Open PI System Explorer in production.
- Import the .XML or .afarchive file you exported from the development environment.
- Ensure that the import process completes without errors and all elements are in place.
Option 2: Using AFSDK (Code-Based Approach)
You can use a similar AFSDK script to import your hierarchy into production by reading the exported JSON file.
PI Vision Screens Migration
To migrate PI Vision screens:
- Use the PI Vision Import Tool to import the previously exported
.pvsnfiles. - Validate that each screen correctly connects to the production data sources.
Step 4: Backfilling AF Analyses
Backfilling analyses is a critical step to ensure that your production environment has historical data calculated for all time periods, not just after the migration.
Manual Backfilling Using PI System Explorer
- Navigate to the Analysis tab in PI System Explorer.
- Right-click the analysis and choose Backfill/Recalculate.
- Select the start and end dates for the backfill.
- Start the process and monitor its progress.
Automating Backfilling with AFSDK
For large-scale backfills, you can use AFSDK to automate the process. Here’s a simple example to programmatically backfill AF analyses:
using OSIsoft.AF;
using OSIsoft.AF.Analysis;
using System;
class Program
{
static void Main(string[] args)
{
PISystems piSystems = new PISystems();
PISystem piSystem = piSystems["YourAFServer"];
AFDatabase afDatabase = piSystem.Databases["YourAFDatabase"];
AFAnalysis analysis = afDatabase.Analyses["YourAnalysisName"];
DateTime startTime = new DateTime(2023, 1, 1);
DateTime endTime = DateTime.UtcNow;
analysis.Backfill(startTime, endTime);
Console.WriteLine("Backfilling completed.");
}
}
This code triggers a backfill for a specific analysis over a specified time range, ensuring historical data is processed correctly.
Step 5: Post-Migration Validation
After migration and backfilling, it’s crucial to validate the production environment to ensure everything is working as expected.
AF Hierarchy Validation
- Check that all elements, attributes, and templates are in place.
- Verify that AF analyses are running smoothly and producing the correct results.
PI Vision Validation
- Open all PI Vision screens in production to ensure they are connected to the correct data sources and displaying accurate data.
- Validate performance and check for any errors.
Step 6: Rollback Plan
While your production environment is empty, having a rollback plan ensures that you can revert to the previous state if any issues arise during migration.
Rollback Triggers
- AF hierarchy or analyses fail after migration.
- PI Vision screens are broken or displaying incorrect data.
Rollback Process
- AF Hierarchy Rollback: If the hierarchy fails, you can delete the incorrect elements and re-import the AF hierarchy from your development backup.
- PI Vision Rollback: If screens don’t display data correctly, simply re-import the previous versions of the screens from the backup
.pvsnfiles.
Step 7: Precautions List
Here’s a list of key precautions to take during your first migration:
-
Data Integrity: Always ensure that historical and real-time data sources are available and accurate before migrating.
-
System Load: Backfilling large amounts of data can be resource-intensive. Stagger backfilling processes and monitor system performance during this time.
-
Permissions: Validate that all necessary user permissions and security settings are correctly configured in the production environment.
-
Rollback Plan: Even with an empty production environment, have a clear rollback plan to prevent downtime or misconfigurations.
-
Post-Migration Testing: Always validate the production environment post-migration to catch any errors early.
-
Schedule the Migration: Perform the migration during low-traffic hours or scheduled downtime to avoid disruption to users.
Conclusion
Migrating to an empty production environment for the first time can be a daunting task, but with proper preparation, backfilling, and validation, it becomes a manageable and seamless process. Whether you’re using PI System Explorer or AFSDK, following this structured approach ensures that your first migration goes off without a hitch.
By taking the necessary precautions, planning for rollbacks, and thoroughly testing each stage of the migration, you can avoid common pitfalls and set your system up for long-term success.
Tags
About Roshan Soni
Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.
No comments yet
Be the first to share your thoughts on this article.
Related Articles
Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead
A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.
Roshan Soni
Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB
Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.
Roshan Soni
Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?
Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.
Roshan Soni