updated gdrive_retention.ps1

This commit is contained in:
dzaitsev
2025-05-22 10:15:40 +03:00
parent 0d51f3c373
commit cea8083422
+12 -7
View File
@@ -1,9 +1,6 @@
param (
[string]$Path = "."
)
# Configuration # Configuration
$rcloneRemote = "AzaionGoogleDrive:AzaionSuiteBuilds" $rcloneRemote = "AzaionGoogleDrive:AzaionSuiteBuilds"
$rclone = "rclone" # Assuming rclone is available in the PATH.
function Write-Header($text) { function Write-Header($text) {
Write-Host "`n=== $text ===`n" -ForegroundColor Cyan Write-Host "`n=== $text ===`n" -ForegroundColor Cyan
@@ -24,8 +21,16 @@ function Write-ErrorMsg($text) {
Write-Header "Starting cleanup of older Full and Iterative installers on Google Drive" Write-Header "Starting cleanup of older Full and Iterative installers on Google Drive"
Write-Info "Listing all files in: $rcloneRemote" Write-Info "Listing all files in: $rcloneRemote"
$allFilesRaw = rclone lsf --files-only $rcloneRemote $allFilesRaw = & $rclone lsf --files-only $rcloneRemote
# Check if the command succeeded
if ($LASTEXITCODE -ne 0) {
Write-ErrorMsg "Failed to list files from Google Drive using rclone."
exit 1
}
$allFiles = $allFilesRaw -split "`n" | Where-Object { $_ -ne "" } $allFiles = $allFilesRaw -split "`n" | Where-Object { $_ -ne "" }
if ($allFiles.Count -eq 0) { if ($allFiles.Count -eq 0) {
Write-WarningMsg "No files found in the remote folder." Write-WarningMsg "No files found in the remote folder."
exit 0 exit 0
@@ -57,7 +62,7 @@ if ($fullFiles.Count -eq 0) {
} }
foreach ($file in $fullToDelete) { foreach ($file in $fullToDelete) {
$res = rclone deletefile "$rcloneRemote/$file" 2>&1 $res = & $rclone deletefile "$rcloneRemote/$file" 2>&1
if ($LASTEXITCODE -eq 0) { if ($LASTEXITCODE -eq 0) {
Write-Info "Deleted Full installer: $file" Write-Info "Deleted Full installer: $file"
} else { } else {
@@ -89,7 +94,7 @@ if ($iterativeFiles.Count -eq 0) {
} }
foreach ($file in $iterativeToDelete) { foreach ($file in $iterativeToDelete) {
$res = rclone deletefile "$rcloneRemote/$file" 2>&1 $res = & $rclone deletefile "$rcloneRemote/$file" 2>&1
if ($LASTEXITCODE -eq 0) { if ($LASTEXITCODE -eq 0) {
Write-Info "Deleted Iterative installer: $file" Write-Info "Deleted Iterative installer: $file"
} else { } else {