生成备份脚本
- cat > run.sh <<'EOF'
- #!/bin/sh
-
- # 需要导出的命名空间
- namespaces=("test")
- # 需要导出的类型
- types=("cm" "deploy" "service" "pod")
-
- day=`date +%Y-%m-%d_%H`
- rm -rf $day
- mkdir $day
- for ns in ${namespaces[@]}
- do
- rm -rf $day/$ns
- mkdir $day/$ns
- for type in ${types[@]}
- do
- mkdir $day/$ns/$type
- for nam in $(kubectl get $type -n $ns|awk '{print $1}'|grep -v NAME)
- do
- kubectl get $type $nam -n $ns -o yaml > $day/$ns/$type/$nam.yaml
- done
- done
- exit
- done
- EOF
-
执行备份
sh run.sh