-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmigrate-gcs-arch.sh
More file actions
executable file
·94 lines (81 loc) · 2.68 KB
/
migrate-gcs-arch.sh
File metadata and controls
executable file
·94 lines (81 loc) · 2.68 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Copies kernel files from x86_64/ to amd64/ subdirectories in GCS buckets.
#
# The infra orchestrator's TargetArch() normalizes x86_64 -> amd64 (Go convention),
# so kernels stored under x86_64/ are never found by the arch-aware path resolution,
# causing a gcsfuse stat penalty on every sandbox create.
#
# Usage:
# ./migrate-gcs-arch.sh <bucket> # dry-run: show what would be copied
# ./migrate-gcs-arch.sh <bucket> --apply # copy x86_64/ -> amd64/
# ./migrate-gcs-arch.sh <bucket> --delete-old # dry-run: show what old x86_64/ files would be deleted
# ./migrate-gcs-arch.sh <bucket> --delete-old --apply # actually delete old x86_64/ files
#
# Recommended workflow:
# 1. ./migrate-gcs-arch.sh gs://my-bucket # review what will be copied
# 2. ./migrate-gcs-arch.sh gs://my-bucket --apply # copy to amd64/
# 3. ... verify everything works ...
# 4. ./migrate-gcs-arch.sh gs://my-bucket --delete-old # review what will be deleted
# 5. ./migrate-gcs-arch.sh gs://my-bucket --delete-old --apply # clean up old x86_64/
set -euo pipefail
BUCKET="${1:?Usage: $0 <bucket> [--apply] [--delete-old]}"
shift
APPLY=false
DELETE_OLD=false
for arg in "$@"; do
case "$arg" in
--apply) APPLY=true ;;
--delete-old) DELETE_OLD=true ;;
*) echo "Unknown flag: $arg"; exit 1 ;;
esac
done
# Normalize bucket name — strip gs:// prefix if provided, we add it back
BUCKET="${BUCKET#gs://}"
echo "Scanning gs://${BUCKET} for x86_64/ paths..."
echo ""
objects=$(gsutil ls -r "gs://${BUCKET}/**/x86_64/**" 2>/dev/null || true)
if [[ -z "$objects" ]]; then
echo "No x86_64/ paths found in gs://${BUCKET}"
exit 0
fi
count=0
if [[ "$DELETE_OLD" == true ]]; then
while IFS= read -r src; do
[[ -z "$src" ]] && continue
[[ "$src" == */ ]] && continue
if [[ "$APPLY" == true ]]; then
echo " DELETE $src"
gsutil rm "$src"
else
echo " [dry-run] would delete $src"
fi
((count++)) || true
done <<< "$objects"
echo ""
echo "Total: $count objects"
if [[ "$APPLY" != true ]]; then
echo ""
echo "This was a dry run. Add --apply to actually delete."
fi
else
while IFS= read -r src; do
[[ -z "$src" ]] && continue
[[ "$src" == */ ]] && continue
dst="${src/\/x86_64\///amd64/}"
if [[ "$APPLY" == true ]]; then
echo " COPY $src"
echo " -> $dst"
gsutil cp "$src" "$dst"
else
echo " [dry-run] $src"
echo " -> $dst"
fi
((count++)) || true
done <<< "$objects"
echo ""
echo "Total: $count objects"
if [[ "$APPLY" != true ]]; then
echo ""
echo "This was a dry run. Add --apply to actually copy."
fi
fi