Adds an admin view at a configurable route plus a sidebar link for downloading and restoring selected collections as a single JSON file. Backups use EJSON so ObjectIds and Dates round-trip exactly, and draft version collections are included automatically. Restore writes through raw Mongoose without running hooks or validation. Requires Payload 3 with the MongoDB adapter.
Admin UI for exporting and restoring selected Payload CMS collections as portable JSON. Includes a /admin/backup view and a sidebar shortcut.
Installation
npm i @yairl/payload-db-backup-restore3
Stars
0
Forks
0
Open Issues
4 months ago
Last Updated
105
Weekly Downloads
v0.1.2
npm Version
62.4 KB
Unpacked Size
1
Dependencies
30 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 3 |
| Dec 4, 2026 | 3 |
| Dec 3, 2026 | 3 |
| Dec 2, 2026 | 3 |
| Dec 1, 2026 | 3 |
| Nov 30, 2026 | 3 |
| Nov 29, 2026 | 3 |
| Nov 28, 2026 | 3 |
| Nov 27, 2026 | 3 |
| Nov 26, 2026 | 3 |
| Nov 25, 2026 | 3 |
| Nov 24, 2026 | 3 |
| Nov 23, 2026 | 3 |
| Nov 22, 2026 | 3 |
| Nov 21, 2026 | 3 |
| Nov 20, 2026 | 3 |
| Nov 19, 2026 | 3 |
| Nov 18, 2026 | 3 |
| Nov 17, 2026 | 3 |
| Nov 16, 2026 | 3 |
| Nov 15, 2026 | 3 |
| Nov 14, 2026 | 3 |
| Nov 13, 2026 | 3 |
| Nov 12, 2026 | 3 |
| Nov 11, 2026 | 3 |
| Nov 10, 2026 | 3 |
| Nov 9, 2026 | 3 |
| Nov 8, 2026 | 3 |
| Nov 7, 2026 | 3 |
| Nov 6, 2026 | 3 |
| Nov 5, 2026 | 3 |
| Nov 4, 2026 | 3 |
| Nov 3, 2026 | 3 |
| Nov 2, 2026 | 3 |
| Nov 1, 2026 | 3 |
| Oct 31, 2026 | 3 |
| Oct 30, 2026 | 3 |
| Oct 29, 2026 | 3 |
| Oct 28, 2026 | 3 |
| Oct 27, 2026 | 3 |
| Oct 26, 2026 | 3 |
| Oct 25, 2026 | 3 |
| Oct 24, 2026 | 3 |
| Oct 23, 2026 | 3 |
| Oct 22, 2026 | 3 |
| Oct 21, 2026 | 3 |
| Oct 20, 2026 | 3 |
| Oct 19, 2026 | 3 |
| Oct 18, 2026 | 3 |
| Oct 17, 2026 | 3 |
| Oct 16, 2026 | 3 |
| Oct 15, 2026 | 3 |
| Oct 14, 2026 | 3 |
| Oct 13, 2026 | 3 |
| Oct 12, 2026 | 3 |
| Oct 11, 2026 | 3 |
| Oct 10, 2026 | 3 |
| Oct 9, 2026 | 3 |
| Oct 8, 2026 | 3 |
| Oct 7, 2026 | 3 |
| Oct 6, 2026 | 3 |
| Oct 5, 2026 | 3 |
| Oct 4, 2026 | 3 |
| Oct 3, 2026 | 3 |
| Oct 2, 2026 | 3 |
| Oct 1, 2026 | 3 |
| Sep 30, 2026 | 3 |
| Sep 29, 2026 | 3 |
| Sep 28, 2026 | 3 |
| Sep 27, 2026 | 3 |
| Sep 26, 2026 | 3 |
| Sep 25, 2026 | 3 |
| Sep 24, 2026 | 3 |
| Sep 23, 2026 | 3 |
| Sep 22, 2026 | 3 |
| Sep 21, 2026 | 3 |
| Sep 20, 2026 | 3 |
| Sep 19, 2026 | 3 |
| Sep 18, 2026 | 3 |
| Sep 17, 2026 | 3 |
| Sep 16, 2026 | 3 |
| Sep 15, 2026 | 3 |
| Sep 14, 2026 | 3 |
| Sep 13, 2026 | 3 |
| Sep 12, 2026 | 3 |
| Sep 11, 2026 | 3 |
| Sep 10, 2026 | 3 |
| Sep 9, 2026 | 3 |
| Sep 8, 2026 | 3 |
| Sep 7, 2026 | 3 |
| Sep 6, 2026 | 3 |
97+86 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 97 |
| Dec 4, 2026 | 103 |
| Dec 3, 2026 | 121 |
| Dec 2, 2026 | 114 |
| Dec 1, 2026 | 108 |
| Nov 30, 2026 | 90 |
| Nov 29, 2026 | 93 |
| Nov 28, 2026 | 88 |
| Nov 27, 2026 | 84 |
| Nov 26, 2026 | 82 |
| Nov 25, 2026 | 95 |
| Nov 24, 2026 | 113 |
| Nov 23, 2026 | 120 |
| Nov 22, 2026 | 124 |
| Nov 21, 2026 | 140 |
| Nov 20, 2026 | 135 |
| Nov 19, 2026 | 128 |
| Nov 18, 2026 | 117 |
| Nov 17, 2026 | 93 |
| Nov 16, 2026 | 91 |
| Nov 15, 2026 | 86 |
| Nov 14, 2026 | 75 |
| Nov 13, 2026 | 75 |
| Nov 12, 2026 | 84 |
| Nov 11, 2026 | 76 |
| Nov 10, 2026 | 77 |
| Nov 9, 2026 | 60 |
| Nov 8, 2026 | 50 |
| Nov 7, 2026 | 49 |
| Nov 6, 2026 | 51 |
| Nov 5, 2026 | 32 |
| Nov 4, 2026 | 39 |
| Nov 3, 2026 | 79 |
| Nov 2, 2026 | 91 |
| Nov 1, 2026 | 98 |
| Oct 31, 2026 | 96 |
| Oct 30, 2026 | 97 |
| Oct 29, 2026 | 95 |
| Oct 28, 2026 | 79 |
| Oct 27, 2026 | 51 |
| Oct 26, 2026 | 41 |
| Oct 25, 2026 | 36 |
| Oct 24, 2026 | 44 |
| Oct 23, 2026 | 35 |
| Oct 22, 2026 | 43 |
| Oct 21, 2026 | 54 |
| Oct 20, 2026 | 48 |
| Oct 19, 2026 | 55 |
| Oct 18, 2026 | 60 |
| Oct 17, 2026 | 60 |
| Oct 16, 2026 | 82 |
| Oct 15, 2026 | 79 |
| Oct 14, 2026 | 83 |
| Oct 13, 2026 | 76 |
| Oct 12, 2026 | 85 |
| Oct 11, 2026 | 82 |
| Oct 10, 2026 | 92 |
| Oct 9, 2026 | 75 |
| Oct 8, 2026 | 81 |
| Oct 7, 2026 | 99 |
| Oct 6, 2026 | 110 |
| Oct 5, 2026 | 95 |
| Oct 4, 2026 | 102 |
| Oct 3, 2026 | 93 |
| Oct 2, 2026 | 89 |
| Oct 1, 2026 | 92 |
| Sep 30, 2026 | 71 |
| Sep 29, 2026 | 76 |
| Sep 28, 2026 | 73 |
| Sep 27, 2026 | 65 |
| Sep 26, 2026 | 57 |
| Sep 25, 2026 | 58 |
| Sep 24, 2026 | 53 |
| Sep 23, 2026 | 56 |
| Sep 22, 2026 | 38 |
| Sep 21, 2026 | 41 |
| Sep 20, 2026 | 37 |
| Sep 19, 2026 | 77 |
| Sep 18, 2026 | 78 |
| Sep 17, 2026 | 72 |
| Sep 16, 2026 | 61 |
| Sep 15, 2026 | 60 |
| Sep 14, 2026 | 56 |
| Sep 13, 2026 | 55 |
| Sep 12, 2026 | 13 |
| Sep 11, 2026 | 12 |
| Sep 10, 2026 | 9 |
| Sep 9, 2026 | 5 |
| Sep 8, 2026 | 5 |
| Sep 7, 2026 | 6 |
| Sep 6, 2026 | 11 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1289282287-root)<a href="https://payloaddirectory.dev/plugins/1289282287-root"><img src="https://payloaddirectory.dev/badge/1289282287-root.svg" alt="Payload Directory"></a>README
Admin UI for exporting and restoring selected Payload CMS collections as a portable JSON file. Ships an /admin/backup view and a sidebar shortcut. Round-trips ObjectIds and Dates faithfully via EJSON.
Works with any Payload 3 project on MongoDB.
Screenshotpnpm add @yairl/payload-db-backup-restore
# or
npm install @yairl/payload-db-backup-restore
# or
yarn add @yairl/payload-db-backup-restore
Add the plugin to your Payload config:
// payload.config.ts
import { buildConfig } from 'payload';
import { backupPlugin } from '@yairl/payload-db-backup-restore';
export default buildConfig({
plugins: [
backupPlugin(),
],
// ...rest of your config
});
Regenerate Payload's importMap so it picks up the plugin's components, then start dev:
pnpm payload generate:importmap
pnpm dev
Visit http://localhost:3000/admin/backup. You'll see every collection listed with checkboxes and two actions: Download backup (writes a .json file) and Restore from file (reads one back). The sidebar gets a "Backup & restore" link at the bottom.
If the view loads but no collections appear and you see "Failed to load collections: HTTP 401", the plugin's default access check isn't matching your Users collection shape.
Why: the default is req.user.roles.includes('admin') — but Payload's out-of-the-box template doesn't add a roles field to users, so every existing user has roles === undefined and the check returns false.
Two ways to fix — pick one:
A. Loosen the check for testing — any logged-in user can back up/restore:
backupPlugin({
access: (req) => !!req.user,
})
Reasonable when the whole /admin panel is already gated to trusted staff.
B. Add a roles field to your Users collection — production-grade, matches the default check:
// src/collections/Users.ts
const Users: CollectionConfig = {
slug: 'users',
auth: true,
fields: [
// your existing fields...
{
name: 'roles',
type: 'select',
hasMany: true,
defaultValue: ['admin'],
options: [
{ label: 'Admin', value: 'admin' },
{ label: 'User', value: 'user' },
],
},
],
};
Existing users need the role set once — via the admin UI or, if you have many, once in mongo:
db.users.updateMany({}, { $set: { roles: ['admin'] } })
backupPlugin({
enabled: true, // default
route: '/backup', // default — mounted at /admin/backup
showInSidebar: true, // default
access: (req) => // default: role check
Array.isArray(req.user?.roles) && req.user.roles.includes('admin'),
packageName: '@yairl/payload-db-backup-restore', // only override if you've forked/renamed
});
access: (req: PayloadRequest) => booleanCalled on every backup/restore request AND on the view render. Return true to permit, false to reject (401). The default checks req.user.roles for the string 'admin'. Common overrides:
// Any authenticated user
access: (req) => !!req.user,
// A specific collection field
access: (req) => req.user?.collection === 'admins',
// Multiple roles allowed
access: (req) =>
Array.isArray(req.user?.roles) &&
['admin', 'devops'].some(r => req.user.roles.includes(r)),
route: stringThe URL segment under /admin where the view is mounted. Change if you already have a /admin/backup route in your project.
showInSidebar: booleanSet to false to skip the "Backup & restore" sidebar entry. The /admin/backup route still exists — you'd link to it yourself.
A single JSON document with this shape:
{
"version": 1,
"exportedAt": "2026-07-04T09:12:34.567Z",
"exportedBy": "[email protected]",
"collections": ["posts", "media", "_posts_versions"],
"data": {
"posts": [ /* every doc from `posts` */ ],
"media": [ /* every doc from `media` */ ],
"_posts_versions": [ /* drafts/version rows, when versions.drafts is on */ ]
}
}
EJSON.stringify(..., { relaxed: false }) so ObjectId, Date, Decimal128, etc. round-trip byte-for-byte.versions.drafts: true, its _<slug>_versions sidecar is included automatically. Both the main and the versions collections are restored together as long as the base slug is selected.On the server, for each selected collection, restore uses raw Mongoose (db.collections[slug].insertMany(docs)) — not payload.create. That means:
beforeChange, afterChange, etc.). Good — you don't want setTitle overwriting titles or revalidatePage firing thousands of times during a bulk restore.If Drop before restore is checked (the default), the target collection is emptied with deleteMany({}) first. If unchecked, insertMany is used with ordered: false — duplicates by _id will error per-row but the rest succeed.
media collection's metadata rows (filenames, alt text, sizes) are included, but the actual blob files under your staticDir are not. Snapshot those separately (tar / rsync / S3 sync).admin. Only regular collections are handled.payload-preferences, payload-locked-documents). These aren't in payload.config.collections.The plugin mounts three endpoints. If you want to script backups from the CLI:
GET /api/db-backup/collections → { collections: [{ slug, hasVersions }, ...] }
POST /api/db-backup/export → binary JSON body, Content-Disposition attachment
POST /api/db-backup/import → multipart: file, collections, dropFirst
All three require the access check to pass. Authenticate the same way you would any Payload API call (session cookie or Authorization: JWT <token>).
^3.0.0@payloadcms/db-mongodb). Postgres/SQLite adapters don't expose the raw model in the same shape.>= 20.9pnpm install
pnpm build # tsc → dist/
pnpm dev # tsc --watch, useful when using pnpm link
To develop against a local Payload project without publishing:
cd payload-db-backup-restore && pnpm build
cd ../my-payload-project && pnpm link ../payload-db-backup-restore
Rebuild and Payload's importMap regen after any source change.
MIT
payload typeid
TypeID identifiers for Payload collections, as native IDs or an extra type_id field, with PostgreSQL integrity guards
802.6k/wk0v3
payload surrealdb
SurrealDB database adapter for Payload CMS v3 and v4 using its PostgreSQL-compatible SQL interface
77268/wk3v3 v4
payload plugin backup postgres
Scheduled and on-demand PostgreSQL backups with selective restore, stored in Vercel Blob or S3-compatible storage
72118/wk3v3
payload locale snapshot
Prevents loss of other-locale translations in localized blocks and arrays when saving with the Postgres adapter
6663/wk3v3
payload plugin backup mongodb
MongoDB backup and restore for Payload with Vercel Blob or S3-compatible storage and an admin dashboard
5484/wk8v3
payload db check
Admin view that finds duplicates, broken references and one-sided links, with opt-in previewed repairs
399/wk0v3