Back up and restore#
This guide shows you how to back up an instance’s data and restore it. The right method depends on your storage backend.
Prerequisites#
New to this template? Start with Your first Zope instance.
Choose an approach#
A complete backup has two parts: the storage (the database or Data.fs) and
any blobs kept on the filesystem.
Whether you must back up a blob directory depends on db_blob_mode: in
shared mode the directory holds the authoritative blobs, while in cache
mode it is only a local cache and the authoritative blobs live in the
database or on the ZEO server.
Backend |
Storage backup |
Filesystem blobs to back up |
|---|---|---|
direct (filestorage) |
Cold copy of |
The blob directory (always) |
relstorage |
|
The shared blob directory if |
pgjsonb |
|
None on the filesystem; the S3 bucket if blobs are tiered |
zeo |
Back up the storage on the ZEO server |
The shared blob directory if |
any |
Portable |
— |
Important
Back up the storage and its blob directory from the same point in time.
A blob directory that is out of sync with the storage causes POSKeyError
on blob access.
Because blob files are write-once, copying the blob directory last makes it a
safe superset of what the storage references.
Filestorage: cold copy#
Stop the instance, then copy the data file and blob directory together so they stay consistent:
cp var/filestorage/Data.fs /backup/Data.fs
cp -a var/blobs /backup/blobs
Restore by copying both back into place while the instance is stopped.
PostgreSQL-backed: pg_dump#
For RelStorage and PGJsonb, back up the underlying PostgreSQL database with its native tools:
pg_dump --format=custom --file=/backup/zodb.dump plone
Restore into an empty database:
pg_restore --dbname=plone /backup/zodb.dump
With RelStorage in the recommended cache mode, blobs are stored in the
database, so pg_dump captures them.
When PGJsonb tiers blobs to S3 (db_pgjsonb_s3_bucket_name), back up that
bucket as well; the database alone does not contain the tiered blobs.
ZEO#
A ZEO client holds no authoritative data of its own, so there is nothing to
back up on the client.
Back up on the ZEO server host instead: the server runs a FileStorage, so use
the cold-copy method above against the server’s Data.fs.
If the deployment uses a shared blob directory, also back it up as described below. ZEO server administration is otherwise outside the scope of this template; consult the ZODB/ZEO documentation.
Portable backup with zodb-convert#
To create a storage-agnostic snapshot, export the database to a FileStorage
and keep the resulting Data.fs as a portable backup you can restore into any
backend.
Use zodb-convert, which works with
every backend.
See Migrate data between storage backends for the step-by-step procedure using the generated
convert-export.conf and convert-import.conf files.
With RelStorage you can instead use its bundled zodbconvert command.
Next steps#
Migrate data between storage backends – Move data between backends with
zodb-convert.Pack and garbage-collect the database – Reclaim space after restoring a large database.
How blob storage works – How blobs are stored across backends.