Skip to content

Instantly share code, notes, and snippets.

@SQLDBAWithABeard
Last active December 6, 2023 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SQLDBAWithABeard/b7f5207678cfedee3080748814b3d601 to your computer and use it in GitHub Desktop.
Save SQLDBAWithABeard/b7f5207678cfedee3080748814b3d601 to your computer and use it in GitHub Desktop.
rough-k8s-backup
$resources = (kubectl api-resources --namespaced=$true 2>$null | Where-Object { $_ -notmatch "events" } | Select-Object -Skip 1 | ForEach-Object { $_.Split()[0] })
$output_folder = 'C:\temp\K8s-output'
if(!(Test-Path $output_folder)) {
New-Item $output_folder -ItemType Directory | Out-Null
}
foreach($resource in $resources){
kubectl get $resource --all-namespaces 2>&1 | Select-Object -Skip 1 | ForEach-Object {
$namespace, $item, $x = $_ -split '\s+'
$outputFolder = Join-Path -Path $output_folder -ChildPath "$namespace\$resource"
New-Item -ItemType Directory -Force -Path $outputFolder | Out-Null
Write-Host " exporting item '$namespace $item'"
kubectl get $resource -n $namespace $item -o yaml | Set-Content -Path (Join-Path -Path $outputFolder -ChildPath "$item.yaml")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment