- 视频上传生成缩略图并提供占位封面和失败原因展示 - 支持 HLS 按需重新封装 MP4,并限制临时文件生命周期与访问权限 - 完善视频、文件 API 文档、搜索、批量删除和单次转码质量参数 - 修复备份恢复与跨后端迁移遗漏缩略图、HLS 清单和分片的问题 - 将备份任务、归档和下载权限按用户隔离 - 增加仅清理当前用户数据的高危存储清空流程和二次文字确认 - 修复 S3 中文文件名元数据及 CLI 数据库连接问题 - 补充备份恢复、用户隔离、媒体资源和转码相关测试
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
/**
|
|
* Restore PicHost from a .phost.tar.gz backup.
|
|
*
|
|
* Usage:
|
|
* node server/cli/backup-restore.mjs <archive-path> [--overwrite]
|
|
*
|
|
* Docker:
|
|
* docker exec pichost backup-restore /app/data/backups/pichost-xxx.phost.tar.gz
|
|
*/
|
|
import { access } from 'node:fs/promises'
|
|
import { resolve } from 'node:path'
|
|
import { loadServerModule } from './backup-cli-loader.mjs'
|
|
|
|
const {
|
|
ensureBackupSchema,
|
|
createBackupJob,
|
|
getBackupJob,
|
|
previewFullRestore,
|
|
runFullRestoreJob
|
|
} = loadServerModule('cli/backup-runtime.ts')
|
|
|
|
function usage() {
|
|
console.error('Usage: backup-restore <archive-path> [--overwrite]')
|
|
process.exit(1)
|
|
}
|
|
|
|
const args = process.argv.slice(2).filter(arg => arg !== '--')
|
|
if (!args.length) usage()
|
|
|
|
const overwrite = args.includes('--overwrite')
|
|
const archiveArg = args.find(arg => arg !== '--overwrite')
|
|
if (!archiveArg) usage()
|
|
|
|
const archivePath = resolve(archiveArg)
|
|
const conflictMode = overwrite ? 'overwrite' : 'skip'
|
|
|
|
async function main() {
|
|
try {
|
|
await access(archivePath)
|
|
} catch {
|
|
console.error(`[PicHost] Backup file not found: ${archivePath}`)
|
|
process.exit(1)
|
|
}
|
|
|
|
ensureBackupSchema()
|
|
const preview = await previewFullRestore(archivePath)
|
|
console.log(`[PicHost] Preview: ${preview.imageCount} media items, ${preview.newImages} new files, ${preview.conflictingImages} conflicting files`)
|
|
|
|
const job = createBackupJob({
|
|
type: 'full_restore',
|
|
message: 'CLI 恢复',
|
|
payload: { archivePath, conflictMode }
|
|
})
|
|
|
|
await runFullRestoreJob(job.id, archivePath, { conflictMode })
|
|
const done = getBackupJob(job.id)
|
|
if (!done || done.status !== 'done') {
|
|
console.error(`[PicHost] Restore failed: ${done?.error ?? done?.message ?? 'unknown error'}`)
|
|
process.exit(1)
|
|
}
|
|
|
|
console.log('[PicHost] Restore complete. Restart PicHost if it is running.')
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(`[PicHost] Restore error: ${error instanceof Error ? error.message : String(error)}`)
|
|
process.exit(1)
|
|
})
|