Admin

Database, backups and restore

What is backed up, how to run and schedule backups and how to restore safely.

For: Administrators, IT ยท Checked against v5.17

Access: Server administrator with access to the installation folder.

SeaVesselManager keeps all its data in one PostgreSQL database, plus the uploaded files (attachments, documents, signatures, pictures). A backup copies both. The tools are scripts in the installation folder of the server, so they work even if the application itself is down.

What a backup contains

Each run creates one backup set in the backups folder:

File Content
db.sql.gz The whole database: work orders, history, counters, users, audit log.
files.tar.gz The uploaded files.
SHA256SUMS Checksums, checked again at restore time.
MANIFEST.txt When it was made, on which host, and the version.

A set is only kept if it verifies. A failed run deletes its half-written set and records FAILED in backups/last-backup.status so the failure is not silent.

Run a backup

Open a terminal in the installation folder.

.\backup.ps1

On Linux or macOS use ./backup.sh. Before applying an update that contains database changes the system makes a backup by itself (the Updates page says so).

Schedule it

.\schedule-backup.ps1

(run in an elevated window; ./schedule-backup.sh on Linux). This schedules a daily backup at 02:30. With a daily schedule you can lose up to 24 hours of data in the worst case; schedule more often if that is too much.

Set BACKUP_OFFSITE_DIR in the .env file to a second disk, a network share or a USB drive so every set is also copied and re-verified off the machine. BACKUP_RETENTION_DAYS (default 30) controls how long sets are kept; the newest seven are always kept.

Important

A backup on the same disk as the database does not protect you from a failed disk or a stolen server. Always use an off-site copy.

Test a restore without changing anything

Try the drill regularly. It checks the set and loads it into a scratch database, and changes nothing else.

.\restore.ps1 -VerifyOnly <set>

Restore for real

.\restore.ps1 <set>

The restore is built so it cannot make things worse: it verifies the set, loads it into a scratch database in one transaction, runs sanity checks (enough tables, migration history present, every completed work order has its history row) and only then switches over. The old database is kept under a name ending in _pre_restore_<time> until you drop it yourself. A set that does not load is refused and the live database is not touched.

Ship databases

For a ship that runs its own copy, the office can export a complete vessel database from Admin > Settings > Database > Vessel Provisioning and import it on the ship (see Ship and office synchronisation). That is how a ship is started, not a backup.

Updating

Updates are described in Updates and licence. Take a backup before you update a live system, even though the update does one for itself when it changes the database.