> Documentation index for agents: /hcp/3.3/en/llms.txt

# Back up the node configuration

Before you upgrade or reinstall a node, take a copy of its configuration: you use it to rebuild the node or return it to its previous state. The `vstackos.config-backup.sh` script does this in one run and changes nothing on the node except its own directory. This is not a data backup: the disks of virtual machines (VMs), pool data and ZFS snapshots are not included in the collection.

## Why a separate collection

The update script also saves the configuration. Before the update, it copies `/etc`, `/usr/local/etc`, `vstack-env.conf` and the boot files `/boot/loader.conf`, `/boot/loader.conf.local`, `/boot/device.hints`. After the update, it restores the accounts, the SSH settings, several system files and these three boot files — [Update nodes to 3.2.6, step 7](/hcp/3.3/en/upgrade/update-nodes/index.md#node-update).

This copy has two weaknesses. It is stored in `/var/backups` on the node's system disk and is lost with that disk during a reinstallation. And it does not cover part of the node state:

| Not covered by the update script copy | Consequence |
| - | - |
| the cluster manager configuration and database | nothing to restore the node's cluster membership and the service layout from |
| the disk partitioning, the system disk mirror, the EFI partitions | nothing to recreate the boot disk from during a reinstallation |
| the definitions of the node's VMs | nothing to restore the machine configuration from |
| the package list and the repository priorities | nothing to reproduce the same build from during a rollback |

## Before you begin

- You have the `vstackos.config-backup.sh` script. It is part of the script kit: download `https://docs.vstack.com/hcp/3.2/files/upgrade-3.0-to-3.2/upgrade-3.0-to-3.2-tools.tar.gz` and `SHA256SUMS`, verify the archive and unpack it as in step 2 of the page [Move to 3.2 with Center 3.0.3–3.2.0](/hcp/3.3/en/upgrade/from-earlier/center-3-0/index.md#kit); the script is `tools/vstackos.config-backup.sh`.
- You have SSH access with `root` privileges to the node and 256 MB of free space in the collection directory. A collection usually takes 5–8 MB.
- The node is working in the cluster as usual: take the copy before you move pools off it. After the pools stop, part of the node state can no longer be obtained: the script notices this and warns you. You do not need a maintenance window — the script only reads and writes to its own directory.
- You have decided where to move the copy: the administrator's workstation and a second medium with a case-sensitive file system. The copy contains the node's password files and private SSH keys: store it like access keys, accessible to administrators only.

## 1. Collect the configuration

1. Run the collection on the node:

   ```sh
   sh vstackos.config-backup.sh --tag before-upgrade
   ```

   You can do the same from the workstation, without copying the script to the node:

   ```sh
   ssh root@<node> 'sh -s -- --tag before-upgrade' < vstackos.config-backup.sh
   ```

2. Check the exit code: `0` — the collection is clean, `2` — collected, but with warnings, `1` — the script did not start.

The `root` shell on the node is `csh`. Pass the script arguments inside single quotes, and do not use spaces or `>` in the `--tag` label: otherwise `csh` parses them its own way, creates an extra file in `/root`, and the script prints its help instead of collecting.

The collection goes to `/root/vstackos-config-backup/<cluster>/<UTC date>/<node>/`, and the directory is created with permissions 700. The script detects the cluster name by itself and prints it at startup: first it takes the prefix of a node name like `<cluster>u<NNN>`, then `cluster_id` from `vstack-env.conf`, and as a last resort the whole node name. If the name is wrong, set the directory with the `--out` option.

## 2. Read the collection report

```sh
cat <collection directory>/00-summary/SUMMARY.txt    # node profile, collection size, check summary
cat <collection directory>/00-summary/checks.txt     # PASS/FAIL for the critical parts
cat <collection directory>/00-summary/warnings.txt   # what was not collected
```

`FAIL` for the cluster manager database, `vstack-env.conf`, the disk partitioning or the VM definitions means stop. Do not start the upgrade until you find out why this part was not collected: contact vStack support with the report.

## 3. Put the collection in three places

By default, the collection is on the node's system disk — the disk that the upgrade overwrites and that is lost during a reinstallation. This one copy is not enough.

| Where | How | Who does it |
| - | - | - |
| on the node | the collection directory | the script |
| a second medium: the node's boot USB drive, another pool, a mounted network share | `--copy-to <mount point>`: the script copies the collection and verifies the copy against checksums; you can specify the option several times | the script |
| off the node: the administrator's workstation | a `tar` stream, see below | the administrator |

At the end of the run, the script prints the three places marked `[done]` or `[NOT done]`. The third mark is always `NOT done`: only the administrator can move the collection off the node.

### USB drive

Writing the installation image with `dd` erases everything that was on the medium, so put the collection on it after you write the image. The collection goes to a UFS partition of the USB drive, for example the partition of the memstick image. A FAT partition does not fit: it is not case-sensitive, and the script refuses to write to it.

```sh
glabel status -s | grep FreeBSD_Install   # USB drive with the memstick image: ufs/FreeBSD_Install  N/A  da<N>s2a
mount -t ufs /dev/ufs/FreeBSD_Install /mnt
sh vstackos.config-backup.sh --copy-to /mnt
umount /mnt
```

The memstick image has MBR partitioning: the first slice is EFI (FAT), the second is UFS with the `FreeBSD_Install` label, the `da<N>s2a` partition. The USB drive has its own `da<N>` number — do not confuse it with the node's system disk.

### File name case

The medium must be case-sensitive. The node has files whose names differ only in case. A FAT USB drive, a Windows disk and a default macOS volume treat such names as one file, and the copy there silently loses one file of each pair. The script checks the medium before copying and refuses to write to a medium that is not case-sensitive. On macOS and Windows, keep the collection as an archive (the `--tar` option or the `tar` stream below), and unpack it where the file system is case-sensitive.

### Move the collection off the node as a `tar` stream

The collection contains about a thousand small files. `scp -r` transfers them one by one, which is slow over a link with latency; a `tar` stream transfers them as one stream.

```sh
D=/root/vstackos-config-backup/<cluster>/<date>

# the receiver is case-sensitive: unpack straight to a directory
ssh root@<node> "tar czf - -C $D <node>" | tar xzf -

# macOS or Windows: keep as an archive, do not unpack
ssh root@<node> "tar czf - -C $D <node>" > vstackos-config-backup-<node>-<date>.tar.gz
```

It is convenient to lay out the storage off the node the same way as on the node — then you move a collection by simple copying:

```text
<store dir>/<cluster>/<date>/vstackos-config-backup-<node>-<date>.tar.gz
                             CHECKSUMS.sha256
```

## 4. Repeat on each node

You upgrade the cluster one node at a time, and you take the collection node by node as well. The node name is the last level of the directory, so collections from different nodes do not collide either on the USB drive or in shared storage.

## Check the result

Each copy is verified against its own manifest. You do not need `root` privileges for this: run the check where the copy is. The script selects the hashing utility (`sha256`, `sha256sum` or `shasum`) by what is available on the machine.

```sh
sh vstackos.config-backup.sh --verify <backup directory>
# verified NNN files ... mismatched 0     -> the copy is intact (code 0)
# MISMATCH ./30-config/etc/rc.conf        -> the copy is damaged (code 2)
```

`MISMATCH` lines and code `2` mean the copy is damaged: take the copy and move it off the node again. The manifest covers the collected material; the report files of the run itself are not included in it.

## After the upgrade: the "after" collection and comparison

Take a second collection to a separate directory and compare it with the first one:

```sh
ssh root@<node> 'sh -s -- --out /root/vstackos-config-backup/<cluster>/<date>-after/<node> --tag after-upgrade' < vstackos.config-backup.sh
diff -r <before>/30-config <after>/30-config | head -50
diff <before>/20-packages/pkg-versions.txt <after>/20-packages/pkg-versions.txt
```

First of all, look for `*.pkgnew` and `*.pkgsave` files in the configuration, missing packages and tuning parameters that differ. Compare tuning by the effective values, not by the file: `sysctl -n <variable>`.

## Script options

| Option | When you need it |
| - | - |
| `--dry-run` | show the collection plan and write nothing; useful for agreeing on the run in advance |
| `--tag <label>` | a mark in the report: the target version, the ticket number |
| `-o`, `--out <directory>` | another directory, for example for a repeated "after" collection |
| `--copy-to <directory>` | duplicate the collection to a mounted medium right away and verify the copy against checksums; you can specify the option several times |
| `--tar` | also pack the collection into `vstackos-config-backup-<node>-<date>.tar.gz` next to the directory |
| `--verify <directory>` | verify a finished copy against its manifest and exit |
| `--no-secrets` | do not include the password files (`master.passwd`, `spwd.db`) and the node's private SSH keys in the copy. In that case, during a restore you have to get the node's accounts and keys from another source |
| `--with-logs` | add the tails of the logs from `/var/log` |

## What not to do

- **Do not mix collections from different nodes:** each node has its own node ID, `vstack-env.conf` and cluster manager database; if you mix them up, they break the cluster.
- **Do not keep the only copy on the node:** it is on the system disk, which a reinstallation erases.
- **Do not unpack the collection on FAT, a Windows disk or a default macOS volume:** the node has files whose names differ only in case, and the copy silently loses them.
- **Do not move the collection off the node with `scp -r`:** move it as a `tar` stream, as in step 3.

## Next

- [Update nodes to 3.2.6](/hcp/3.3/en/upgrade/update-nodes/index.md)
- [Upgrade a 3.0, 3.1 or 3.2.0 node to 3.2.6](/hcp/3.3/en/upgrade/from-earlier/node/index.md)
