Skip to content

Commit 6807c9e

Browse files
authored
UBERF-10523: Fixes for backup/compact (#8888)
* UBERF-10523: Fixes for backup/compact Signed-off-by: Andrey Sobolev <[email protected]> * Fix build Signed-off-by: Andrey Sobolev <[email protected]> * Fix build Signed-off-by: Andrey Sobolev <[email protected]> --------- Signed-off-by: Andrey Sobolev <[email protected]>
1 parent 06fb92b commit 6807c9e

File tree

7 files changed

+430
-197
lines changed

7 files changed

+430
-197
lines changed

desktop/src/main/backup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async function doBackup (dirName: string, token: string, endpoint: string, wsIds
4747
blobDownloadLimit: backupHugeFiles ? 10240 : 50,
4848
token,
4949
skipBlobContentTypes: [],
50+
keepSnapshots: 7 * 14,
5051
isCanceled: (): boolean => {
5152
return runningBackup == null
5253
},

dev/tool/src/index.ts

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

server/backup-service/src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const envMap: { [key in keyof Config]: string } = {
4747
Storage: 'STORAGE',
4848
WorkspaceStorage: 'WORKSPACE_STORAGE',
4949
Region: 'REGION',
50-
Parallel: 'PARALLEL'
50+
Parallel: 'PARALLEL',
51+
KeepSnapshots: 'KEEP_SNAPSHOTS'
5152
}
5253

5354
const required: Array<keyof Config> = [

0 commit comments

Comments
 (0)