11import RemoteHandlerAbstract from '@xen-orchestra/fs'
22import { basename , normalize } from '@xen-orchestra/fs/path'
33import { VmFullBackupArchive } from './VmFullBackupArchive.mjs'
4- import { IVmBackupInterface , PartialBackupMetadata } from './VmBackup.types.mjs'
4+ import { BackupCleanOptions , IVmBackupInterface , PartialBackupMetadata } from './VmBackup.types.mjs'
55
66const FILES_TO_KEEP = [ 'cache.json.gz' ]
77
@@ -11,10 +11,22 @@ export class VmBackupDirectory implements IVmBackupInterface {
1111 files : Array < string > = new Array ( )
1212 orphans : Set < string > = new Set ( )
1313 backupArchives : Map < string , IVmBackupInterface > = new Map ( )
14+ opts : BackupCleanOptions
1415
15- constructor ( handler : RemoteHandlerAbstract , vmBackupPath : string ) {
16+ constructor (
17+ handler : RemoteHandlerAbstract ,
18+ vmBackupPath : string ,
19+ opts = {
20+ fix : true ,
21+ merge : false ,
22+ remove : false ,
23+ logInfo : console . info . bind ( console ) ,
24+ logWarn : console . warn . bind ( console ) ,
25+ }
26+ ) {
1627 this . handler = handler
1728 this . rootPath = vmBackupPath
29+ this . opts = opts
1830 }
1931
2032 async init ( ) {
@@ -25,7 +37,7 @@ export class VmBackupDirectory implements IVmBackupInterface {
2537 const backupArchive = await this . createBackupArchive ( fullPath , metadata )
2638 this . backupArchives . set ( fullPath , backupArchive )
2739 } catch ( error ) {
28- console . warn ( `Issue loading ${ metadata . xva ?? metadata . vhds } ` , { json : fullPath , backup : metadata } )
40+ this . opts . logWarn ( `Issue loading ${ metadata . xva ?? metadata . vhds } ` , { json : fullPath , backup : metadata } )
2941 }
3042 }
3143 }
@@ -63,15 +75,15 @@ export class VmBackupDirectory implements IVmBackupInterface {
6375 fix : true ,
6476 merge : true ,
6577 remove : true ,
66- logWarn : console . warn ,
67- logInfo : console . log ,
78+ logWarn : this . opts . logWarn ,
79+ logInfo : this . opts . logInfo ,
6880 } )
6981 } else {
7082 //@ts -ignore
7183 backupArchive = new VmIncrementalBackupArchive ( this . handler )
7284 }
7385 } catch ( error ) {
74- console . warn ( `Error trying to create backupArchive from ${ metadataPath } ` , { metadata } )
86+ this . opts . logWarn ( `Error trying to create backupArchive from ${ metadataPath } ` , { metadata } )
7587 throw new Error ( `Error trying to create backupArchive from ${ metadataPath } ` )
7688 }
7789 await backupArchive . init ( )
0 commit comments