@@ -29,9 +29,6 @@ def call(virtual_server)
2929 next
3030 end
3131
32- # Get BackupSize for restorePoints
33- backup_size = get_backup_size ( backup_id )
34-
3532 # Get vmRestorePoints for restorePoints
3633 get_recovery_points ( "restorePoints" , rp_id , "vmRestorePoints" )
3734 . flatten
@@ -43,6 +40,9 @@ def call(virtual_server)
4340 # Restore point date is right after '@' rightmost occurrence
4441 vm_restore_point_date = vm_restore_point_hash [ :Name ] . rpartition ( '@' ) [ 2 ]
4542
43+ # Get BackupSize for restorePoints
44+ backup_size = get_backup_size ( vm_restore_point_hash )
45+
4646 build_recovery_point ( size : backup_size ,
4747 created_at : vm_restore_point_date ,
4848 updated_at : vm_restore_point_date ,
@@ -80,14 +80,14 @@ def get_vm_recovery_points(resource_id)
8080 vm_points . is_a? ( Hash ) ? [ vm_points ] : vm_points
8181 end
8282
83- def get_backup_size ( backup_id )
84- api_get (
85- build_query ( :BackupFile , BackupUid : identifier_to_uid ( :Backup , backup_id ) )
86- )
87- . dig ( :QueryResult , :Entities , :BackupFiles , :BackupFile )
88- . map { | hash | hash . transform_keys ( & :downcase ) }
89- . max_by { | hash | Time . parse ( hash [ :creationtimeutc ] ) if hash [ :creationtimeutc ] }
90- &. fetch ( :backupsize , 0 )
83+ def get_backup_size ( vm_restore_point_hash )
84+ refs = vm_restore_point_hash . dig ( :Links , :Link )
85+
86+ backup_file_id = refs . detect { | hash | hash [ :Type ] == 'BackupFileReference' } &. fetch ( :Href , '' ) &. rpartition ( '/' ) &. last
87+
88+ return 0 unless backup_file_id
89+
90+ api_get ( "backupFiles/ #{ backup_file_id } ?format=Entity" ) . dig ( :BackupFile , :BackupSize )
9191 rescue RestClient ::BadRequest
9292 0
9393 end
0 commit comments