# Upgrade Existing Node

Use this path when an existing DeFCoN node already has wallet files, config, masternode config, or chain data.

## 1. Dry Run First

```bash
sudo bin/defcon-helper upgrade-existing --dry-run --image YOUR_DEFCON_IMAGE
```

The dry-run lists detected data and planned actions.

## 2. Apply Upgrade

```bash
sudo bin/defcon-helper upgrade-existing --image YOUR_DEFCON_IMAGE
```

The helper then:

1. runs the dry-run preview again
2. asks you to type `UPGRADE`
3. creates a timestamped backup
4. preserves existing config and data
5. installs Docker Compose files
6. stops/disables legacy `defcond.service` if present
7. starts `defcond` through Docker Compose

## Existing Config

If `/opt/defcon/config/defcon.conf` exists, it is preserved.

If only `/opt/defcon/data/defcon.conf` exists, it is copied into `/opt/defcon/config/defcon.conf` after backup.

Configs with public RPC exposure are refused.

## Rollback

List backups:

```bash
ls -la /opt/defcon/backups
```

Rollback overlays the selected backup and creates a new pre-rollback backup first:

```bash
sudo bin/defcon-helper rollback /opt/defcon/backups/YYYY-MM-DD-HHMMSS
```

The rollback command does not delete wallet or chain data.
