@@ -947,6 +947,7 @@ export function devTool (
947947 . option ( '-bl, --blobLimit <blobLimit>' , 'A blob size limit in megabytes (default 15mb)' , '15' )
948948 . option ( '-f, --force' , 'Force backup' , false )
949949 . option ( '-t, --timeout <timeout>' , 'Connect timeout in seconds' , '30' )
950+ . option ( '-k, --keepSnapshots <keepSnapshots>' , 'Keep snapshots for days' , '14' )
950951 . action (
951952 async (
952953 dirName : string ,
@@ -959,6 +960,7 @@ export function devTool (
959960 blobLimit : string
960961 contentTypes : string
961962 full : boolean
963+ keepSnapshots : string
962964 }
963965 ) => {
964966 const storage = await createFileBackupStorage ( dirName )
@@ -984,7 +986,8 @@ export function devTool (
984986 skipBlobContentTypes : cmd . contentTypes
985987 . split ( ';' )
986988 . map ( ( it ) => it . trim ( ) )
987- . filter ( ( it ) => it . length > 0 )
989+ . filter ( ( it ) => it . length > 0 ) ,
990+ keepSnapshots : parseInt ( cmd . keepSnapshots )
988991 } )
989992 } )
990993 }
@@ -1004,9 +1007,18 @@ export function devTool (
10041007 . command ( 'backup-compact <dirName>' )
10051008 . description ( 'Compact a given backup, will create one snapshot clean unused resources' )
10061009 . 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 } ) => {
10081017 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+ } )
10101022 } )
10111023 program
10121024 . command ( 'backup-check <dirName>' )
@@ -1231,21 +1243,30 @@ export function devTool (
12311243 // await backupRemoveLast(storage, daysInterval)
12321244 // })
12331245
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+ } )
12491270 // program
12501271 // .command('backup-s3-check <bucketName> <dirName>')
12511272 // .description('Compact a given backup to just one snapshot')
@@ -2465,5 +2486,13 @@ export function devTool (
24652486
24662487 extendProgram ?.( program )
24672488
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+
24682497 program . parse ( process . argv )
24692498}
0 commit comments