完成真实成对异机备份(07-26-internal-ops-recovery-baseline)
这个提交包含在:
+45
-2
@@ -67,8 +67,13 @@ STORAGE_BYTES="$(wc -c <"$STORAGE_FILE" | tr -d ' ')"
|
||||
BUILD_SHA="$(git -C "$ROOT_DIR" rev-parse --short=12 HEAD 2>/dev/null || true)"
|
||||
CREATED_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
|
||||
node - "$TEMP_DIR/$MANIFEST_NAME" "$BACKUP_RUN_ID" "$CREATED_AT" "$BUILD_SHA" \
|
||||
"$DB_NAME" "$DB_BYTES" "$DB_SHA256" "$STORAGE_NAME" "$STORAGE_BYTES" "$STORAGE_SHA256" <<'NODE'
|
||||
MANIFEST_ARGS=(
|
||||
"$TEMP_DIR/$MANIFEST_NAME" "$BACKUP_RUN_ID" "$CREATED_AT" "$BUILD_SHA"
|
||||
"$DB_NAME" "$DB_BYTES" "$DB_SHA256" "$STORAGE_NAME" "$STORAGE_BYTES" "$STORAGE_SHA256"
|
||||
)
|
||||
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
node - "${MANIFEST_ARGS[@]}" <<'NODE'
|
||||
const fs = require("node:fs");
|
||||
const [manifestPath, runId, createdAt, buildSha, dbFile, dbBytes, dbSha256, storageFile, storageBytes, storageSha256] = process.argv.slice(2);
|
||||
const manifest = {
|
||||
@@ -84,6 +89,44 @@ const manifest = {
|
||||
};
|
||||
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, { encoding: "utf8", flag: "wx" });
|
||||
NODE
|
||||
elif command -v python3 >/dev/null 2>&1; then
|
||||
python3 - "${MANIFEST_ARGS[@]}" <<'PYTHON'
|
||||
import json
|
||||
import sys
|
||||
|
||||
(
|
||||
manifest_path,
|
||||
run_id,
|
||||
created_at,
|
||||
build_sha,
|
||||
db_file,
|
||||
db_bytes,
|
||||
db_sha256,
|
||||
storage_file,
|
||||
storage_bytes,
|
||||
storage_sha256,
|
||||
) = sys.argv[1:]
|
||||
|
||||
manifest = {
|
||||
"schemaVersion": 1,
|
||||
"runId": run_id,
|
||||
"createdAt": created_at,
|
||||
"buildSha": build_sha or None,
|
||||
"status": "complete",
|
||||
"artifacts": {
|
||||
"database": {"file": db_file, "bytes": int(db_bytes), "sha256": db_sha256},
|
||||
"storage": {"file": storage_file, "bytes": int(storage_bytes), "sha256": storage_sha256},
|
||||
},
|
||||
}
|
||||
|
||||
with open(manifest_path, "x", encoding="utf-8") as manifest_file:
|
||||
json.dump(manifest, manifest_file, ensure_ascii=True, indent=2)
|
||||
manifest_file.write("\n")
|
||||
PYTHON
|
||||
else
|
||||
echo "[ERR] node or python3 is required to write the backup manifest" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv "$TEMP_DIR" "$FINAL_DIR"
|
||||
TEMP_DIR=""
|
||||
|
||||
在新工单中引用
屏蔽一个用户