๐๏ธAdvanced
Do not read, do not edit, and most definitely do not try, you might (and will) break things. ๐
Registry Cleaning
REGISTRY="luckyCycleRegistry"
PURGE_RC="acr purge --filter ".*:.*rc.*" \
--ago 1d --keep 2 --untagged --dry-run"
PURGE_PROD="acr purge --filter ".*:.*" \
--ago 1d --keep 4 --untagged --dry-run"
az acr run \
--cmd "$PURGE_RC" \
--registry "$REGISTRY" \
--timeout 3600 \
/dev/nullRegistry Images Size
REGISTRY="luckyCycleRegistry"
REPOS=$(az acr repository list --name $REGISTRY)
REPOS=("curl-jq" "luckycycle_api" "luckycycle_backend" "luckycycle_box" "maintenance" "node-auth" "node-backofficeleclerc" "node-frontendleclerc" "node-itm-gji" "node-lck2" "node-lucky-cycle-com" "node-luckygame" "node-saas-back" "node-saas-front")
REGISTRY_SIZE=0
for REPO in "${REPOS[@]}"; do
echo "\n[$REPO]"
MANIFESTS=$(az acr manifest list-metadata --registry $REGISTRY --name $REPO --query "[].{digest:digest, tags:tags, imageSize:imageSize, createdTime:createdTime}" 2>/dev/null)
if [[ $? -ne 0 ]]; then
echo "$MANIFESTS"
continue
fi
MANIFESTS=$(echo $MANIFESTS | jq -r 'sort_by(.createdTime) | reverse')
REPO_SIZE=0
for MANIFEST in $(echo $MANIFESTS | jq -r '.[].digest'); do
TAGS=$(echo $MANIFESTS | jq -r ".[] | select(.digest==\"$MANIFEST\") | .tags | join(\"|\")")
IMAGE_SIZE=$(echo $MANIFESTS | jq -r ".[] | select(.digest==\"$MANIFEST\") | .imageSize")
REPO_SIZE=$(echo "scale=2; $REPO_SIZE + $IMAGE_SIZE" | bc)
echo "+ $TAGS ->> $(echo "scale=2; $IMAGE_SIZE / (1024^2)" | bc)Mb"
done
echo "= $(echo "scale=2; $REPO_SIZE / (1024^2)" | bc)Mb"
REGISTRY_SIZE=$(echo "scale=2; $REGISTRY_SIZE + $REPO_SIZE" | bc)
done
echo "->> $(echo "scale=2; $REGISTRY_SIZE / (1024^3)" | bc)Gb"Database
SELECT
relname AS table_name,
n_live_tup, # Estimated number of live rows in the table (currently visible rows).
n_dead_tup, # Estimated number of dead rows (rows deleted/updated but not yet vacuumed).
vacuum_count, # Number of times the table has been manually vacuumed.
autovacuum_count # Number of times autovacuum has processed this table.
FROM
pg_stat_user_tables
ORDER BY
n_dead_tup DESC;SELECT
relname AS table_name,
pg_size_pretty(pg_total_relation_size(relid)) AS total_size,
pg_size_pretty(pg_relation_size(relid)) AS table_size,
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) AS index_size
FROM
pg_catalog.pg_statio_user_tables
ORDER BY
pg_total_relation_size(relid) DESC;Blobs
$resourceGroupName = "rgStorage"
$storageAccountName = "stgluckycycleprod"
$containerName = "public"
$filesPath = "uploads/reward"
$filesTreshold = 500000
$filesLastUpdate = 180
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$blobs = Get-AzStorageBlob -Context $storageAccount.Context -Container $containerName -Prefix $filesPath
$fileHeader = "File_Path;Last_Modified;Weight_KB"
# Add-Content -Path blobs.csv -Value $fileHeader
foreach ($blob in $blobs) {
if ($blob.Name.Contains('.')) {
if ($blob.Length -gt $filesTreshold) {
$lastUpdate = (New-TimeSpan -Start $blob.LastModified.UtcDateTime -End (Get-Date)).TotalDays
if ($lastUpdate -le $filesLastUpdate) {
$blobInfo = $blob.Name + ';' + $blob.LastModified.UtcDateTime + ';' + $blob.Length / 1000
Write-Host $blobInfo
# Add-Content -Path blobs.csv -Value $blobInfo
}
}
}
}Folders
$resourceGroupName = "rgStorage"
$storageAccountName = "stgluckycycleprod"
$containerName = "public"
$filesPath = "uploads/operation"
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$blobs = Get-AzStorageBlob -Context $storageAccount.Context -Container $containerName -Prefix $filesPath
$fileHeader = "Folder_Path;Files_Count"
# Add-Content -Path folders.csv -Value $fileHeader
foreach ($blob in $blobs) {
if (!$blob.Name.Contains('.')) {
$Blobs = Get-AzStorageBlob -Context $storageAccount.Context -Container $containerName -Prefix $blob.Name
$FilesCount = ($Blobs | Where-Object {$_.BlobType -eq 'BlockBlob'}).Count
$folderInfo = $blob.Name + ';' + ($FilesCount - 1)
# Add-Content -Path folders.csv -Value $folderInfo
Write-Host -NoNewline '.'
if ($FilesCount -eq 1) {
Remove-AzStorageBlob -Context $storageAccount.Context -Container $containerName -Blob $blob.Name
# Write-Output $blob.Name
Write-Host -NoNewline -ForegroundColor red '.'
}
}
}Unwanted files
$resourceGroupName = "rgStorage"
$storageAccountName = "stgluckycycleprod"
$containerName = "public"
$filesPath = "uploads/operation"
$targetExtensions = @(".csv", ".txt")
$writeFiles = $true
$deleteFiles = $false
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$blobs = Get-AzStorageBlob -Context $storageAccount.Context -Container $containerName -Prefix $filesPath
$fileHeader = "File_Path;Last_Modified"
Add-Content -Path blobs.csv -Value $fileHeader
foreach ($blob in $blobs) {
# Write-Host $blob.Name
if ($blob.Name.Contains('.')) {
$extension = [System.IO.Path]::GetExtension($blob.Name)
if ($targetExtensions -contains $extension) {
if ($writeFiles) {
$blobInfo = $blob.Name + ';' + $blob.LastModified.UtcDateTime
Add-Content -Path blobs.csv -Value $blobInfo
}
if ($deleteFiles) {
Remove-AzStorageBlob -Context $storageAccount.Context -Container $containerName -Blob $blob.Name
Write-Host "Deleted:" $blob.Name
}
}
}
}Make sure to switch to a PowerShell environment and to log in to Azure with an admin account before trying to run the scripts:
pwsh
Connect-AzAccountPG Bouncer
Add your ip in this file to access the db locally in loadBalancerSourceRanges
Last updated