# Migration from Hostinger Secondary Server **Date:** December 21, 2025 **Current Secondary:** srvfailover01 (72.62.39.24) - Hostinger VPS **Reason:** Cost reduction - server too expensive for passive HA role --- ## Current Setup Analysis ### Hostinger Server (srvfailover01 - 72.62.39.24) - **Uptime:** 26 days - **Disk Usage:** 20GB / 99GB (21% used) - **Running Containers:** - trading-bot-v4-secondary (unhealthy - expected for passive) - trading-bot-postgres (streaming replica) - n8n (for webhook routing) - trading-bot-nginx (reverse proxy) - **Role:** Passive secondary with auto-failover via DNS (INWX API) - **Database:** PostgreSQL streaming replication from primary (95.216.52.28) - **DNS Failover:** Monitors primary every 30s, switches tradervone.v4.dedyn.io on failure ### What Needs to be Preserved **Critical Data:** 1. ✅ Trading bot code + configuration (synced daily from primary) 2. ✅ Database (replicated from primary - can restore from primary) 3. ✅ .env file with wallet keys (MUST backup securely) 4. ✅ n8n workflows (if different from primary) 5. ✅ DNS failover scripts (/usr/local/bin/dns-failover-monitor.py) 6. ✅ SSL certificates (if using Let's Encrypt) 7. ✅ Docker compose configurations 8. ✅ Logs for debugging (optional) **NOT Critical (can rebuild):** - node_modules (688MB) - .next (198MB) - .git (133MB - can clone from git) - Python virtual envs - Docker images (can rebuild) --- ## Space Requirements ### Minimum Backup Size (Critical Data Only) ``` Project files (without node_modules/.next/.git): ~500MB Database backup: 40MB n8n data: ~50MB Logs (optional): ~100MB ------------------------------------------- Total: ~700MB (compressed: ~200MB) ``` ### Recommended New Server Specs - **RAM:** 4GB minimum (8GB recommended) - **CPU:** 2 cores minimum - **Disk:** 50GB minimum (100GB recommended for growth) - **Network:** 1Gbps, low latency to primary - **Cost Target:** <$10/month (vs Hostinger's premium pricing) - **Alternatives:** Hetzner CX22 ($6/mo), Oracle Free Tier, Contabo VPS --- ## Pre-Migration Checklist ### 1. Verify Primary is Healthy ```bash # From anywhere curl -s http://95.216.52.28:3001/api/health | jq . # Check database replication status ssh root@95.216.52.28 'docker exec trading-bot-postgres psql -U postgres -c "SELECT client_addr, state, sync_state FROM pg_stat_replication;"' # Should show: 72.62.39.24 | streaming | async ``` ### 2. Stop Auto-Failover (CRITICAL) ```bash # Stop DNS failover monitor on Hostinger ssh root@72.62.39.24 'systemctl stop dns-failover' ssh root@72.62.39.24 'systemctl disable dns-failover' # Verify stopped ssh root@72.62.39.24 'systemctl status dns-failover' # Should show: inactive (dead) ``` ### 3. Document Current Configuration ```bash # Save current DNS state dig tradervone.v4.dedyn.io +short # Should return: 95.216.52.28 (primary) # Save database replication config ssh root@72.62.39.24 'docker exec trading-bot-postgres cat /var/lib/postgresql/data/postgresql.auto.conf' > /tmp/secondary-pg-config.txt # Save container status ssh root@72.62.39.24 'docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"' > /tmp/secondary-containers.txt ``` --- ## Migration Procedure ### Phase 1: Backup Critical Data (30 minutes) **Run this script on Hostinger server:** ```bash #!/bin/bash # Save as: /root/backup-for-migration.sh BACKUP_DATE=$(date +%Y%m%d_%H%M%S) BACKUP_DIR="/tmp/trading-bot-migration-$BACKUP_DATE" ARCHIVE_NAME="trading-bot-migration-$BACKUP_DATE.tar.gz" echo "🔄 Starting backup for migration..." mkdir -p "$BACKUP_DIR" # 1. Project files (exclude large unnecessary directories) echo "📦 Backing up project files..." cd /root/traderv4-secondary tar czf "$BACKUP_DIR/project-files.tar.gz" \ --exclude='node_modules' \ --exclude='.next' \ --exclude='.git' \ --exclude='*.log' \ --exclude='.backtester' \ --exclude='backtester/data/*.csv' \ --exclude='cluster' \ . # 2. .env file (CRITICAL - contains wallet keys) echo "🔐 Backing up environment variables..." cp /root/traderv4-secondary/.env "$BACKUP_DIR/.env" # 3. Database backup echo "💾 Backing up database..." docker exec trading-bot-postgres pg_dump -U postgres -Fc trading_bot_v4 > "$BACKUP_DIR/trading_bot_v4.dump" # 4. n8n workflows and data echo "📝 Backing up n8n data..." docker run --rm \ --volumes-from n8n \ -v "$BACKUP_DIR":/backup \ alpine tar czf /backup/n8n-data.tar.gz -C /home/node/.n8n . # 5. DNS failover scripts echo "🌐 Backing up DNS failover scripts..." mkdir -p "$BACKUP_DIR/dns-scripts" cp /usr/local/bin/dns-failover-monitor.py "$BACKUP_DIR/dns-scripts/" 2>/dev/null || echo "dns-failover-monitor.py not found" cp /usr/local/bin/manual-dns-switch.py "$BACKUP_DIR/dns-scripts/" 2>/dev/null || echo "manual-dns-switch.py not found" cp /etc/systemd/system/dns-failover.service "$BACKUP_DIR/dns-scripts/" 2>/dev/null || echo "dns-failover.service not found" # 6. Docker compose files echo "🐳 Backing up Docker configurations..." cp /root/traderv4-secondary/docker-compose*.yml "$BACKUP_DIR/" # 7. SSL certificates (if using Let's Encrypt) echo "🔒 Backing up SSL certificates..." if [ -d "/etc/letsencrypt" ]; then tar czf "$BACKUP_DIR/letsencrypt.tar.gz" -C /etc letsencrypt fi # 8. Logs (last 7 days only) echo "📋 Backing up recent logs..." journalctl -u dns-failover --since "7 days ago" > "$BACKUP_DIR/dns-failover-journal.log" 2>/dev/null || true docker logs trading-bot-v4-secondary --tail 10000 > "$BACKUP_DIR/trading-bot.log" 2>/dev/null || true cp /var/log/dns-failover.log "$BACKUP_DIR/" 2>/dev/null || true # 9. Create manifest echo "📄 Creating backup manifest..." cat > "$BACKUP_DIR/MANIFEST.txt" < /dev/null && echo "✅ Archive valid" || echo "❌ Archive corrupted" ``` ### Phase 3: Deploy on New Server (when ready) **Will provide detailed deployment script after you provide new server access.** Basic steps: 1. Install Docker + Docker Compose 2. Extract backup archive 3. Update IP addresses (72.62.39.24 → NEW_IP) in all configs 4. Setup PostgreSQL streaming replication from primary 5. Deploy containers 6. Update DNS failover scripts on primary to monitor NEW_IP 7. Test failover (stop primary, verify secondary takes over) 8. Monitor for 1-2 weeks before canceling Hostinger --- ## Decommissioning Hostinger (ONLY after new server proven) ### Pre-Decommission Checklist - [ ] New secondary running for 2+ weeks without issues - [ ] Successful failover test completed - [ ] DNS updates working correctly - [ ] Database replication healthy (0 lag) - [ ] Telegram alerts working from new secondary - [ ] No active trades during decommission window ### Safe Decommission ```bash # 1. Stop all containers ssh root@72.62.39.24 'cd /root/traderv4-secondary && docker compose down' # 2. Verify primary is NOT using Hostinger as replica ssh root@95.216.52.28 'docker exec trading-bot-postgres psql -U postgres -c "SELECT client_addr FROM pg_stat_replication;"' # Should NOT show 72.62.39.24 # 3. Final backup (just in case) ssh root@72.62.39.24 'docker exec trading-bot-postgres pg_dump -U postgres -Fc trading_bot_v4 > /tmp/final-backup.dump' scp root@72.62.39.24:/tmp/final-backup.dump /home/icke/backups/hostinger-final-backup.dump # 4. Cancel Hostinger subscription # (via Hostinger control panel) ``` --- ## Cost Savings ### Current Hostinger Cost (estimate) - Hostinger VPS Premium: ~$20-40/month - Annual cost: ~$240-480 ### Alternative Providers (recommendations) 1. **Hetzner CX22** - €5.83/month (~$6.50) - 2 vCPU, 4GB RAM, 40GB SSD, 20TB traffic - Located in Germany (good latency to primary) 2. **Oracle Cloud Free Tier** - FREE - 1-4 OCPU, 1-24GB RAM, 200GB storage - Lifetime free (with minimal usage) 3. **Contabo VPS S** - $6.99/month - 4 vCores, 8GB RAM, 200GB SSD - Unlimited traffic ### Estimated Savings - Moving to Hetzner: **$13-33/month saved** ($156-396/year) - Moving to Oracle Free: **$20-40/month saved** ($240-480/year) --- ## Security Considerations ⚠️ **CRITICAL: The .env file contains your Drift wallet private key** **Secure Transfer Methods:** 1. Use SCP over SSH (encrypted in transit) 2. Encrypt archive before transfer: `gpg -c trading-bot-migration.tar.gz` 3. Delete from Hostinger AFTER confirming new server works 4. Never transfer via unencrypted channels (FTP, HTTP, email) **After Migration:** 1. Rotate any API keys that were on Hostinger (if paranoid) 2. Update firewall rules on primary to block old IP (72.62.39.24) 3. Monitor for unauthorized access attempts --- ## Rollback Plan If new server fails: 1. **Immediate:** Re-enable DNS failover on Hostinger ```bash ssh root@72.62.39.24 'systemctl start dns-failover' ``` 2. **Restart containers:** ```bash ssh root@72.62.39.24 'cd /root/traderv4-secondary && docker compose up -d' ``` 3. **Verify health:** ```bash ssh root@72.62.39.24 'curl -s http://localhost:3001/api/health' ``` 4. **Keep Hostinger active** until new server stable --- ## Timeline 1. **Today (Dec 21):** Create backup, store safely ✅ (THIS SCRIPT) 2. **When new server ready:** Deploy and configure (1-2 hours) 3. **Week 1:** Test new secondary, monitor health checks 4. **Week 2:** Perform failover test (controlled) 5. **Week 3:** If stable, decommission Hostinger 6. **Week 4:** Confirm cost savings in billing --- ## Questions Before Proceeding 1. What's the budget for new secondary server? (<$10/mo?) 2. Geographic preference? (Europe/US/Asia) 3. Managed vs unmanaged? (Docker pre-installed or DIY?) 4. Any specific provider requirements/restrictions? --- ## Summary **Safe to proceed:** YES **Data at risk:** NO (all backed up to primary + this backup) **Downtime during migration:** ZERO (primary stays active) **Estimated savings:** $156-480/year **Time to complete:** 2-4 hours setup + 2 weeks validation **Next step:** Run backup script above, then provide new server access when ready.