完善数据库备份恢复链路

This commit is contained in:
yml2213
2026-08-23 14:39:30 +08:00
parent 0dfc1ef0df
commit d56189fe59
10 changed files with 1535 additions and 5 deletions
@@ -70,9 +70,10 @@ export class ObjectStorage {
async putObject(input: {
key: string
content: Buffer
content: Buffer | Readable
contentType: string
metadata?: Record<string, string>
contentLength?: number
}): Promise<void> {
await this.ensureBucketReady()
await this.client.send(
@@ -81,6 +82,7 @@ export class ObjectStorage {
Key: input.key,
Body: input.content,
ContentType: input.contentType,
...(input.contentLength === undefined ? {} : { ContentLength: input.contentLength }),
...(input.metadata ? { Metadata: sanitizeObjectMetadata(input.metadata) } : {}),
}),
)
@@ -125,13 +127,17 @@ export class ObjectStorage {
return stat
}
async listObjects(): Promise<StorageObjectSummary[]> {
async listObjects(prefix?: string): Promise<StorageObjectSummary[]> {
await this.ensureBucketReady()
const objects: StorageObjectSummary[] = []
let continuationToken: string | undefined
do {
const output = await this.client.send(
new ListObjectsV2Command({ Bucket: this.bucket, ContinuationToken: continuationToken }),
new ListObjectsV2Command({
Bucket: this.bucket,
...(prefix ? { Prefix: prefix } : {}),
ContinuationToken: continuationToken,
}),
)
for (const item of output.Contents || []) {
if (!item.Key) {
@@ -166,7 +172,9 @@ export class ObjectStorage {
throw error
}
if (!this.pathStyle) {
throw new Error(`OSS bucket ${this.bucket} 不存在,请先在阿里云控制台创建`)
throw new Error(`OSS bucket ${this.bucket} 不存在,请先在阿里云控制台创建`, {
cause: error,
})
}
await this.client.send(new CreateBucketCommand({ Bucket: this.bucket }))
}
@@ -197,6 +205,9 @@ export class StorageRouter {
}
async putObject(input: Parameters<ObjectStorage['putObject']>[0]): Promise<void> {
if (!Buffer.isBuffer(input.content) && this.mode === 'dual') {
throw new Error('dual 存储模式不支持同一可读流双写,请传入 Buffer')
}
if (this.mode === 'minio') {
await this.legacy.putObject(input)
return