<# .SYNOPSIS Copie de sauvegarde des fichiers qu'un lot de migration va modifier. .DESCRIPTION Copie chaque fichier vers \\ et consigne son empreinte dans \\manifest.csv. Un fichier deja present dans le manifeste n'est jamais recopie : la premiere sauvegarde d'un lot est l'etat de reference que Restore.ps1 remet en place. Un chemin qui n'existe pas encore est consigne avec Existed=False : la restauration le retirera (deplacement, jamais suppression definitive). .EXAMPLE .\Tools\Snapshot.ps1 -Lot L1 -Path Content\BPs\GI.uasset, Config\DefaultEngine.ini .\Tools\Snapshot.ps1 -Lot L4 -Path Content\UI -Recurse #> param( [Parameter(Mandatory)][string]$Lot, [Parameter(Mandatory)][string[]]$Path, [switch]$Recurse, [string]$ProjectRoot = (Split-Path $PSScriptRoot -Parent), [string]$BackupRoot = 'D:\Game\LifePlay_Backup_5.5' ) $ErrorActionPreference = 'Stop' $lotDir = Join-Path $BackupRoot $Lot $manifest = Join-Path $lotDir 'manifest.csv' New-Item -ItemType Directory -Force $lotDir | Out-Null $known = @{} if (Test-Path $manifest) { Import-Csv $manifest | ForEach-Object { $known[$_.Rel] = $true } } # Liste des fichiers relatifs a traiter $rels = foreach ($p in $Path) { $full = Join-Path $ProjectRoot $p if (Test-Path $full -PathType Container) { $items = if ($Recurse) { Get-ChildItem $full -File -Recurse -Force } else { Get-ChildItem $full -File -Force } $items | ForEach-Object { $_.FullName.Substring($ProjectRoot.TrimEnd('\').Length + 1) } } else { $p -replace '^\.\\', '' } } $rows = @() foreach ($rel in $rels) { if ($known.ContainsKey($rel)) { Write-Host "deja sauvegarde : $rel"; continue } $src = Join-Path $ProjectRoot $rel if (Test-Path $src -PathType Leaf) { $dst = Join-Path $lotDir $rel New-Item -ItemType Directory -Force (Split-Path $dst -Parent) | Out-Null Copy-Item -LiteralPath $src -Destination $dst -Force $h1 = (Get-FileHash -LiteralPath $src -Algorithm MD5).Hash $h2 = (Get-FileHash -LiteralPath $dst -Algorithm MD5).Hash if ($h1 -ne $h2) { throw "Copie corrompue : $rel" } $rows += [pscustomobject]@{ Rel = $rel; Existed = $true; Size = (Get-Item -LiteralPath $src).Length; MD5 = $h1; Date = (Get-Date -Format s) } Write-Host "sauvegarde : $rel ($h1)" } else { $rows += [pscustomobject]@{ Rel = $rel; Existed = $false; Size = 0; MD5 = ''; Date = (Get-Date -Format s) } Write-Host "absent (sera retire a la restauration) : $rel" } } if ($rows.Count) { $rows | Export-Csv $manifest -NoTypeInformation -Append -Encoding UTF8 } Write-Host "$($rows.Count) entree(s) ajoutee(s) a $manifest"