Spaces:
Sleeping
Sleeping
File size: 1,277 Bytes
b155cd5 b8c3220 b155cd5 b8c3220 b155cd5 b8c3220 b22a5f1 b8c3220 b22a5f1 b8c3220 b22a5f1 b8c3220 b22a5f1 b8c3220 b155cd5 cb72d1d b22a5f1 b8c3220 b155cd5 b8c3220 b155cd5 b8c3220 | 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 | #!/bin/bash
# OCI設定の最適化
OCI_ENDPOINT="https://${OCI_NAMESPACE}.compat.objectstorage.${AWS_DEFAULT_REGION}.oraclecloud.com"
S3_BUCKET_URL="s3://${S3_BUCKET_NAME}/code-server-full-backup"
SYNC_DIR="/home/user/app/sync"
# AWS CLIの挙動をOCIに最適化
aws configure set default.s3.signature_version s3v4
# マルチパートアップロードの閾値を大きくしてMissingContentLengthを回避
aws configure set default.s3.multipart_threshold 1024MB
mkdir -p $SYNC_DIR/workspace $SYNC_DIR/user-data $SYNC_DIR/extensions
# 1. 起動時に復元
echo "📥 Restoring environment from OCI..."
aws s3 sync $S3_BUCKET_URL $SYNC_DIR --endpoint-url $OCI_ENDPOINT || echo "No backup found."
# 2. 定期バックアップ(MissingContentLength対策を追加)
(
while true; do
sleep 30
echo "📤 Snapshotting environment to OCI..."
# --no-guess-mime-type をつけると安定する場合があります
aws s3 sync $SYNC_DIR $S3_BUCKET_URL --delete --endpoint-url $OCI_ENDPOINT --no-guess-mime-type
done
) &
# 3. code-serverの起動
code-server \
--bind-addr 0.0.0.0:7860 \
--auth password \
--user-data-dir $SYNC_DIR/user-data \
--extensions-dir $SYNC_DIR/extensions \
--disable-telemetry \
$SYNC_DIR/workspace |