#!/bin/bash # Run this ON labmac3 after transferring backup # Usage: ssh duwenbo@192.168.1.77 'bash -s' < 03_restore_data.sh echo "=== Restoring Gitea data on labmac3 ===" cd /opt/gitea # Stop Gitea if running docker compose down 2>/dev/null # Restore data from backup if [ -d "/opt/gitea-backup/gitea-data" ]; then echo "Restoring from data volume backup..." cp -r /opt/gitea-backup/gitea-data/* ./data/ 2>/dev/null # Fix the ROOT_URL in app.ini to point to new IP if [ -f "./data/conf/app.ini" ]; then sed -i 's|ROOT_URL.*=.*|ROOT_URL = http://192.168.1.77:3300/|' ./data/conf/app.ini sed -i 's|SSH_DOMAIN.*=.*|SSH_DOMAIN = 192.168.1.77|' ./data/conf/app.ini echo "Updated ROOT_URL and SSH_DOMAIN in app.ini" fi elif [ -f "/opt/gitea-backup/gitea-dump.zip" ]; then echo "Restoring from gitea dump..." unzip /opt/gitea-backup/gitea-dump.zip -d /tmp/gitea-restore # Copy repos and database cp -r /tmp/gitea-restore/repos/* ./data/gitea/repositories/ 2>/dev/null cp /tmp/gitea-restore/gitea-db.sql ./data/ 2>/dev/null fi # Fix permissions sudo chown -R 1000:1000 ./data # Start Gitea docker compose up -d echo "Waiting for Gitea to start..." sleep 10 # Verify echo "=== Verification ===" curl -s http://localhost:3300/api/v1/version echo "" curl -s http://localhost:3300/api/v1/repos/search?limit=5 | python3 -c " import sys,json try: data=json.load(sys.stdin) repos = data.get('data', data) if isinstance(data, dict) else data print(f'Repos found: {len(repos)}') for r in repos[:5]: name = r.get('full_name', r.get('name', '?')) print(f' {name}') except: print('Could not parse response') " 2>/dev/null echo "" echo "=== Gitea should now be accessible at: ===" echo " http://192.168.1.77:3300/" echo "" echo "If this is a fresh install (no backup), create admin:" echo " docker exec -it gitea gitea admin user create --admin --username tianpu --password 'TianpuGit2026!' --email admin@tianpu.com"