7 Backup and Restore
liquibyte edited this page 2026-11-27 14:59:02 -06:00

Backup and Restore

A Folio site is one folder on the server, /srv/folio. A backup is that folder, or the part of it that matters, packed into one file by the program folio-backup. This page says what has to be in a backup and why, how to make one, how to keep it, and how to bring a site back from it, on the same server or on another.

The steps happen on three kinds of computer. Each step says which:

Name on this page What it is
the server the computer the site runs on. You log in there with your own user account and use sudo
your own computer the one you use the site from, with the owner's SSH key and GPG key, and the folio command (package folio-client)
a spare computer any computer with Devuan that is not the server: for trying a restore

Commands that act on the site run as the user folio, who owns /srv/folio. sudo -u folio COMMAND runs a command as that user.

The short version

  1. Two parts of the site exist nowhere else and can never be made again: /srv/folio/private, and the signer's folder /var/lib/folio-sign, which holds the site's signing keys. Lose the signing keys and the owner must make new ones with the master (an emergency: every computer that installs from the site runs its setup.sh again).
  2. On the server, as root, sudo /usr/lib/folio/folio-backup save FILE --encrypt-to KEY writes the site, the signer's keys with it, into one file encrypted to a PGP key you name. Without --encrypt-to, the file holds every key the site keeps, unencrypted.
  3. Copy that file off the server, regularly, and keep it as safe as the server itself.
  4. The site's master key is never in a backup: it is on your own computer (folio-site-key). Keep that computer's GnuPG folder backed up on its own, offline.
  5. To bring the site back, on the same server or a new one, run the guided setup with FOLIO_RESTORE=FILE.
  6. Try a restore on a spare computer now and then.

What to back up, and why

The site's folder

Folder in /srv/folio What it holds Can the site make it again? In a backup
record/ every fact: accounts and their keys, packages, votes, comments, requests, mirrors, build nodes, settings. A git repository; every change is a signed commit no yes
private/ the site's public key, where a change of key stands, and other private things (next table) no yes
builds/ every build: its facts, its full log, the files it made only by building everything again yes, except with --small
apt/ the signed archive people install from only by building everything again yes, except with --small
source/ for each package, the packaging files shown on its page yes, at the next import yes
guides/ the guides shown under Help yes, from the installed package yes
site/static/ the stylesheets and the site's own pictures (logo, emblem, favicon) the pictures: no yes
cache/needs/ what each built package needs to run, shown on its page at the next build yes
cache/found/ projects found on a watched forge, and which were declined the declines: no yes
site/ (the rest) the pages, and a download of each package's source the pages: yes, at once. The source downloads: at each project's next commit no
cache/fetched/ the site's copies of the projects it imports yes, from the forges no
cache/published.git the site's copy of what it sends to the forge yes, from the forge no

The private folder

This is the part to protect. Only the user folio can read it.

Path in /srv/folio/private What it is If it is lost
gnupg/ the site's public key (on a site of the older kind, its signing keys too). A backup never holds the master's secret part, nor its revocation certificate the public key is also in the record (verify/site-key.asc) and on the owner's computer
key-state which signing key signs, and how far a change of signing key has come (see The site's key) the site takes its newest signing key that can sign, and forgets a change that was going on: finish it by hand, with folio-key show to guide you
keyring/ the site's keyring package as it was made last nothing: it is made again at the next publishing, with a higher version
reprepro/ the archive's index: which package files apt/ holds the archive cannot be added to; every package must be built again
mail/ the mail addresses of people who asked for notifications they must give them again
forge/key, forge/key.pub, forge/registry-token only on a site of the older kind: the key the site writes to the forge with, and the forge's token (on any other site they are the signer's, below) the site makes a new key, which must be added on the forge again; make a new token on the forge and give it again
forge/known_hosts the forge server's SSH host key, as an administrator confirmed it (Forge Setup, B1) nothing: the record names the confirmed fingerprint (publish-host-key), and the site fetches the key again and keeps it only if it has that fingerprint. A site whose forge key was never confirmed must confirm it
forge/record-sent, forge/site-sent what it sent last nothing: they are made again
sshd/authorized_keys who may come in. Written from the record nothing: it is written again
refused/ projects that were not imported, and why (what imports shows) the list starts empty
requests/ every signed request the site took (NONCE and NONCE.asc), also for the changes that are not in the record, such as mail set the proof of who asked for those changes is gone; the requests kept in the record's own history stay
nonces/ the nonces of the last 20 minutes' requests, so that none counts twice nothing: a request older than five minutes is refused anyway
activity.log, activity.log.1 every command that reached the site (.1: the lines before, once the log passed 5 MB) the history of what happened is gone; the site works
rate/, outbox/ hourly counts, mail waiting to go nothing that matters

