Skip to content

Commit 10bdfaa

Browse files
committed
add backup database manually
1 parent a05d34b commit 10bdfaa

File tree

7 files changed

+87
-7
lines changed

7 files changed

+87
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ APP_CMD=start
8585

8686
## Troubleshooting
8787

88-
- On first startup, you may encounter an error indicating that `xc2f_pgdata` was not found. You can resolve this by commenting out the `volumes.pgdata.external` and `volumes.pgdata.name` lines in `docker-compose.yml`. If you keep these options, you can customize the pgdata name. See [Change Postgres volume name](#change-postgres-volume-name) for details.
88+
- On first startup, you may encounter an error indicating that `external volume "xc2f_pgdata" not found`. You can resolve this by commenting out the `volumes.pgdata.external` and `volumes.pgdata.name` lines in `docker-compose.yml`. Or you can create the xc2f_pgdata volume by running `docker volume create xc2f_pgdata`.
8989
- On first startup or after new table structures are added, enter the payload container to run `pnpm payload migrate:create` and `pnpm payload migrate`.
9090

9191
## Commands

src/app/(payload)/admin/importMap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { RowLabel as RowLabel_1f6ff6ff633e3695d348f4f3c58f1466 } from '@/Footer/
2828
import { default as default_1a7510af427896d367a49dbf838d2de6 } from '@/components/BeforeDashboard'
2929
import { default as default_8a7ab0eb7ab5c511aba12e68480bfe5e } from '@/components/BeforeLogin'
3030
import { S3ClientUploadHandler as S3ClientUploadHandler_f97aa6c64367fa259c5bc0567239ef24 } from '@payloadcms/storage-s3/client'
31+
import { default as default_739e6b432caad92cc3d7bab1ebeedbb4 } from '../../../views/System'
3132
import { CollectionCards as CollectionCards_ab83ff7e88da8d3530831f296ec4756a } from '@payloadcms/ui/rsc'
3233

3334
export const importMap = {
@@ -61,5 +62,6 @@ export const importMap = {
6162
"@/components/BeforeDashboard#default": default_1a7510af427896d367a49dbf838d2de6,
6263
"@/components/BeforeLogin#default": default_8a7ab0eb7ab5c511aba12e68480bfe5e,
6364
"@payloadcms/storage-s3/client#S3ClientUploadHandler": S3ClientUploadHandler_f97aa6c64367fa259c5bc0567239ef24,
65+
"./views/System#default": default_739e6b432caad92cc3d7bab1ebeedbb4,
6466
"@payloadcms/ui/rsc#CollectionCards": CollectionCards_ab83ff7e88da8d3530831f296ec4756a
6567
}

src/components/BeforeDashboard/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const BeforeDashboard: React.FC = () => {
1212
<h4>Welcome to your dashboard!</h4>
1313
</Banner>
1414
<div className="row">
15+
<a href="/admin/system">Go to system</a>
16+
<span>|</span>
1517
<a href="/" target="_blank">
16-
visit your website
18+
Visit your website
1719
</a>
1820
<span>|</span>
1921
<a href="https://payloadcms.com/docs/getting-started/what-is-payload" target="_blank">
20-
visit payload docs
22+
Visit payload docs
2123
</a>
2224
</div>
2325
</div>

src/endpoints/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Endpoint } from 'payload'
2+
3+
import { backupDatabaseTask } from '../tasks/backupDatabase'
4+
5+
export const endpoints: Endpoint[] = [
6+
{
7+
path: '/backup/database',
8+
method: 'get',
9+
handler: async () => {
10+
const result = await backupDatabaseTask()
11+
return Response.json(result)
12+
},
13+
},
14+
]

src/payload.config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { backupDatabaseTask } from './tasks/backupDatabase'
2727
import { en } from '@payloadcms/translations/languages/en'
2828
import { zh } from '@payloadcms/translations/languages/zh'
2929

30+
import { endpoints } from './endpoints'
3031
import { migrations } from './migrations'
3132

3233
const filename = fileURLToPath(import.meta.url)
@@ -35,12 +36,14 @@ const dirname = path.dirname(filename)
3536
export default buildConfig({
3637
admin: {
3738
components: {
38-
// The `BeforeLogin` component renders a message that you see while logging into your admin panel.
39-
// Feel free to delete this at any time. Simply remove the line below.
4039
beforeLogin: ['@/components/BeforeLogin'],
41-
// The `BeforeDashboard` component renders the 'welcome' block that you see after logging into your admin panel.
42-
// Feel free to delete this at any time. Simply remove the line below.
4340
beforeDashboard: ['@/components/BeforeDashboard'],
41+
views: {
42+
system: {
43+
Component: './views/System',
44+
path: '/system',
45+
},
46+
},
4447
},
4548
importMap: {
4649
baseDir: path.resolve(dirname),
@@ -169,4 +172,5 @@ export default buildConfig({
169172
],
170173
defaultLocale: 'zh',
171174
},
175+
endpoints,
172176
})

src/views/System/Backup.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client'
2+
import React from 'react'
3+
import { Gutter, Button, toast } from '@payloadcms/ui'
4+
5+
const Backup = () => {
6+
const handleBackup = async () => {
7+
const loading = toast.loading('备份中...')
8+
const res = await fetch('/api/backup/database')
9+
toast.dismiss(loading)
10+
if (res.ok) {
11+
toast.success('备份成功!')
12+
}
13+
}
14+
15+
return (
16+
<Gutter>
17+
<h1>System</h1>
18+
<Button onClick={handleBackup}>Backup Database</Button>
19+
</Gutter>
20+
)
21+
}
22+
23+
Backup.propTypes = {}
24+
25+
export default Backup

src/views/System/index.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { AdminViewServerProps } from 'payload'
2+
import { DefaultTemplate } from '@payloadcms/next/templates'
3+
import { Gutter } from '@payloadcms/ui'
4+
import Backup from './Backup'
5+
6+
const System = async ({ initPageResult, params, searchParams }: AdminViewServerProps) => {
7+
const {
8+
req: { user },
9+
} = initPageResult
10+
11+
if (!user) {
12+
return <p>You must be logged in to view this page.</p>
13+
}
14+
15+
return (
16+
<DefaultTemplate
17+
i18n={initPageResult.req.i18n}
18+
locale={initPageResult.locale}
19+
params={params}
20+
payload={initPageResult.req.payload}
21+
permissions={initPageResult.permissions}
22+
searchParams={searchParams}
23+
user={initPageResult.req.user || undefined}
24+
visibleEntities={initPageResult.visibleEntities}
25+
>
26+
<Gutter>
27+
<Backup />
28+
</Gutter>
29+
</DefaultTemplate>
30+
)
31+
}
32+
33+
export default System

0 commit comments

Comments
 (0)