Add backup script and redeployment guide
This commit is contained in:
+214
@@ -0,0 +1,214 @@
|
||||
# VM Redeployment Guide
|
||||
|
||||
This guide covers rebuilding all apps from scratch on a new VM after a total loss of `192.168.16.130`.
|
||||
|
||||
**What you need before starting:**
|
||||
- Access to your Gitea server (`git.yoda.ddnsgeek.com`)
|
||||
- The latest backup archive from `/opt/backups/vm-apps/` on the VPS
|
||||
- The backup encryption password (if you set one)
|
||||
- A fresh Ubuntu VM
|
||||
|
||||
---
|
||||
|
||||
## Step 1 — Prepare the new VM
|
||||
|
||||
```bash
|
||||
# Install Docker
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker.io docker-compose-plugin
|
||||
sudo systemctl enable --now docker
|
||||
sudo usermod -aG docker $USER
|
||||
# Log out and back in after this
|
||||
```
|
||||
|
||||
```bash
|
||||
# Install Git
|
||||
sudo apt-get install -y git
|
||||
|
||||
# Create app directories
|
||||
sudo mkdir -p /opt/rv50x-manager /opt/switch-config-manager /opt/lldp-mapper /opt/stunnel
|
||||
sudo chown $USER:$USER /opt/rv50x-manager /opt/switch-config-manager /opt/lldp-mapper /opt/stunnel
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 2 — Set up SSH key for Gitea
|
||||
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -C "new-vm" -f ~/.ssh/id_ed25519 -N ""
|
||||
cat ~/.ssh/id_ed25519.pub
|
||||
```
|
||||
|
||||
Add the public key to Gitea: `https://git.yoda.ddnsgeek.com/user/settings/keys`
|
||||
|
||||
Add the SSH config:
|
||||
```bash
|
||||
cat >> ~/.ssh/config << 'EOF'
|
||||
Host git.yoda.ddnsgeek.com
|
||||
HostName git.yoda.ddnsgeek.com
|
||||
User git
|
||||
Port 2222
|
||||
IdentityFile ~/.ssh/id_ed25519
|
||||
EOF
|
||||
```
|
||||
|
||||
Test:
|
||||
```bash
|
||||
ssh -T git@git.yoda.ddnsgeek.com
|
||||
# Should print: Hi there, dcstephenson! You've successfully authenticated...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 3 — Clone all repositories
|
||||
|
||||
```bash
|
||||
cd /opt/rv50x-manager
|
||||
git clone git@git.yoda.ddnsgeek.com:dcstephenson/rv50x-manager.git .
|
||||
|
||||
cd /opt/switch-config-manager
|
||||
git clone git@git.yoda.ddnsgeek.com:dcstephenson/switch-config-manager.git .
|
||||
|
||||
cd /opt/lldp-mapper
|
||||
git clone git@git.yoda.ddnsgeek.com:dcstephenson/lldp-mapper.git .
|
||||
|
||||
cd /opt/stunnel
|
||||
git clone git@git.yoda.ddnsgeek.com:dcstephenson/stunnel.git .
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 4 — Restore from backup
|
||||
|
||||
Copy the latest backup archive from the VPS:
|
||||
|
||||
```bash
|
||||
scp root@git.yoda.ddnsgeek.com:/opt/backups/vm-apps/vm-apps-backup_YYYYMMDD_HHMMSS.tar.gz.enc /tmp/
|
||||
```
|
||||
|
||||
Decrypt and extract:
|
||||
```bash
|
||||
# If encrypted:
|
||||
openssl enc -d -aes-256-cbc -pbkdf2 -iter 100000 \
|
||||
-in /tmp/vm-apps-backup_YYYYMMDD_HHMMSS.tar.gz.enc \
|
||||
-out /tmp/vm-apps-backup.tar.gz \
|
||||
-pass pass:"YOUR_BACKUP_PASSWORD"
|
||||
|
||||
# Extract
|
||||
mkdir /tmp/restore
|
||||
tar -xzf /tmp/vm-apps-backup.tar.gz -C /tmp/restore
|
||||
```
|
||||
|
||||
Restore secrets:
|
||||
```bash
|
||||
cp /tmp/restore/secrets/rv50x-manager.env /opt/rv50x-manager/.env
|
||||
cp /tmp/restore/secrets/switch-config-manager-config.py /opt/switch-config-manager/config.py
|
||||
cp /tmp/restore/secrets/lldp-mapper-config.py /opt/lldp-mapper/config.py
|
||||
mkdir -p /opt/rv50x-manager/certs
|
||||
cp /tmp/restore/secrets/cert.pem /opt/rv50x-manager/certs/
|
||||
cp /tmp/restore/secrets/key.pem /opt/rv50x-manager/certs/
|
||||
```
|
||||
|
||||
Restore rv50x-manager runtime data:
|
||||
```bash
|
||||
cp /tmp/restore/rv50x-manager/rv50x.db /opt/rv50x-manager/
|
||||
cp /tmp/restore/rv50x-manager/at_presets.json /opt/rv50x-manager/
|
||||
cp -r /tmp/restore/rv50x-manager/xml_templates /opt/rv50x-manager/
|
||||
```
|
||||
|
||||
Restore switch configs:
|
||||
```bash
|
||||
cp -r /tmp/restore/switch-config-manager/configs /opt/switch-config-manager/
|
||||
```
|
||||
|
||||
Restore lldp-mapper topology data:
|
||||
```bash
|
||||
cp -r /tmp/restore/lldp-mapper/data /opt/lldp-mapper/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 5 — Start the rv50x stack and restore NocoDB database
|
||||
|
||||
```bash
|
||||
cd /opt/rv50x-manager
|
||||
|
||||
# Start postgres and nocodb only (not the app yet)
|
||||
docker compose up -d postgres
|
||||
# Wait for postgres to be healthy
|
||||
docker compose up -d nocodb
|
||||
```
|
||||
|
||||
Restore the PostgreSQL dump:
|
||||
```bash
|
||||
docker exec -i rv50x-postgres psql -U nocodb nocodb < /tmp/restore/rv50x-manager/nocodb_postgres.sql
|
||||
```
|
||||
|
||||
Start the full stack:
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
docker compose ps
|
||||
# All three containers should be running/healthy
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 6 — Start remaining apps
|
||||
|
||||
```bash
|
||||
cd /opt/switch-config-manager
|
||||
docker compose up -d --build
|
||||
|
||||
cd /opt/lldp-mapper
|
||||
docker compose up -d --build
|
||||
|
||||
cd /opt/stunnel
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 7 — Verify everything is working
|
||||
|
||||
| App | URL |
|
||||
|-----|-----|
|
||||
| rv50x-manager | `http://NEW-VM-IP:8002` |
|
||||
| rv50x-nocodb | `http://NEW-VM-IP:8090` |
|
||||
| switch-config-manager | `http://NEW-VM-IP:8003` |
|
||||
| lldp-mapper | `http://NEW-VM-IP:5000` |
|
||||
| stunnel | `https://NEW-VM-IP:4500` (through to first switch) |
|
||||
|
||||
Check rv50x-manager loads devices from NocoDB — if devices appear, the Postgres restore worked.
|
||||
|
||||
---
|
||||
|
||||
## Step 8 — Clean up
|
||||
|
||||
```bash
|
||||
rm -rf /tmp/restore /tmp/vm-apps-backup*
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Backup location on VPS
|
||||
|
||||
Backups are stored at:
|
||||
```
|
||||
root@git.yoda.ddnsgeek.com:/opt/backups/vm-apps/
|
||||
```
|
||||
|
||||
The last 7 backups are kept. To list them:
|
||||
```bash
|
||||
ssh root@git.yoda.ddnsgeek.com "ls -lht /opt/backups/vm-apps/"
|
||||
```
|
||||
|
||||
## Running a backup
|
||||
|
||||
On this VM:
|
||||
```bash
|
||||
/opt/backup.sh
|
||||
```
|
||||
Reference in New Issue
Block a user