Submitting your feedback...
Knowledge Base Article
2971OSI8 - How to delete Shutdown events from the Snapshot table
Product: PI Data Archive
Version(s): 3.4 and earlier
 

Issue

In rare cases, it is possible for the snapshot table to become corrupted. In the PI 3 Manual, there is a documented procedure on how to fix such corruption using a snapfix procedure. However, the drawback to using the snapfix procedure is that all the points are subsequently set to Shutdown in the snapshot. This can cause problems for points where Shutdown events are not desired.  

Solution

Upgrade the PI Server and then run the snapfix to avoid inserting Shutdown events into the snapshot table.

In PI Server 3.4.380, the snapfix procedure was enhanced such that the snapshot will be populated with the snapshot value from the existing snapshot table whenever possible, instead of the digital state Shutdown. If the snapshot value cannot be recovered, the digital state snapfix will be inserted, but the next incoming value will replace the value and the "snapfix" event will not be archived.

If the PI Server cannot be upgraded or snapfix has already been run, the workaround is to use piconfig to extract and remove the Shutdown events from the Snapshot table. These events will automatically be replaced by the latest archived event.

The script pisnapfix.bat (see  Notes┬ásection below) makes the procedure easier by automatically running piconfig with the proper commands. This script (along with the two .dif files, also included below) should be created in the PI\adm directory. The syntax to run the script is the following:
C:\PI\adm> pisnapfix.bat [tagmask]
If not provided, the tagmask defaults to *, which is all points.

Note: Only events with "Shutdown" as their value will be deleted by the script. Valid events from the snapshot table will not be touched even if matching the tagmask.  

Notes

* Comments
* piremove.dif file
* This PIconfig script deletes the snapshot events extracted by the pisnaplist.dif
* script. Filtering in pisnapfix.bat insures only Shutdown events are deleted.

@echo data

@table piarc
@mode delete
@istr tag, status, time
@input %1%


==============================================================

* Comments
* pisnaplist.dif file
* This PIconfig script extracts the snapshot events for a particular tagmask
* The tagmask can be provided as an argument to the input command, example:
* @input pisnaplist.dif,sin*

@echo data
@mode list
@table pisnap
@ostr tag, status, time
@output pisnaplist.csv
@select tag=%1%
@ends


==============================================================

rem Comments
rem pisnapfix.bat file
rem This bat file runs the commands necessary to remove the Shutdown events
rem that are written when the snapfix procedure is executed.

@echo off
setlocal
echo.
echo The following script uses PIconfig to extract and remove any "Shutdown"
echo events from the PI Snapshot table.
echo You should use this only when directed by OSIsoft technical support.
echo.
set _tagmask=%1
if not defined _tagmask echo You may provide a tagmask as the first argument.
if not defined _tagmask set _tagmask=*
echo The current tagmask is: %_tagmask%
echo Press any key to proceed or Ctrl-C to abort...
pause > nul
echo.
echo Extracting the Snapshot events into "pisnaplist.csv"...
piconfig.exe input pisnaplist.dif,%_tagmask% exit
if not %errorlevel% == 0 goto ErrorPIconfig
echo.
type pisnaplist.csv | find "Shutdown" > pishutdown.csv
for %%i in (pishutdown.csv) do set _filesize=%%~zi
if %_filesize% == 0 goto NothingFound
echo Removing the Snapshot events...
piconfig.exe input piremove.dif,pishutdown.csv exit
if not %errorlevel% == 0 goto ErrorPIconfig
rem Done
goto End

:ErrorPIconfig
echo %0%: PIconfig error %errorlevel%
goto End

:NothingFound
echo No "Shutdown" events was found for the tagmask: %_tagmask%

:End
endlocal


Last Reviewed: 12-Oct-05, OAS  
Article ID: 2971OSI8 Created: 2003-08-18
Article Type: How-To Last Updated: 2017-02-02