The signer's folder

The site's signing keys, the key it writes to the forge with and the forge's token are held by the site's signer, the user folio-sign, in /var/lib/folio-sign. Only that user, and root, can read them. So folio-backup save takes them only when it is run as root: they are then in the backup as signer/, and the guided setup puts them back for the signer when it restores (FOLIO_RESTORE). Run as folio, the backup holds no key at all, and says so.

Path in /var/lib/folio-sign What it is If it is lost
gnupg/ the site's signing keys (one for the archive, one for the record) nothing can be signed until the owner gives the site new ones: on the owner's computer folio-site-key emergency, then folio-key import BUNDLE; computers that install from the site then run its setup.sh again
forge/ the forge key, the forge's token, the host key as last used a new key is made (add it on the forge again); give the token again
site, secrets which site's key it holds, and which signing keys made again by the next bundle it takes
sign.log every signature it made the history is gone; not in a backup

The master key

The site's key has three parts: a master, which only vouches for signing keys, and two signing keys under it, which do the daily signing. The master is made on the owner's own computer and stays there (see the Owner and Administrator Guide). It is never in a backup of the site, and neither is its revocation certificate. Back up that computer's GnuPG folder (with its openpgp-revocs.d) on its own, to two places that are not on a network.

  • On a site of the older kind whose master is still on the server, a backup leaves the master out and says WARNING: the site's master key is on this server, and is NOT in the backup. Move it to your computer now (the same guide, "Moving the master off a server of an older site").
  • A backup made by an older Folio, before the master moved, still holds the master. Destroy every such backup once the master is on your computer.

A change of signing key, half-way

A backup carries where a change of signing key stands (key-state), and the keyring package. A site restored from it goes on from there: folio-key show says what is next. If the new signing key was due to take over while the site was down, it takes over at the first publishing after the restore.

What the forge holds, and what it does not

If the site writes itself to a forge (Forge Setup, part B), the forge has two repositories, named after the site's short name (SHORT, for example dur):

On the forge Holds
SHORT-record a full copy of record/, with its signed history
SHORT-site the pages, apt/ with the packages, and a README listing them

That is a running copy of most of the site, but it is not a backup. The private folder and the signer's folder are never sent anywhere: not the signing keys, not the mail addresses, not the forge token. A site that has lost its server and has only the forge copy has lost its signing keys, and starts again with a new key. See If there is no backup.

What a backup does not hold

A backup holds the site. It does not hold the server's own settings, which the guided setup (folio-install) writes:

