From b34873f98052ac5fb4bf6731a25730075796d764 Mon Sep 17 00:00:00 2001 From: ertopogo Date: Fri, 13 Mar 2026 00:33:28 +0100 Subject: Initial commit medias platform --- sync_windows_to_minio.ps1 | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sync_windows_to_minio.ps1 (limited to 'sync_windows_to_minio.ps1') diff --git a/sync_windows_to_minio.ps1 b/sync_windows_to_minio.ps1 new file mode 100644 index 0000000..43e0871 --- /dev/null +++ b/sync_windows_to_minio.ps1 @@ -0,0 +1,66 @@ +param( + [Parameter(Mandatory = $true)] + [string]$SourceRoot, + + [Parameter(Mandatory = $true)] + [string]$EndpointUrl, + + [Parameter(Mandatory = $true)] + [string]$Bucket, + + [Parameter(Mandatory = $true)] + [string]$AccessKey, + + [Parameter(Mandatory = $true)] + [string]$SecretKey, + + [string]$ProfileName = "minio-sync", + [string]$PrefixRoot = "photos", + [switch]$WhatIf +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" + +if (-not (Test-Path -Path $SourceRoot)) { + throw "Le chemin source '$SourceRoot' est introuvable." +} + +$aws = Get-Command aws -ErrorAction SilentlyContinue +if (-not $aws) { + throw "AWS CLI est requis. Installer AWS CLI puis relancer." +} + +Write-Host "Configuration du profil AWS CLI '$ProfileName'..." +aws configure set aws_access_key_id $AccessKey --profile $ProfileName | Out-Null +aws configure set aws_secret_access_key $SecretKey --profile $ProfileName | Out-Null +aws configure set default.region us-east-1 --profile $ProfileName | Out-Null + +$normalizedSource = (Resolve-Path $SourceRoot).Path +$folders = Get-ChildItem -Path $normalizedSource -Directory + +if ($folders.Count -eq 0) { + Write-Warning "Aucun sous-dossier detecte. Synchronisation du dossier source complet." + $target = "s3://$Bucket/$PrefixRoot/" + $cmd = "aws s3 sync `"$normalizedSource`" `"$target`" --endpoint-url `"$EndpointUrl`" --profile `"$ProfileName`" --delete" + if ($WhatIf) { + Write-Host "[WhatIf] $cmd" + } else { + Invoke-Expression $cmd + } + exit 0 +} + +foreach ($folder in $folders) { + $logicalPrefix = "$PrefixRoot/$($folder.Name)/" + $target = "s3://$Bucket/$logicalPrefix" + $cmd = "aws s3 sync `"$($folder.FullName)`" `"$target`" --endpoint-url `"$EndpointUrl`" --profile `"$ProfileName`" --delete" + if ($WhatIf) { + Write-Host "[WhatIf] $cmd" + } else { + Write-Host "Sync '$($folder.FullName)' -> '$target'" + Invoke-Expression $cmd + } +} + +Write-Host "Synchronisation terminee." -- cgit v1.2.3