3.14 Restore from backup

If you have a recent backup, this path is faster than installing from scratch.

  1. Provision a fresh Ubuntu 24.04 host.
  2. Install just enough packages to extract and restore:
    sudo apt update
    sudo apt install -y openjdk-21-jdk-headless \
        postgresql-16 postgresql-16-pgvector \
        s3fs gzip tar
    
  3. Mount the backup bucket. You will need the AWS credentials by other means (password manager, etc.) since /etc/passwd-s3fs is itself inside the backup:
    sudo mkdir -p /mnt/backups
    echo "<bucket>:<KEY>:<SECRET>" | sudo tee /etc/passwd-s3fs
    sudo chmod 600 /etc/passwd-s3fs
    sudo s3fs <bucket> /mnt/backups -o passwd_file=/etc/passwd-s3fs \
        -o allow_other -o use_path_request_style
    
  4. (optional) Reinstall previously-managed apt packages:
    sudo tar -xzf /mnt/backups/files-YYYY-MM-DD.tar.gz -C /tmp \
        var/lib/ownsona-backup/apt-mark-manual.txt
    xargs -a /tmp/var/lib/ownsona-backup/apt-mark-manual.txt sudo apt install -y
    
  5. Extract the file backup over the root filesystem:
    sudo tar -xzpf /mnt/backups/files-YYYY-MM-DD.tar.gz -C /
    

    This restores /home, /root, /etc, /usr/local, /opt, the per-user crontabs in /var/spool/cron, the live systemd units, and the metadata bundle.

  6. Restore PostgreSQL (drops and recreates everything):
    zcat /mnt/backups/database-YYYY-MM-DD.gz | sudo -u postgres psql -X postgres
    
  7. Reload systemd and bring services up:
    sudo systemctl daemon-reload
    sudo systemctl enable --now ownsona.service
    sudo systemctl enable --now ownsona-backup.timer
    
  8. Smoke test (see Smoke test).

The OS-level ownsona Linux user is restored along with /home/ownsona, so no manual adduser is needed. PostgreSQL roles (including the ownsona role and its password hash) are restored by pg_dumpall.