Created
May 11, 2026 07:10
-
-
Save koliadych/9fc7f0375559dbe6d087d0ec78a59bfd to your computer and use it in GitHub Desktop.
fintechner protect + count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| export AWS_PAGER="" | |
| REGION=ap-northeast-1 | |
| INSTANCE_ID=i-089ad4a6b76132ba2 | |
| echo "=== 1. Enable termination protection (idempotent) ===" | |
| aws --region "$REGION" ec2 modify-instance-attribute \ | |
| --instance-id "$INSTANCE_ID" \ | |
| --disable-api-termination "{\"Value\":true}" | |
| TERM=$(aws --region "$REGION" ec2 describe-instance-attribute \ | |
| --instance-id "$INSTANCE_ID" --attribute disableApiTermination \ | |
| --query 'DisableApiTermination.Value' --output text) | |
| echo " termination-protection: $TERM" | |
| echo | |
| echo "=== 2. DB row counts (base64-encoded query to avoid SSM mangle) ===" | |
| SQL_B64=$(base64 -w0 <<'SQL' | |
| SELECT 'users : '||COUNT(*) FROM users | |
| UNION ALL SELECT 'hl_credentials : '||COUNT(*) FROM hl_credentials | |
| UNION ALL SELECT 'strategy_cfg : '||COUNT(*) FROM strategy_configs | |
| UNION ALL SELECT 'strategy_decis : '||COUNT(*) FROM strategy_decisions | |
| UNION ALL SELECT 'orders : '||COUNT(*) FROM orders | |
| UNION ALL SELECT 'orders.filled : '||COUNT(*) FROM orders WHERE status='filled' | |
| UNION ALL SELECT 'orders.partial : '||COUNT(*) FROM orders WHERE status='partial' | |
| UNION ALL SELECT 'orders.rejected: '||COUNT(*) FROM orders WHERE status='rejected' | |
| UNION ALL SELECT 'fills : '||COUNT(*) FROM fills | |
| UNION ALL SELECT 'closed_trades : '||COUNT(*) FROM closed_trades | |
| UNION ALL SELECT 'copy_leaders : '||COUNT(*) FROM copy_leaders | |
| UNION ALL SELECT 'copy_pols (on) : '||COUNT(*) FROM copy_policies WHERE enabled=true | |
| UNION ALL SELECT 'copy_pols (off): '||COUNT(*) FROM copy_policies WHERE enabled=false; | |
| SQL | |
| ) | |
| cat > /tmp/ssm-count.json <<JSON | |
| {"commands": ["echo '$SQL_B64' | base64 -d > /tmp/q.sql && sudo docker cp /tmp/q.sql timescale:/tmp/q.sql && sudo docker exec timescale psql -U fintechner -d fintechner -tA -f /tmp/q.sql"]} | |
| JSON | |
| CMD_ID=$(aws --region "$REGION" ssm send-command \ | |
| --instance-ids "$INSTANCE_ID" \ | |
| --document-name AWS-RunShellScript \ | |
| --parameters file:///tmp/ssm-count.json \ | |
| --query Command.CommandId --output text) | |
| rm -f /tmp/ssm-count.json | |
| for i in $(seq 1 20); do | |
| sleep 3 | |
| STATUS=$(aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query Status --output text 2>/dev/null || echo Pending) | |
| case "$STATUS" in Success|Failed|Cancelled|TimedOut) break ;; esac | |
| done | |
| aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query StandardOutputContent --output text | |
| echo | |
| echo "=== 3. Connector binary commit (compare to feature/tokyo-deploy HEAD) ===" | |
| echo " on-box SHA: 6736672e1518a7a5 (from earlier status)" | |
| echo " latest commit: $(cd ~/work/fintechner 2>/dev/null && git log -1 --format=%h%n%s feature/tokyo-deploy 2>/dev/null || echo NOT-CLONED)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment