@@ -947,6 +947,7 @@ export function devTool (
947
947
. option ( '-bl, --blobLimit <blobLimit>' , 'A blob size limit in megabytes (default 15mb)' , '15' )
948
948
. option ( '-f, --force' , 'Force backup' , false )
949
949
. option ( '-t, --timeout <timeout>' , 'Connect timeout in seconds' , '30' )
950
+ . option ( '-k, --keepSnapshots <keepSnapshots>' , 'Keep snapshots for days' , '14' )
950
951
. action (
951
952
async (
952
953
dirName : string ,
@@ -959,6 +960,7 @@ export function devTool (
959
960
blobLimit : string
960
961
contentTypes : string
961
962
full : boolean
963
+ keepSnapshots : string
962
964
}
963
965
) => {
964
966
const storage = await createFileBackupStorage ( dirName )
@@ -984,7 +986,8 @@ export function devTool (
984
986
skipBlobContentTypes : cmd . contentTypes
985
987
. split ( ';' )
986
988
. map ( ( it ) => it . trim ( ) )
987
- . filter ( ( it ) => it . length > 0 )
989
+ . filter ( ( it ) => it . length > 0 ) ,
990
+ keepSnapshots : parseInt ( cmd . keepSnapshots )
988
991
} )
989
992
} )
990
993
}
@@ -1004,9 +1007,18 @@ export function devTool (
1004
1007
. command ( 'backup-compact <dirName>' )
1005
1008
. description ( 'Compact a given backup, will create one snapshot clean unused resources' )
1006
1009
. option ( '-f, --force' , 'Force compact.' , false )
1007
- . action ( async ( dirName : string , cmd : { force : boolean } ) => {
1010
+ . option (
1011
+ '-ct, --contentTypes <contentTypes>' ,
1012
+ 'A list of ; separated content types for blobs to exclude from backup' ,
1013
+ 'video/;application/octet-stream'
1014
+ )
1015
+ . option ( '-k, --keepSnapshots <keepSnapshots>' , 'Keep snapshots for days' , '14' )
1016
+ . action ( async ( dirName : string , cmd : { force : boolean , contentTypes : string , keepSnapshots : string } ) => {
1008
1017
const storage = await createFileBackupStorage ( dirName )
1009
- await compactBackup ( toolCtx , storage , cmd . force )
1018
+ await compactBackup ( toolCtx , storage , cmd . force , {
1019
+ blobLimit : 10 * 1024 * 1024 , // 10 MB
1020
+ skipContentTypes : cmd . contentTypes . split ( ';' )
1021
+ } )
1010
1022
} )
1011
1023
program
1012
1024
. command ( 'backup-check <dirName>' )
@@ -1231,21 +1243,30 @@ export function devTool (
1231
1243
// await backupRemoveLast(storage, daysInterval)
1232
1244
// })
1233
1245
1234
- // program
1235
- // .command('backup-s3-compact <bucketName> <dirName>')
1236
- // .description('Compact a given backup to just one snapshot')
1237
- // .option('-f, --force', 'Force compact.', false)
1238
- // .action(async (bucketName: string, dirName: string, cmd: { force: boolean, print: boolean }) => {
1239
- // const backupStorageConfig = storageConfigFromEnv(process.env.STORAGE)
1240
- // const storageAdapter = createStorageFromConfig(backupStorageConfig.storages[0])
1241
- // try {
1242
- // const storage = await createStorageBackupStorage(toolCtx, storageAdapter, getWorkspaceId(bucketName), dirName)
1243
- // await compactBackup(toolCtx, storage, cmd.force)
1244
- // } catch (err: any) {
1245
- // toolCtx.error('failed to size backup', { err })
1246
- // }
1247
- // await storageAdapter.close()
1248
- // })
1246
+ program
1247
+ . command ( 'backup-s3-compact <bucketName> <dirName>' )
1248
+ . description ( 'Compact a given backup to just one snapshot' )
1249
+ . option ( '-f, --force' , 'Force compact.' , false )
1250
+ . option (
1251
+ '-ct, --contentTypes <contentTypes>' ,
1252
+ 'A list of ; separated content types for blobs to exclude from backup' ,
1253
+ 'video/;application/octet-stream'
1254
+ )
1255
+ . action ( async ( bucketName : string , dirName : string , cmd : { force : boolean , contentTypes : string } ) => {
1256
+ const backupStorageConfig = storageConfigFromEnv ( process . env . STORAGE )
1257
+ const storageAdapter = createStorageFromConfig ( backupStorageConfig . storages [ 0 ] )
1258
+ const backupIds = { uuid : bucketName as WorkspaceUuid , dataId : bucketName as WorkspaceDataId , url : '' }
1259
+ try {
1260
+ const storage = await createStorageBackupStorage ( toolCtx , storageAdapter , backupIds , dirName )
1261
+ await compactBackup ( toolCtx , storage , cmd . force , {
1262
+ blobLimit : 10 * 1024 * 1024 , // 10 MB
1263
+ skipContentTypes : cmd . contentTypes !== undefined ? cmd . contentTypes . split ( ';' ) : undefined
1264
+ } )
1265
+ } catch ( err : any ) {
1266
+ toolCtx . error ( 'failed to size backup' , { err } )
1267
+ }
1268
+ await storageAdapter . close ( )
1269
+ } )
1249
1270
// program
1250
1271
// .command('backup-s3-check <bucketName> <dirName>')
1251
1272
// .description('Compact a given backup to just one snapshot')
@@ -2465,5 +2486,13 @@ export function devTool (
2465
2486
2466
2487
extendProgram ?.( program )
2467
2488
2489
+ process . on ( 'unhandledRejection' , ( reason , promise ) => {
2490
+ toolCtx . error ( 'Unhandled Rejection at:' , { reason, promise } )
2491
+ } )
2492
+
2493
+ process . on ( 'uncaughtException' , ( error , origin ) => {
2494
+ toolCtx . error ( 'Uncaught Exception at:' , { origin, error } )
2495
+ } )
2496
+
2468
2497
program . parse ( process . argv )
2469
2498
}
0 commit comments