Files
easyai-ai-gateway/scripts/cluster/prune-legacy-generated.sh
T
wangbo 971540a2a4 feat(deploy): 增加三节点 K3s 高可用迁移能力
新增 WireGuard 全互联、三 server embedded-etcd K3s、CloudNativePG 双实例、Barman OSS 备份、双 NGINX、Kubernetes Secret/RBAC 与本地旧文件按严格 24 小时清理。

新增维护窗口数据迁移、digest 固定滚动发布、应用回滚、跨节点文件 E2E、节点和数据库故障演练、CNPG 恢复与 etcd 快照验收脚本;洛杉矶仅作为带 NoSchedule 污点的仲裁节点。

所有生产 Secret 只在执行时从 0600 本地环境和旧生产容器导入,仓库不保存凭据;公网入口保持人工 DNS 故障切换边界。

验证:bash -n、ShellCheck、kubectl kustomize、Node 语法检查、Secret 扫描、OSS put/head/delete 实测。
2026-07-28 04:37:31 +08:00

46 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
mode=${1:---dry-run}
storage_root=${AI_GATEWAY_LEGACY_STORAGE_ROOT:-/var/lib/docker/volumes/easyai-ai-gateway_api_data/_data/static}
maximum_age_seconds=86400
[[ $mode == --dry-run || $mode == --apply ]] || {
echo 'usage: prune-legacy-generated.sh [--dry-run|--apply]' >&2
exit 64
}
[[ $storage_root == /var/lib/docker/volumes/*/_data/static && -d $storage_root && ! -L $storage_root ]] || {
echo 'legacy storage root failed safety validation' >&2
exit 1
}
candidate_list=$(mktemp)
trap 'rm -f -- "$candidate_list"' EXIT HUP INT TERM
now_epoch=$(date +%s)
while IFS= read -r -d '' file; do
modified_epoch=$(stat -c '%Y' "$file")
if (( now_epoch - modified_epoch > maximum_age_seconds )); then
printf '%s\0' "$file" >>"$candidate_list"
fi
done < <(find "$storage_root" -xdev -type f -print0)
file_count=$(tr -cd '\0' <"$candidate_list" | wc -c | tr -d ' ')
byte_count=0
while IFS= read -r -d '' file; do
[[ $file == "$storage_root/"* && ! -L $file ]] || {
echo "unsafe cleanup candidate: $file" >&2
exit 1
}
byte_count=$((byte_count + $(stat -c '%s' "$file")))
done <"$candidate_list"
if [[ $mode == --apply ]]; then
while IFS= read -r -d '' file; do
rm -f -- "$file"
done <"$candidate_list"
find "$storage_root" -xdev -depth -type d -empty -delete
fi
printf 'legacy_cleanup=%s files=%s bytes=%s age_seconds_strictly_greater_than=86400\n' \
"${mode#--}" "$file_count" "$byte_count"