This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-helm.ps1
46 lines (35 loc) · 1.59 KB
/
backup-helm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
param(
[string]$KubeconfigPath = "",
[string]$OutputPath = "."
)
if (!$KubeconfigPath) {
$KubeconfigPath = Read-Host -Prompt "Enter the Path to your kubeconfig:"
}
if (Get-Command -ErrorAction Ignore -Type Cmdlet Start-ThreadJob) {
Write-Host "Module 'ThreadJob' is already installed."
}else{
Write-Verbose "Installing module 'ThreadJob' on demand..."
Install-Module -ErrorAction Stop -Scope CurrentUser ThreadJob
}
function GetHelmValues($kubeconfigPath, $namespace, $releaseName, $outputFile) {
.\_tools\helm.exe --kubeconfig $kubeconfigPath get values -n $namespace $releaseName --output yaml | Out-File $outputFile
}
$ArchiveName = "${OutputPath}/helm_backup.7z"
$Namespace = "united-manufacturing-hub"
$ReleaseName = "united-manufacturing-hub"
if (Test-Path $ArchiveName) {
$overwrite = Read-Host -Prompt "The file $ArchiveName already exists. Do you want to overwrite it? (y/N)"
if ($overwrite.ToLower() -ne 'y') {
Write-Host "Aborted. No changes have been made to the existing $ArchiveName."
exit 1
}
}
New-Item -Path "${OutputPath}/helm" -ItemType Directory -Force | Out-Null
Write-Host "Saving Helm values"
GetHelmValues -kubeconfigPath $KubeconfigPath -namespace $Namespace -releaseName $ReleaseName -outputFile "${OutputPath}/helm/values.yaml"
# Compress the helm folder
$SevenZipPath = ".\_tools\7z.exe"
& $SevenZipPath a -m0=zstd -mx0 -md=16m -mmt=on -mfb=64 "${ArchiveName}" "${OutputPath}/helm/" | Out-Null
# Delete the helm folder
Remove-Item -Path "${OutputPath}/helm" -Recurse -Force
Write-Host "Helm folder compressed to $ArchiveName and deleted"