create-filtered-edge-checkpoint.ps1 #2

  • //
  • guest/
  • perforce_software/
  • sdp/
  • dev/
  • Server/
  • Windows/
  • p4/
  • common/
  • bin/
  • create-filtered-edge-checkpoint.ps1
  • View
  • Commits
  • Open Download .zip Download (3 KB)
# ============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
# ----------------------------------------------------------------------------

<#
    .Synopsis
        Creates a filtered edge checkpoint from a master offline database
        
    .Description
        Create filtered checkpoint
        
    .Parameter SDPInstance
        The specified instance to process
        
    .Parameter EdgeServer
        The specified id of edge server (from 'p4 servers')
        
    .Parameter CkpFile
        The specified checkpoint file to produce
        
    .Example
        create-filtered-edge-checkpoint.ps1 1 Edge p4_1.ckp.1234.gz
        
#>

[CmdletBinding()]
param ([string]$SDPInstance = $(throw "SDPInstance parameter is required."),
       [string]$EdgeServer = $(throw "EdgeServer parameter is required."))

Set-StrictMode -Version 2.0

# Source the SDP Functions shared between scripts
$SDPFunctionsPath = Split-Path -parent $MyInvocation.MyCommand.Path | Join-Path -childpath "SDP-Functions.ps1" 
. $SDPFunctionsPath

$global:ScriptName = "create-filtered-edge-checkpoint.ps1"
$global:ScriptTask = "Create Filtered edge checkpoint from master"
$global:LogFileName = "create-filtered-edge-checkpoint.log"

Parse-SDPConfigFile $MyInvocation.MyCommand.Path
Create-LogFile

$OrigPath = convert-path .
Set-Location -Path $global:LOGS_DIR

try {
    $checkpoint_prefix = -join($global:CHECKPOINTS_DIR, "\", $global:SDP_INSTANCE_P4SERVICE_NAME, ".ckp.")
    $checkpoint_path = -join($checkpoint_prefix, "[0-9]*.gz")
    $files = @(Get-ChildItem -Path $checkpoint_path | Sort-Object -Property LastWriteTime -Descending)
    if (!$files -or $files.count -eq 0) {
        $journal = Get-JournalCounter $global:OFFLINE_DB_DIR
    } else {
        $journal = $files[0].Name | select-string '\.ckp\.([0-9]*)\.gz' | % {$_.Matches} | % {$_.Groups[1].Value}
    }
    $CkpFile = -join($checkpoint_prefix, "filtered-edge.", $journal, ".gz")
    remove-files $CkpFile 0
    
    # With -K we filter out the various Edge-specific tables which will be replaced with 
    # current live versions.
    $EXCLUDED_TABLES = "db.have,db.working,db.resolve,db.locks,db.revsh,db.workingx,db.resolvex"

    log "Checkpointing from master offline_db skipping tables not used on the edge - with filtering."
    $cmd = "$global:P4DEXE -r $global:OFFLINE_DB_DIR -K $EXCLUDED_TABLES -P $EdgeServer -jd -z $CkpFile"
    run-cmd-with-check $cmd "ERROR - attempting to create filtered checkpoint"
    
    Log "End ${global:SDP_INSTANCE_P4SERVICE_NAME} ${global:ScriptTask}"
    Write-Output "`r`n${global:ScriptTask} completed successfully - see ${global:logfile}"
    Log "Please copy $CkpFile to remote server and restore using recover-edge.ps1"
}
Catch
{
    write-error $error[0].ScriptStackTrace
    LogException $_.Exception
    Write-Output "`r`nFAILED - ${global:ScriptTask} - see ${global:logfile}"
}

Set-Location -Path $OrigPath
# Change User Description Committed
#7 26659 Robert Cowham Removing out-of-date files and ancient utilities.
Updating SDP Guide for Windows with includes to various .ps1 scripts
Add new sync-replica.ps1 and call it from sync_replica.bat
#6 26120 Robert Cowham Fix daily_checkpoint for edge/standby servers
Make edge tables to include/exclude version specific
Move password files to config dir
#5 22759 Robert Cowham Improve documentation within scripts.
#4 22727 Robert Cowham Rotate md5 where necessary
#3 22726 Robert Cowham Fix quoting issues
#2 22724 Robert Cowham Fix problem with multiple files.
#1 22722 Robert Cowham Basic creation of filtered edge checkpoint file