haste/MIGRATION.md

188 lines
5.3 KiB
Markdown

# Migration Guide: macmini3 → ingress.nixc.us
This guide explains how to migrate the haste.nixc.us services from macmini3 to ingress.nixc.us.
## Prerequisites
1. **SSH Access**: Ensure you have SSH key-based authentication set up for both hosts:
- `macmini3` (source)
- `ingress.nixc.us` (target)
The script uses non-interactive SSH commands like:
```bash
ssh macmini3 "command"
ssh ingress.nixc.us "command"
```
2. **Docker Swarm**: Both hosts should be part of the same Docker Swarm cluster, or you need to deploy to the target's Swarm manager.
3. **Volume Access**: The script needs to access Docker volumes on both hosts.
## Migration Steps
### Option 1: Automated Migration (Recommended)
Run the full migration script which handles everything:
```bash
./migrate-to-ingress.sh
```
The script will:
1. Verify SSH connectivity to both hosts
2. Backup Docker volumes (`redis_data` and `public_system`) from macmini3
3. Transfer backups to ingress.nixc.us
4. Restore volumes on ingress.nixc.us
5. Update `stack.production.yml` to use the new hostname
6. Deploy the stack to the new location
7. Verify the deployment
8. Clean up temporary files
### Option 2: Manual Migration
If you prefer to migrate manually or need more control:
#### Step 1: Update Stack Configuration
```bash
# Auto-detect hostname
./update-stack-hostname.sh
# Or specify hostname explicitly
./update-stack-hostname.sh ingress
```
#### Step 2: Backup Volumes from macmini3
```bash
BACKUP_DIR="/tmp/haste-migration-$(date +%Y%m%d-%H%M%S)"
ssh macmini3 "mkdir -p ${BACKUP_DIR}"
# Backup redis_data
ssh macmini3 "docker run --rm -v haste_redis_data:/source:ro -v ${BACKUP_DIR}:/backup alpine:latest tar czf /backup/redis_data.tar.gz -C /source ."
# Backup public_system
ssh macmini3 "docker run --rm -v haste_public_system:/source:ro -v ${BACKUP_DIR}:/backup alpine:latest tar czf /backup/public_system.tar.gz -C /source ."
```
#### Step 3: Transfer Backups
```bash
ssh ingress.nixc.us "mkdir -p ${BACKUP_DIR}"
scp macmini3:${BACKUP_DIR}/*.tar.gz ingress.nixc.us:${BACKUP_DIR}/
```
#### Step 4: Restore Volumes on ingress.nixc.us
```bash
# Create volumes
ssh ingress.nixc.us "docker volume create haste_redis_data"
ssh ingress.nixc.us "docker volume create haste_public_system"
# Restore redis_data
ssh ingress.nixc.us "docker run --rm -v haste_redis_data:/target -v ${BACKUP_DIR}:/backup alpine:latest sh -c 'rm -rf /target/* && tar xzf /backup/redis_data.tar.gz -C /target'"
# Restore public_system
ssh ingress.nixc.us "docker run --rm -v haste_public_system:/target -v ${BACKUP_DIR}:/backup alpine:latest sh -c 'rm -rf /target/* && tar xzf /backup/public_system.tar.gz -C /target'"
```
#### Step 5: Deploy Updated Stack
```bash
scp stack.production.yml ingress.nixc.us:/tmp/
ssh ingress.nixc.us "docker stack deploy --with-registry-auth -c /tmp/stack.production.yml haste"
```
#### Step 6: Verify Deployment
```bash
ssh ingress.nixc.us "docker stack services haste"
```
#### Step 7: Test Service
Visit https://haste.nixc.us and verify it's working correctly.
#### Step 8: Cleanup Old Deployment (when ready)
```bash
ssh macmini3 "docker stack rm haste"
ssh macmini3 "docker volume rm haste_redis_data haste_public_system"
```
## Configuration
The migration script supports environment variables for customization:
```bash
# Customize source/target hosts
SOURCE_HOST=macmini3 TARGET_HOST=ingress.nixc.us ./migrate-to-ingress.sh
# Customize stack name (default: haste)
STACK_NAME=haste-production ./migrate-to-ingress.sh
# Specify target hostname explicitly
TARGET_HOSTNAME=ingress ./migrate-to-ingress.sh
# Enable automatic cleanup of old deployment
CLEANUP_OLD=true ./migrate-to-ingress.sh
```
## Troubleshooting
### SSH Connection Issues
If you get SSH connection errors:
- Ensure SSH keys are set up: `ssh-copy-id user@macmini3` and `ssh-copy-id user@ingress.nixc.us`
- Test connectivity: `ssh macmini3 "echo OK"` and `ssh ingress.nixc.us "echo OK"`
- The script uses `-o BatchMode=yes` for non-interactive SSH, which requires key-based auth (no password prompts)
### Volume Not Found
If volumes are not found, check the actual volume names:
```bash
ssh macmini3 "docker volume ls | grep haste"
```
Docker Swarm prefixes volumes with the stack name, so `redis_data` becomes `haste_redis_data` if the stack is named `haste`.
### Hostname Detection
The script auto-detects the target hostname. If it's incorrect, specify it explicitly:
```bash
TARGET_HOSTNAME=ingress ./migrate-to-ingress.sh
```
### Stack Deployment Issues
If deployment fails, check:
- Docker Swarm is initialized on the target
- You have access to the Swarm manager
- Registry authentication is set up
## Rollback
If something goes wrong, you can rollback:
1. Restore the original stack file:
```bash
mv stack.production.yml.bak stack.production.yml
```
2. Redeploy to macmini3:
```bash
ssh macmini3 "docker stack deploy --with-registry-auth -c stack.production.yml haste"
```
3. Remove volumes from ingress.nixc.us if needed:
```bash
ssh ingress.nixc.us "docker volume rm haste_redis_data haste_public_system"
```
## Notes
- The migration script creates backups before making changes
- Original `stack.production.yml` is backed up with `.bak` extension
- Temporary backup files are cleaned up automatically
- Old deployment on macmini3 is NOT removed automatically (set `CLEANUP_OLD=true` to enable)