---
# System prepended metadata

title: Internalsys migration

---

# Internalsys migration

## Stop services
```
ssh yap@internalsys.sinlead.com

sudo su -

docker stop ray_sidekiq_1

docker stop internalsys
```


## MYSQL 
```
ssh yap@internalsys.sinlead.com

sudo su -

mysql -h 192.168.96.2 -u root 

# session 不能關掉
FLUSH TABLES WITH READ LOCK;

mysqldump -h 192.168.96.2 -u root internalsys_db > backup.sql;

mysql -h 192.168.96.2 -u root 

unlock tables;

mv backup.sql /home/yap/

chown yap:yap /home/yap/backup.sql

# local
scp yap@internalsys.sinlead.com:~/backup.sql backup.sql

kubectl cp backup.sql default/mysql-primary-0:/tmp

kubectl exec -it mysql-primary-0 bash

mysql -u root -p

BN3CBMSsQf6QHuZN

DROP database internalsys_db;

CREATE database internalsys_db;

cd /tmp && mysql -u root -p internalsys_db < backup.sql

BN3CBMSsQf6QHuZN
```

## Redis
```bash
ssh yap@internalsys.sinlead.com

sudo su -

docker exec -it ray_redis_1 sh

redis-cli

save

docker cp ray_redis_1:/data/dump.rdb dump.rdb

mv dump.rdb /home/yap/

chown yap:yap /home/yap/dump.rdb

scp yap@internalsys.sinlead.com:~/dump.rdb dump.rdb

kubectl scale deploy redis --replicas=0

kubectl apply -f busybox.yaml

kubectl cp dump.rdb default/$(kubectl get po -l "app=busybox" -o jsonpath='{.items[0].metadata.name}'):/data

kubectl delete -f busybox.yaml

kubectl scale deploy redis --replicas=1
```

## Proxy to k8s
```
# 新增 upstream
upstream k8s {
    server 139.162.95.145:443;
}

# 修改 server
server {
    proxy_set_header Host internalsys.sinlead.com;
    
    proxy_pass https://k8s;
}
```


## 切 DNS
- 在 route53 把 internalsys.sinlead.com 指到 139.162.95.145