Not in a backup Made again by
the user folio the guided setup
/etc/folio/folio.conf (where the site's folder is) the guided setup
/etc/ssh/sshd_config.d/folio.conf the guided setup
/etc/nginx/sites-available/folio, and the https certificate the guided setup (the certificate: certbot, or your own files)
/etc/cron.d/folio (the timed jobs) the guided setup
/etc/msmtprc or other mail settings you (Owner Install Guide, Part 4)
the installed packages (folio-server and what it works with) you, with apt install
the server's SSH host keys (/etc/ssh/ssh_host_*) a new server has new ones; see Moving a site
the pages the restore writes them again
the build nodes they are other computers; they only need the site's address

The program: folio-backup

Command (on the server, as folio, or as root to take the signer's keys along) What it does
folio-backup save FILE writes everything in the "In a backup" column above into FILE, a tar archive (as root, the signer's keys too). The file must not exist yet. It is made exclusively: a new temporary file beside FILE, linked to FILE only if nobody made one meanwhile, never written over. A folder anyone may write to is refused unless it is sticky (as /tmp is)
folio-backup save FILE --small the same without builds/, apt/ and the archive's index (private/reprepro). A few megabytes instead of everything ever built
folio-backup save FILE --encrypt-to KEY the same, encrypted with gpg to the PGP key KEY: a file with a public key, or the fingerprint of an account's key as the record holds it. The key must be able to encrypt (have an encryption subkey; a key folio-mykeys made only signs). Only whoever holds that key's secret can read the backup. Without it, a backup holds every key the site keeps, unencrypted
folio-backup restore FILE lists every member of FILE first, and refuses the whole file, unpacking nothing, if one is a link, a device, a hard link that leads out, a name with .., a leading / or a backslash, or anything outside the parts a backup holds (record, private, source, guides, site, cache, builds, apt, signer). Then it unpacks FILE into a folder of its own inside a site folder that holds no site yet, and moves it into place only once all of it is there. It drops what could make git or gpg run a program (the record's git settings, hooks and attributes, GnuPG's *.conf), writes Folio's own git settings, and names what it dropped. It merges the newest the site can know of its key (see A backup older than the last change of the key). It writes the pages and the list of SSH keys again, and after a small backup queues every package to be built again. If the record's copy of the site's public key (verify/site-key.asc) is not the key in the backup's private/gnupg/, it writes that key in, as a signed change, and says The record's verify/site-key.asc is the key this server holds now (FINGERPRINT). The restored site takes no signed request made before the restore ended

A full backup made by an earlier Folio holds an archive that still has empty lists of source packages. Nothing needs doing about it: the first publishing after the restore (folio-publish, run whenever a build is handed in, or by hand) takes them out, and the archive serves its packages as before.

The program is /usr/lib/folio/folio-backup.

While a backup is being saved, the site is held. Nobody can change anything for those seconds or minutes:

  • a command arriving then waits up to half a minute, then answers folio: the site is busy; try again in a moment;
  • a build node handing in a result waits up to a minute, then is turned away; that build goes back to the queue after fifteen minutes (an attempt without a result: the third makes a build failed);
  • the timed jobs wait up to a minute, then skip their turn.

Full or small? Use a full backup when you want the site back exactly as it was, with every package installable at once. Use a small backup for frequent copies of what cannot be made again. After restoring a small backup, the site queues every package's newest version to be built, and nothing can be installed from it until the build nodes have worked through that queue.

Making a backup

  1. On the server, save the site:

    sudo /usr/lib/folio/folio-backup save /root/backup-2026-01-31.tar.gpg --encrypt-to /root/backup-key.asc
    

    Run as root, it takes the signer's keys along. /root/backup-key.asc is the public half of a PGP key that can encrypt, whose secret half is kept away from the server (on your computer: gpg --armor --export FINGERPRINT > backup-key.asc, then copy it over). The name is yours to choose; a date in it helps. The file must not exist yet, and only its maker can read it.

    You should see:

    Saved: /root/backup-2026-01-31.tar.gpg (48M)
    It is encrypted to the key FINGERPRINT: only whoever holds that key's secret can
    read it (gpg --decrypt /root/backup-2026-01-31.tar.gpg > backup.tar, before restoring it).
    

    For the small kind, add --small at the end. Without --encrypt-to it says It is NOT encrypted, and holds every key the site keeps. Run as folio (sudo -u folio ...), it says that the signing keys are with the signer and not in the backup.

  2. On the server, hand the file to your own user, so you can copy it:

    sudo mv /root/backup-2026-01-31.tar.gpg ~/
    sudo chown "$USER" ~/backup-2026-01-31.tar.gpg
    
  3. On your own computer, copy it off the server. scp copies a file over SSH; you is your user on the server:

    scp you@dur.example.org:backup-2026-01-31.tar.gpg .
    
  4. On the server, delete it:

    rm ~/backup-2026-01-31.tar.gpg
    
  5. Store the copy (next section).

Every night

The server can make the file by itself. On the server, write the file /etc/cron.d/folio-backup (for example with sudo nano /etc/cron.d/folio-backup) with this one line:

30 3 * * *  root  /usr/lib/folio/folio-backup save /root/backups/backup-$(date +\%F).tar.gpg --small --encrypt-to /root/backup-key.asc

(Make the folder first: sudo mkdir -m 700 /root/backups.)

Part Means
30 3 * * * at 03:30, every day
root as root, so that the signer's keys are in it
--encrypt-to /root/backup-key.asc encrypted to that public key (see above)
$(date +\%F) the day's date in the name, for example 2026-01-31. The \ is needed in a cron file

This only makes the file in /root/backups. Getting it off the server and deleting old ones is still yours to arrange, for example from another computer that fetches the newest file each morning with scp and then deletes it on the server. A backup that stays on the server is lost with the server.

Checking a backup with folio-audit

Before you rely on a backup, or after a break-in, check it on your own computer with folio-audit (package folio-client). It trusts nothing in the backup but what public keys can check: every change signed by the site's key, every change a person made carrying their own signed request for exactly that change, every change the site made by itself naming what authorised it, and, with --builds, every build's signed claim and result from a node whose key the record held then. See Auditing a Site.

  1. On your computer, unpack the backup into an empty folder (a backup made as root holds the signing keys: do this on a computer you trust, and delete the folder afterwards). Use a computer that does not hold the site's master (the GnuPG folder folio-site-key keeps it in), and a folio-audit of this Folio or later: it runs no setting or hook of the record it checks. A backup made by an older Folio carries the record's own git settings and hooks (record/.git/config, record/.git/hooks); one made after a break-in as folio can carry a program there. Backups made now leave them out. An encrypted backup is decrypted first, on the computer that holds its key: gpg --decrypt backup-2026-01-31.tar.gpg > backup-2026-01-31.tar.

    mkdir audit
    tar -C audit -xf backup-2026-01-31.tar
    
  2. Take the site's public key from somewhere other than the backup: its pages publish it.

    curl --proto '=https' -fsSLO https://dur.example.org/apt/archive-keyring.asc
    
  3. Check it:

    folio-audit --key archive-keyring.asc --builds audit/builds audit/record
    

    You should see Everything holds. at the end, and the exit status is 0. A small backup has no builds/: leave --builds audit/builds out.

  4. Delete the folder: rm -rf audit.

Compare a backup with the forge's copy the same way: run folio-audit on a clone of SHORT-record too. Two copies that both hold, and whose newest changes are the same, were not rewritten in between.

Read the lines that start with WARNING: near the top. the record's own copy of the site's key (verify/site-key.asc) is X, not the key you gave (Y) means the record names another key than the one you fetched from the site's pages: a site restored or moved without its key, whose owner did not run folio-key record yet, or a copy that is not the site's. the site's key in the record changed from X to Y at change CODE means the record was brought onto a server with a new key at that change (a restore from the forge alone); the changes before it are checked against the old key, the ones after against the new. See Auditing a Site.

Storing backups

  • Keep them on a computer or medium that is not the server, and better in two places.
  • Treat each file as the site itself. A backup made as root holds the signing keys: whoever has it can sign packages as your site. It also holds people's mail addresses, in private/mail and in the signed mail set requests kept in private/requests.
  • Make it with --encrypt-to KEY, as above. A backup made without it is encrypted before it leaves your own hands, for example with gpg --symmetric backup-2026-01-31.tar, which asks for a passphrase and writes backup-2026-01-31.tar.gpg.
  • After erasing something from the record, make a new backup and destroy the older ones: they still hold what was erased.

Bringing a site back on a new server

An encrypted backup is decrypted first, where its key is (gpg --decrypt FILE.tar.gpg > backup.tar), and the decrypted file copied to the server; folio-backup restore says FILE is encrypted (--encrypt-to): decrypt it first otherwise. The guided setup puts the signer's keys (signer/ in a backup made as root) back for the user folio-sign, and says The signer's keys from the backup are back with folio-sign. A backup of a site of the older kind, whose signing keys were in private/gnupg, has them handed to the signer then (The backup is of an older site, ...). A backup made as folio holds no signing keys: the setup says so, and the owner gives the restored site new ones (folio-site-key emergency on the owner's computer, then folio-key import BUNDLE).

Root splits the backup first, in a folder of its own: it lists every member, refuses the whole backup if one is not a plain file or folder of the site (FILE was not restored, and nothing of it was unpacked: ...), hands the signer only what Folio writes there (its keyring and the secret parts of its keys, the forge's key, host key and token, site and secrets), and gives the user folio the rest without the signer's part. Anything else in the signer's part is left out, and named: Left out of the signer's part (Folio does not write it there): signer/gnupg/gpg.conf. The record's git settings and hooks, and GnuPG's *.conf, are dropped too, and named after Left out, because they could make git or gpg run a program (Folio wrote its own):.

A backup older than the last change of the key

A backup holds the site's key as it was when it was made. If the key changed since (an emergency, or old signing keys revoked), the restore takes the newer one from where it is known: the forge's record (its verify/site-key.asc, which the signer fetches) and the owner's own copy, given as FOLIO_SITE_KEY_PUBLIC=FILE (on your computer: gpg --armor --export MASTER > site-key.asc, or any bundle folio-site-key made). They are merged in, so a revocation is never lost. If a signing key the backup signs with is revoked there, the restore says

WARNING: the site's key as the forge's record knows it is newer than the one here: the signing keys ..., which signed here, are revoked there. The site signs nothing with them any more, and takes no changes, until the owner gives it new ones: ...

and the site signs nothing with them. Make new ones on your computer (folio-site-key emergency) and bring them with folio-key import BUNDLE (as root). If the forge could not be read, the restore says so; give your copy of the key afterwards with sudo -u folio /usr/lib/folio/folio-key merge site-key.asc. Every folio-key import merges the forge's copy too.

An older backup also holds an older record than the forge. The restored site never sends it over the forge's: see The forge's record is newer than the site's.

The forge's record is newer than the site's

The site sends its record to the forge only on top of what the forge holds. If the forge's record has changes the site's does not have, nothing is sent, and the activity log says the record could not be sent to the forge: the forge's record holds changes this site's record does not have: .... That happens after a restore from a backup older than the last sending, or when someone changed the forge's copy. Clone the forge's SHORT-record and check it on your computer (folio-audit --key site-key.asc CLONE). If it holds, it is the newer record: restore the site from it (as in restoring from the forge alone, step 2). If the site's record is the one to keep, delete SHORT-record on the forge, make it again, empty, and the next sending fills it. Only right after an erasure (admin erase, which the record holds, signed) does the site replace the forge's record by itself.

The steps

Use this when the server was lost or broken, and you have a backup file. The guided setup does it in one go: it makes the user and the server's settings as in a first install, and unpacks the site from the backup instead of making a new one.

  1. On the new server, install the package and what it works with (as in Part 2 of the Owner Install Guide):

    sudo apt install ./folio-server_0.1_amd64.deb nginx reprepro fcgiwrap cron
    
  2. Copy the backup file to the new server, for example to /root/backup.tar. (If you encrypted it: gpg -d backup.tar.gpg > backup.tar first.)

  3. On the new server, make sure there is no site in /srv/folio yet. If there is one, the setup stops before it does anything and says:

    folio-install: /srv/folio holds a site already, so the backup was not restored; nothing was changed. To replace that site with the one in the backup, move the old folder away first (mv /srv/folio /srv/folio.old), then run this again.
    

    If that site is the one to replace, sudo mv /srv/folio /srv/folio.old and run the setup again. (folio-backup restore does not unpack over a site either.)

  4. On the new server, run the guided setup with the backup:

    sudo FOLIO_RESTORE=/root/backup.tar FOLIO_SITE_KEY_PUBLIC=/root/site-key.asc /usr/lib/folio/folio-install
    

    FOLIO_SITE_KEY_PUBLIC is your own copy of the site's public key (on your computer: gpg --armor --export MASTER > site-key.asc, copied over). It may be left out; it matters when the key changed after the backup was made (see A backup older than the last change of the key).

    It does not ask about the site's name or owner: those come from the backup. It still asks who provides https (step 7), as in a first install. nginx is given the name from the restored site's own address setting (not a FOLIO_ADDRESS given now): a site that moves keeps its name. For a new name, see step 6 of Moving a site to another server. In step 5 you should see:

    == 5. The site
    Restored into /srv/folio: the pages and sshd's key list are written again.
    Signed requests made before now are not taken: send them again.
    

    (A request signed before the restore ended could have been taken by the old site already, so it is refused: this request was signed before the site was restored from a backup (at TIME UTC), .... Send the command again.)

    After a small backup, also:

    12 packages are queued to be built again (the backup held no builds).
    
  5. On the new server, delete the backup file:

    sudo rm /root/backup.tar
    
  6. Point the site's name at the new server (DNS), if it is a new computer. If you chose certbot in step 4 before the name led here, certbot could not get a certificate; the setup printed the command to run once the name works (certbot --nginx -d dur.example.org --redirect).

  7. On your own computer, check:

    ssh folio@dur.example.org whoami
    ssh folio@dur.example.org admin verify
    

    The first should show your account and role: owner. The second should say 0 with a signature that does NOT hold.

    If the signing key ran out while the site was down (a backup kept for a long time), admin verify says The signing key ran out on DATE, and the restored site takes no changes until you renew it on your own computer: folio-site-key renew, then on the server folio-key import BUNDLE (see Renewing the signing key). Every command that would change the record answers folio: the site's signing key ran out on DATE, so the site takes no changes until the owner renews it (on the owner's computer: folio-site-key renew, then on the server: folio-key import BUNDLE) until then.

    If whoami says note: your account has no GPG key, so it can only look (see: help), the backup is of a site made before changes were signed: set the owner's key on the server, then the others', as in A site made before changes were signed.

    If ssh refuses with Host key verification failed, the new server has a new SSH identity: see The SSH identity below.

  8. Mail, if you use it: set it up again (Part 4 of the Owner Install Guide).

What comes back by itself:

  • the pages, at once;
  • the source downloads on package pages, when each project next has a commit (until then the page offers none);
  • the copy on the forge: the next timed job carries on from what the forge has, if its newest commit is one the site signed. If it is not (someone else put a commit there), the site starts the copy afresh and replaces the forge's, and the activity log says the forge's copy of the pages ends in a commit the site did not sign, ....

Moving a site to another server

Moving is a restore onto a new server, with the old one still running. Anything that changes on the old server after the last backup is lost, so hold the old site still first.

  1. Tell people when it happens. SSH will warn them about the new server (see The SSH identity).

  2. On the old server, stop the timed jobs, so nothing is imported or built from then on:

    sudo mv /etc/cron.d/folio /root/folio.cron
    
  3. On the old server, make a full backup and copy it off, as in Making a backup.

  4. On the new server, follow Bringing a site back on a new server, steps 1 to 8.

  5. If the name stays the same (dur.example.org), point it at the new server. Build nodes and people change nothing apart from the SSH identity.

  6. If the name changes, tell the site, from your own computer. First put the new name in the ssh= and web= lines of your site's file, ~/.config/folio/sites/NAME (or change them under Site..., Edit... in the desktop program), so that the folio command reaches the new server (it fetches the new server's SSH keys from the new web address); then:

    folio admin set address https://NEW-NAME
    folio admin set ssh folio@NEW-NAME
    

    A signed request names the site by its key, not by its name, so the name can change and your requests still count.

    Then, on the new server, write apt/setup.sh again with the new address, and give nginx the new name (the guided setup took the old one from the backup):

    sudo -u folio /usr/lib/folio/folio-publish
    sudo rm /etc/nginx/sites-available/folio /etc/nginx/sites-enabled/folio
    sudo /usr/lib/folio/folio-install
    

    The guided setup leaves everything else as it is and asks about https again. People who added the old address to apt must run the new setup.sh. Each build node needs the new address in the ssh = and web = lines of its ~/.config/folio-node/site, and each person the ssh= and web= lines of their ~/.config/folio/sites/NAME (the desktop program's Site..., Edit... writes that file).

  7. Switch the old server off, or at least remove its site, once the new one works. Its signer still holds the signing keys.

The SSH identity

Every server has SSH host keys of its own, and ssh remembers them. After a restore onto a new computer, ssh sees a different identity under the same name and refuses: Host key verification failed. That is correct behaviour, and it is why people should be told beforehand.

There are two ways to deal with it:

  • Keep the identity, for a move of a server nobody broke into only. Before people connect, copy the old server's /etc/ssh/ssh_host_* files to the new server (as root, keeping the private files readable by root only), then sudo service ssh restart. Nobody notices the move. This needs the old server, or a copy of those files. Never after a break-in: whoever broke in as root has those keys, and could pass for the site; make new ones (the Owner and Administrator Guide, step 3).

  • Publish the new one. The new server's pages publish its own keys (https://dur.example.org/ssh-host-keys, written by folio-install and each time the pages are written). Give everyone the new fingerprints (ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub). None of Folio's programs takes them by itself: when the server shows a key they do not trust, the folio command and the desktop program fetch the list again, show the new fingerprints beside the old ones and ask (Trust the new keys? Type yes; without a terminal, folio --site NAME --host-keys does it), and a build node stops until its owner runs folio-node trust-host-keys and answers yes. People who use plain ssh forget the old identity and check the new one against the published keys:

    ssh-keygen -R dur.example.org
    curl -fsS --proto '=https' https://dur.example.org/ssh-host-keys | ssh-keygen -l -f -
    ssh folio@dur.example.org whoami
    

    The first forgets the old identity; the second shows the new keys' fingerprints; the third asks whether to trust the new one: answer yes only if its fingerprint is among them. If the site uses a port other than 22, the first is ssh-keygen -R '[dur.example.org]:PORT'.

Testing a restore

A backup that was never restored is a hope. Every few months, restore the newest one on a spare computer. The test copy must not act as the site: it must not import, build, send mail or write to the forge, or it would overwrite the real site's copy there.

  1. On the spare computer, install the package (as in step 1 above), and stop the timed jobs from being written, by making their file before the setup does:

    sudo touch /etc/cron.d/folio
    

    The setup then says /etc/cron.d/folio was written by an older Folio, or changed by hand, so it is kept as it is. and shows what it would have written; it writes that into /etc/cron.d/folio.folio-new, which cron does not read (a name with a dot in it). Leave both as they are.

  2. On the spare computer, restore. The setup always asks who provides https; answer front (a server in front does https). There is no such server for the test copy, so nginx answers plain http on port 80, which is enough for a copy only you look at:

    sudo FOLIO_HTTPS=front FOLIO_RESTORE=/root/backup.tar /usr/lib/folio/folio-install
    

    You should see Restored into /srv/folio: ... in step 5.

  3. On the spare computer, look at the key and the record:

    sudo -u folio /usr/lib/folio/folio-key show
    sudo -u folio git -C /srv/folio/record log -1 --format='%h %ad %s'
    

    The key's fingerprint should be the site's (the same as folio-key show prints on the real server). The newest change should be about the time of the backup.

  4. On your own computer, talk to the test copy by its address (SPARE here). Use only commands that change nothing:

    ssh folio@SPARE whoami
    ssh folio@SPARE admin verify
    ssh folio@SPARE packages
    curl -s -H 'Host: dur.example.org' http://SPARE/ | head
    

    (nginx on the spare answers to the site's own name, so the last line gives that name with -H 'Host: ...'.)

    You should see role: owner, 0 with a signature that does NOT hold, the list of packages, and the start of the home page. (ssh asks whether to trust the spare computer the first time; that is expected.)

  5. Wipe the spare computer's copy. Its signer holds the signing keys, in /var/lib/folio-sign:

    sudo rm -rf /srv/folio /var/lib/folio-sign
    sudo rm /root/backup.tar
    

    Or reinstall the spare computer.

Restoring by hand

Use this only when the server's settings are already in place (the user folio, /etc/folio/folio.conf, sshd, nginx) and /srv/folio holds no site, for example after deleting a broken one. On the server, with the backup file readable by folio (for example in /srv/folio):

sudo -u folio /usr/lib/folio/folio-backup restore /srv/folio/backup.tar

You should see the same Restored into /srv/folio: ... line. It refuses to unpack over an existing site: /srv/folio holds a site already; nothing was changed, and refuses a backup with a link or a name that leads out, whole (... nothing of it was unpacked: ...). It brings back the site's folder only: the signer's keys in a backup made as root (signer/) are put back only by the guided setup, and it says so (The backup holds the signer's keys: folio-install, as root, puts them back).

If there is no backup: restoring from the forge alone

If the server is gone, there is no backup file, but the forge has SHORT-record, the record can be brought back. The signing keys cannot. This is the worst case; a backup file avoids it.

The forge's copy is someone else's to change: whoever holds the forge, or its account, can add changes to it. So it is checked against the site's key before it is used, on your computer first and then by the server itself, and a copy with one change the site did not sign is refused.

What you get back: every account with its keys, every package's facts, votes, comments, requests, settings and build nodes. What is lost: the signing keys, mail addresses, the forge token, every build and the archive.

  1. On your own computer, check the forge's copy with the site's key, which your computer has (the master stays there):

    gpg --armor --export MASTER > old-key.asc
    git clone https://forge.example.org/you/dur-record.git dur-record
    folio-audit --key old-key.asc dur-record
    

    Go on only if it says Everything holds. (changes it calls doubtful, signed with keys you revoked as stolen, are for you to look at; see step 7).

  2. On the new server, set up a new site as in the Owner Install Guide. Give the old site's web address (nginx is set up for it); the other answers are replaced by the old site's in the next step. If you still have the master (it was on your computer, as it should be), keep it: on your computer make new signing keys under it with folio-site-key emergency (the old ones were on the lost server, and are revoked as stolen), and give that bundle to the setup (FOLIO_SITE_KEY=folio-key-emergency-....bundle). The site keeps its key and its fingerprint, and computers keep trusting it. Only if the master is lost too, make a new key with folio-site-key init, as for any new site.

  3. On the new server, replace the new record with the copy from the forge, and let the server check it and write its key into it, so that the record's copy of the site's key (verify/site-key.asc, which folio-audit checks with when it is given no other) is the key that signs from now on. Copy old-key.asc from step 1 to the server first:

    sudo -u folio sh -c 'cd /srv/folio && rm -rf record && git clone -b master https://forge.example.org/you/dur-record.git record'
    sudo -u folio /usr/lib/folio/folio-key record /srv/folio/old-key.asc
    

    The first line deletes the new, empty record and fetches the old one. The second checks every change of the record against the old key, and takes the record only if each one holds: The record holds with the site's key FINGERPRINT: signatures: good .... A record with a change the site did not sign is refused, and nothing is written: the record does NOT hold with the site's key FINGERPRINT (...). Then do not go on with that copy: delete it, and restore from a backup you trust. Under the master you kept (step 2), the server has the key already, and folio-key record alone is enough; with a new key it asks for the old one (the record names another site's key (OLD) than this server's (NEW), so it is checked against that key before it is taken).

    You should then see The record's verify/site-key.asc is the key this server holds now (FINGERPRINT). It is a signed change of the site's key, the site's key: this server's key, NEW, is the site's key from now on; the record named OLD (the site was restored or moved without its key). Until it is done, folio-key show says Due: the record's verify/site-key.asc is not the key this server holds (after a restore or a move?): folio-key record, and admin verify warns of it.

    Only then write the pages and the list of SSH keys from it:

    sudo -u folio folio-generate /srv/folio/record /srv/folio/site
    sudo -u folio /usr/lib/folio/folio-keys /srv/folio/record /srv/folio/private/sshd/authorized_keys /usr/lib/folio/folio-door
    

    The first writes the pages. The second writes the list of SSH keys, so the old site's people and build nodes can come in again. The owner is whoever owned the old site, with the keys the record has for them.

  4. On your own computer, check that you are in:

    ssh folio@dur.example.org whoami
    
  5. The forge. The new site has a new key for the forge. Show it with ssh folio@dur.example.org admin publish-key and add it on the forge (Forge Setup, B2). Give the package list's token again if you used one (C2 and C3). The record names the forge's host key as it was confirmed (publish-host-key): the site fetches the forge's key again and sends only if it is that one. If the record names none (a site that published before keys were confirmed), confirm it first (Forge Setup, B1).

  6. The packages. There are no builds and no archive. A package is imported and built again when its project next has a commit. To build one now, its maintainers or an administrator queue its newest upload: folio rebuild PACKAGE. For every package at once:

    for p in $(ssh folio@dur.example.org packages | cut -f1); do folio rebuild "$p"; done
    

    (packages only looks, so plain ssh does; rebuild is a change, so it goes through folio, signed with your GPG key. gpg-agent asks for the passphrase once and then remembers it for a while.)

    (fetch PACKAGE says PACKAGE: nothing new at URL for a project without a new commit, and reminds you of rebuild PACKAGE.)

  7. Tell everyone who installs from the site to run its setup.sh again. With a new key, the whole key is new; under the master you kept, the signing keys are, and the old ones' secret parts were lost with the server, so they cannot sign beside the new ones for a while as they do after an emergency on a running site. Until a computer runs setup.sh again, apt there says it cannot check the site's signature. Tell everyone who had mail to give their address again (folio mail set ADDRESS).

  8. admin verify with a new key counts every change made before the restore under signed by a key this server does not have, so they cannot be checked, and lists them: the server no longer has the key they were signed with. That is expected, and admin verify does not fail for it. The changes made from now on are signed with the new key. The signed requests kept in the old changes still hold: each is checked against its person's GPG key, which the record has, not against the site's key. Their site: line names the old key; new requests name the new one. Under the master you kept, the old changes are signed with keys revoked as stolen: admin verify calls them doubtful until you accept them (admin verify accept CODE..., or all, once you have read them).

The Changes page shows the old history from the next change on.

A check list

How often What
every night a small backup, copied off the server
every week, and before any upgrade a full backup, copied off the server
once, when the site becomes real the master key moved off the server, onto two media in two places; then a new backup, and the older ones destroyed
after erasing something a new backup, and the older ones destroyed
every few months a test restore on a spare computer