diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts index 93cffba3d6..765e7389b7 100644 --- a/dev/tool/src/index.ts +++ b/dev/tool/src/index.ts @@ -992,9 +992,11 @@ export function devTool ( .command('backup-find ') .description('dump workspace transactions and minio resources') .option('-d, --domain ', 'Check only domain') - .action(async (dirName: string, fileId: string, cmd: { domain: string | undefined }) => { + .option('-a, --all', 'Show all versions', false) + .action(async (dirName: string, fileId: string, cmd: { domain: string | undefined, all: boolean }) => { const storage = await createFileBackupStorage(dirName) - await backupFind(storage, fileId as unknown as Ref, cmd.domain) + console.log(cmd.all) + await backupFind(storage, fileId as unknown as Ref, cmd.all, cmd.domain) }) program diff --git a/server/backup/src/backup.ts b/server/backup/src/backup.ts index a2bf27f2e7..4625515bf1 100644 --- a/server/backup/src/backup.ts +++ b/server/backup/src/backup.ts @@ -196,7 +196,7 @@ async function loadDigest ( break } } - ctx.info('load-digest', { domain, snapshots: snapshots.length, documents: result.size }) + // ctx.info('load-digest', { domain, snapshots: snapshots.length, documents: result.size }) return result } async function verifyDigest ( @@ -1668,7 +1668,12 @@ export async function backupDownload (storage: BackupStorage, storeIn: string): /** * @public */ -export async function backupFind (storage: BackupStorage, id: Ref, domain?: string): Promise { +export async function backupFind ( + storage: BackupStorage, + id: Ref, + showAll: boolean, + domain?: string +): Promise { const infoFile = 'backup.json.gz' if (!(await storage.exists(infoFile))) { @@ -1698,25 +1703,42 @@ export async function backupFind (storage: BackupStorage, id: Ref, domain?: console.log('we found file') let found = false for (const sn of rnapshots) { + const ssDigest = await loadDigest(toolCtx, storage, [sn], dd) + if (!ssDigest.has(id)) { + continue + } const d = sn.domains[dd] - if (found) { + if (found && !showAll) { break } for (const sf of d?.storage ?? []) { - if (found) { + if (found && !showAll) { break } console.log('processing', sf) const readStream = await storage.load(sf) const ex = extract() - ex.on('entry', (headers, stream, next) => { if (headers.name === id + '.json') { console.log('file found in:', sf) + + const chunks: Buffer[] = [] + stream.on('data', (chunk) => { + chunks.push(chunk) + }) + stream.on('end', () => { + const bf = Buffer.concat(chunks as any) + console.log('>>>>>>>>>>>') + console.log(JSON.stringify(JSON.parse(bf.toString()), undefined, 2)) + console.log('>>>>>>>>>>>') + next() + }) + found = true + } else { + stream.resume() // auto drain for non-matching entries + next() // continue to the next entry } - next() - stream.resume() // just auto drain the stream }) const endPromise = new Promise((resolve) => {