Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 17x 17x 17x 12x 12x 10x 10x 10x 2x 2x 8x 8x 8x 1x 1x 7x 7x 17x 193x 193x | import { getBackups } from '@clevercloud/client/esm/api/v2/backups.js';
import fs from 'node:fs';
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { z } from 'zod';
import { defineArgument } from '../../lib/define-argument.js';
import { defineCommand } from '../../lib/define-command.js';
import { defineOption } from '../../lib/define-option.js';
import { resolveAddon } from '../../models/ids-resolver.js';
import { sendToApi } from '../../models/send-to-api.js';
import { orgaIdOrNameOption } from '../global.options.js';
import { databaseIdArg } from './database.args.js';
export const databaseBackupsDownloadCommand = defineCommand({
description: 'Download a database backup',
since: '2.10.0',
options: {
output: defineOption({
name: 'output',
schema: z.string().optional(),
description: 'Redirect the output of the command in a file',
aliases: ['out'],
placeholder: 'file-path',
}),
org: { ...orgaIdOrNameOption, deprecated: 'organisation is now resolved automatically' },
},
args: [
databaseIdArg,
defineArgument({
schema: z.string(),
description: 'A Database backup ID (format: UUID)',
placeholder: 'backup-id',
}),
],
async handler(options, addonIdOrRealId, backupId) {
const { output } = options;
const { ownerId, realId } = await resolveAddon(addonIdOrRealId);
const backups = await getBackups({ ownerId, ref: realId }).then(sendToApi);
const backup = backups.find((backup) => backup.backup_id === backupId);
if (backup == null) {
throw new Error('no backup with this ID');
}
const response = await globalThis.fetch(backup.download_url);
if (!response.ok) {
throw new Error('Failed to download backup');
}
const nodeReadable = Readable.fromWeb(response.body);
await pipeline(nodeReadable, output ? fs.createWriteStream(output) : process.stdout);
},
});
|