Backup and restore¶
The live database is local/db. The copy an upgrade makes is taken while the website is stopped, so it is always consistent. You can also copy it yourself at any time; a copy taken while the website is running is quick, but MongoDB may be in the middle of a write, so stop the website first for a copy you intend to rely on.
Make a database copy¶
nextpyp backup-db
nextpyp backup-db /path/to/db-copy
With no path, the copy is local/db.manual-<timestamp>. The website is not stopped for it; when it is running, the command says The website is running and warns that such a copy may not be restorable. The copy uses a reflink when the filesystem can make one, so it shares disk blocks with the original until something changes. nextpyp doctor -v prints the database size, and reports a problem when the free space is less than that, because an upgrade could then not snapshot it.
Warning
Keep the copy somewhere outside the install directory if you may run ./uninstall --purge later. A plain uninstall leaves local/, including local/db.previous-*, local/db.failed-*, and local/db.manual-*. ./uninstall --purge deletes those folders after you type purge.
The copy an upgrade makes¶
nextpyp upgrade copies local/db to local/db.previous-<old-version> after the website has stopped and before the new version starts. The copy is written under a temporary name and renamed when it is complete, so a directory with that name is always a whole snapshot. A snapshot left by an earlier upgrade of the same version is replaced by a fresh copy, unless that upgrade did not finish: then it holds the database from before that upgrade and is kept.
Note
Everything that can stop the snapshot is decided while the website is still running: not enough free space, a disk quota, or a database larger than PYP_BACKUP_DB_MAX_GB (50 by default). At a terminal the upgrade asks whether to copy a database over the limit; unattended, it stops before changing anything. A snapshot that cannot be taken stops the upgrade. To upgrade without one, set PYP_BACKUP_DB=false; to copy a large database, set PYP_BACKUP_DB_MAX_GB above its size or run nextpyp backup-db first.
If the new version doesn’t work out, you can put the upgrade’s copy back:
nextpyp rollback --with-db
nextpyp rollback --accept-migrated-db
--with-db puts local/db.previous-<old-version> back as local/db and moves the database written by the newer version aside to local/db.failed-<version>-<timestamp>, so nothing is thrown away.
Warning
With no snapshot, rollback refuses until you pass --accept-migrated-db. That option restores the program files and leaves the current database as it is, which may already have been migrated by the newer version.
See Upgrade for the rest of the rollback story.
What else to keep¶
A database copy is enough to return to the previous version on the same machine. If you want a copy of the whole install, you’ll need these too:
config.tomlin the shared exec directoryinstalled.tomlin the install directoryreleases/withcurrent, andcontainers/pyp-<version>-<hash>.sif(containers/pyp-code-*is unpacked again fromreleases/)the shared data directory, which holds project files
Note
The paths inside config.toml are absolute, and installed.toml is read first, so a move has to change both. If you’re copying the install to a new machine, follow Moving to another server.