| #!/bin/bash |
|
|
| |
| |
| |
|
|
| set -euo pipefail |
|
|
| |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| DTO_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" |
| ENV_FILE="$DTO_ROOT/.env" |
|
|
| if [ -f "$ENV_FILE" ]; then |
| export $(grep -v '^#' "$ENV_FILE" | xargs) |
| echo "β
Loaded .env file from $ENV_FILE" |
| else |
| echo "β .env file not found at $ENV_FILE" |
| exit 1 |
| fi |
|
|
| |
| MIGRATION_LOG="/tmp/migration_$(date +%Y%m%d_%H%M%S).log" |
| BACKUP_DIR="/tmp/migration_backup_$(date +%Y%m%d_%H%M%S)" |
| TIMESTAMP=$(date +%Y%m%d_%H%M%S) |
|
|
| |
| RED='\033[0;31m' |
| GREEN='\033[0;32m' |
| YELLOW='\033[1;33m' |
| BLUE='\033[0;34m' |
| NC='\033[0m' |
|
|
| |
| log() { |
| echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1" | tee -a "$MIGRATION_LOG" |
| } |
|
|
| error() { |
| echo -e "${RED}[ERROR]${NC} $1" | tee -a "$MIGRATION_LOG" >&2 |
| } |
|
|
| warning() { |
| echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$MIGRATION_LOG" |
| } |
|
|
| info() { |
| echo -e "${BLUE}[INFO]${NC} $1" | tee -a "$MIGRATION_LOG" |
| } |
|
|
| |
| pre_migration_prep() { |
| log "=== PHASE 1: Pre-Migration Preparation ===" |
| |
| |
| mkdir -p "$BACKUP_DIR" |
| |
| |
| log "Verifying Hugging Face authentication" |
| python3 -c " |
| from huggingface_hub import HfApi |
| try: |
| api = HfApi(token='$HF_TOKEN') |
| user = api.whoami() |
| print(f'β
Authenticated as: {user[\"name\"]}') |
| print(f'β
Organization: {user.get(\"orgs\", [{}])[0].get(\"name\", \"Personal\")}') |
| except Exception as e: |
| print(f'β Authentication failed: {e}') |
| exit(1) |
| " | tee -a "$MIGRATION_LOG" |
| |
| |
| log "Checking repository access" |
| for repo in "$HF_REPO_MODELS" "$HF_REPO_DATASETS" "$HF_REPO_ARTIFACTS"; do |
| python3 -c " |
| from huggingface_hub import HfApi, RepositoryNotFoundError |
| |
| try: |
| api = HfApi(token='$HF_TOKEN') |
| info = api.repo_info('$repo') |
| print(f'β
Repository accessible: $repo ({info.size} bytes)') |
| except RepositoryNotFoundError: |
| print(f'β οΈ Repository not found: $repo (will create)') |
| except Exception as e: |
| print(f'β Error accessing $repo: {e}') |
| exit(1) |
| " | tee -a "$MIGRATION_LOG" |
| done |
| |
| |
| log "Creating inventory of critical files" |
| find /data/adaptai/aiml/02_models -type f -name "*.safetensors" -o -name "*.pt" -o -name "*.bin" | head -20 > "$BACKUP_DIR/critical_models.txt" |
| find /data/adaptai/aiml/03_training -type f -name "*.parquet" -o -name "*.jsonl" -o -name "*.csv" | head -20 > "$BACKUP_DIR/critical_datasets.txt" |
| |
| log "Pre-migration preparation completed" |
| } |
|
|
| |
| rapid_upload() { |
| log "=== PHASE 2: Rapid Upload to HF/Xet ===" |
| |
| |
| log "Uploading critical models..." |
| python3 -c " |
| import os |
| from integrations.huggingface_client import HuggingFaceClient |
| |
| client = HuggingFaceClient() |
| if not client.is_authenticated(): |
| print('β Not authenticated') |
| exit(1) |
| |
| # Upload most critical model files first |
| critical_files = [] |
| for root, dirs, files in os.walk('/data/adaptai/aiml/02_models'): |
| for file in files: |
| if file.endswith(('.safetensors', '.pt', '.bin')): |
| full_path = os.path.join(root, file) |
| critical_files.append(full_path) |
| if len(critical_files) >= 50: # Limit for rapid upload |
| break |
| if len(critical_files) >= 50: |
| break |
| |
| for file_path in critical_files: |
| rel_path = os.path.relpath(file_path, '/data/adaptai/aiml/02_models') |
| print(f'π UPLOADING: {rel_path}') |
| success = client.upload_artifact(file_path, rel_path, '$HF_REPO_MODELS') |
| if not success: |
| print(f'β FAILED: {rel_path}') |
| exit(1) |
| |
| print('β
Critical models uploaded successfully') |
| " | tee -a "$MIGRATION_LOG" |
| |
| |
| log "Uploading critical datasets..." |
| python3 -c " |
| import os |
| from integrations.huggingface_client import HuggingFaceClient |
| |
| client = HuggingFaceClient() |
| |
| # Upload critical dataset files |
| for root, dirs, files in os.walk('/data/adaptai/aiml/03_training'): |
| for file in files: |
| if file.endswith(('.parquet', '.jsonl')): |
| full_path = os.path.join(root, file) |
| rel_path = os.path.relpath(full_path, '/data/adaptai/aiml/03_training') |
| print(f'π UPLOADING: {rel_path}') |
| success = client.upload_artifact(full_path, rel_path, '$HF_REPO_DATASETS') |
| if not success: |
| print(f'β FAILED: {rel_path}') |
| exit(1) |
| if len([f for f in os.listdir('/data/adaptai/aiml/03_training') if f.endswith(('.parquet', '.jsonl'))]) <= 10: |
| break # Stop after first 10 files for rapid migration |
| |
| print('β
Critical datasets uploaded successfully') |
| " | tee -a "$MIGRATION_LOG" |
| |
| log "Rapid upload phase completed" |
| } |
|
|
| |
| verification_cleanup() { |
| log "=== PHASE 3: Verification & Cleanup ===" |
| |
| |
| log "Verifying uploads..." |
| python3 -c " |
| from huggingface_hub import HfApi |
| |
| api = HfApi(token='$HF_TOKEN') |
| |
| for repo in ['$HF_REPO_MODELS', '$HF_REPO_DATASETS']: |
| try: |
| info = api.repo_info(repo) |
| print(f'β
{repo}: {len(info.siblings)} files, {info.size} bytes') |
| except Exception as e: |
| print(f'β Failed to verify {repo}: {e}') |
| exit(1) |
| " | tee -a "$MIGRATION_LOG" |
| |
| |
| log "Creating cleanup manifest..." |
| find /data/adaptai/aiml/02_models -type f -name "*.safetensors" -o -name "*.pt" -o -name "*.bin" | head -50 > "$BACKUP_DIR/cleanup_manifest.txt" |
| |
| log "Verification completed - Ready for cleanup" |
| } |
|
|
| |
| rapid_migration() { |
| log "=== PHASE 4: Rapid Server Migration ===" |
| |
| |
| log "Generating migration package..." |
| MIGRATION_PACKAGE="/tmp/dto_migration_$TIMESTAMP.tar.gz" |
| |
| tar -czf "$MIGRATION_PACKAGE" \ |
| -C /data/adaptai/platform/dataops/dto \ |
| .env \ |
| integrations/ \ |
| scripts/ \ |
| dto_manifest.yaml \ |
| --exclude="*.pyc" --exclude="__pycache__" |
| |
| echo "β
Migration package created: $MIGRATION_PACKAGE ($(du -h $MIGRATION_PACKAGE | cut -f1))") | tee -a "$MIGRATION_LOG" |
| |
| |
| cat > "/tmp/rapid_setup.sh" << 'EOF' |
| |
| |
| |
|
|
| set -euo pipefail |
|
|
| |
| tar -xzf $1 -C /tmp/dto_setup |
| cd /tmp/dto_setup |
|
|
| |
| export $(grep -v '^#' .env | xargs) |
|
|
| |
| pip install huggingface_hub hf-xet --upgrade |
|
|
| |
| python3 -c " |
| from huggingface_hub import HfApi |
| try: |
| api = HfApi(token='$HF_TOKEN') |
| user = api.whoami() |
| print(f'β
Authenticated as: {user[\"name\"]}') |
| except Exception as e: |
| print(f'β Authentication failed: {e}') |
| exit(1) |
| " |
|
|
| |
| python3 -c " |
| from integrations.huggingface_client import HuggingFaceClient |
| client = HuggingFaceClient() |
| |
| # Download most critical models |
| print('Downloading critical models...') |
| # Add specific file downloads here based on priority |
| " |
|
|
| echo "β
Rapid setup completed - DTO Framework ready" |
| EOF |
| |
| chmod +x "/tmp/rapid_setup.sh" |
| |
| log "Rapid migration preparation completed" |
| log "Migration package: $MIGRATION_PACKAGE" |
| log "Setup script: /tmp/rapid_setup.sh" |
| } |
|
|
| |
| emergency_cleanup() { |
| log "=== EMERGENCY CLEANUP (IF SPACE CRITICAL) ===" |
| warning "THIS WILL DELETE LOCAL COPIES AFTER UPLOAD VERIFICATION" |
| |
| |
| if [ -f "$BACKUP_DIR/cleanup_manifest.txt" ] && [ $(wc -l < "$BACKUP_DIR/cleanup_manifest.txt") -gt 0 ]; then |
| log "Removing uploaded files..." |
| while read -r file; do |
| if [ -f "$file" ]; then |
| rm -v "$file" | tee -a "$MIGRATION_LOG" |
| fi |
| done < "$BACKUP_DIR/cleanup_manifest.txt" |
| |
| log "Emergency cleanup completed" |
| df -h /data | tee -a "$MIGRATION_LOG" |
| else |
| warning "No cleanup manifest found - skipping emergency cleanup" |
| fi |
| } |
|
|
| |
| main() { |
| log "π STARTING 30-MINUTE SERVER MIGRATION PLAN" |
| log "Timestamp: $(date)" |
| log "Migration log: $MIGRATION_LOG" |
| log "Backup directory: $BACKUP_DIR" |
| |
| |
| pre_migration_prep |
| rapid_upload |
| verification_cleanup |
| rapid_migration |
| |
| |
| if [ "${1:-}" = "--cleanup" ]; then |
| emergency_cleanup |
| fi |
| |
| log "β
30-MINUTE MIGRATION PLAN COMPLETED SUCCESSFULLY" |
| log "Next steps:" |
| log " 1. Transfer migration package to new server" |
| log " 2. Run: /tmp/rapid_setup.sh /path/to/migration_package.tar.gz" |
| log " 3. Complete full uploads with upload_to_hf.sh" |
| log " 4. Monitor new server deployment" |
| } |
|
|
| |
| main "$@" |