Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VMWARE-818] Add ability to get backup size directly for vm_restore_p… #7

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions recovery_points_for_virtual_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def call(virtual_server)
next
end

# Get BackupSize for restorePoints
backup_size = get_backup_size(backup_id)

# Get vmRestorePoints for restorePoints
get_recovery_points("restorePoints", rp_id, "vmRestorePoints")
.flatten
Expand All @@ -43,6 +40,9 @@ def call(virtual_server)
# Restore point date is right after '@' rightmost occurrence
vm_restore_point_date = vm_restore_point_hash[:Name].rpartition('@')[2]

# Get BackupSize for restorePoints
backup_size = get_backup_size(vm_restore_point_hash)

build_recovery_point(size: backup_size,
created_at: vm_restore_point_date,
updated_at: vm_restore_point_date,
Expand Down Expand Up @@ -80,14 +80,14 @@ def get_vm_recovery_points(resource_id)
vm_points.is_a?(Hash) ? [vm_points] : vm_points
end

def get_backup_size(backup_id)
api_get(
build_query(:BackupFile, BackupUid: identifier_to_uid(:Backup, backup_id))
)
.dig(:QueryResult, :Entities, :BackupFiles, :BackupFile)
.map { |hash| hash.transform_keys(&:downcase) }
.max_by { |hash| Time.parse(hash[:creationtimeutc]) if hash[:creationtimeutc] }
&.fetch(:backupsize, 0)
def get_backup_size(vm_restore_point_hash)
refs = vm_restore_point_hash.dig(:Links, :Link)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this works? .dig works only for hashes, and vm_restore_point_hash[:Links] will be an array if I'm not mistaken (I've looked at https://helpcenter.veeam.com/docs/backup/em_rest/restorepoints_id_vmrestorepoints.html?ver=110 for API reference)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vm_restore_point_hash variable here has hash inside like this
{:Links=> {:Link=> [{:Href=>"https://10.63.0.92:9398/api/backupServers/bd76362f-fa63-4d9a-a988-599b41c0f423", :Name=>"vc-b-backup.onappdev.lviv", :Type=>"BackupServerReference", :Rel=>"Up"}, {:Href=>"https://10.63.0.92:9398/api/restorePoints/f1734567-c830-40bd-8476-e935449c788b", :Name=>"Apr 7 2022 11:49AM", :Type=>"RestorePointReference", :Rel=>"Up"}, {:Href=>"https://10.63.0.92:9398/api/backupFiles/bf1f4635-ead1-4f5a-ae4b-adabac3b0e75", :Name=>"Hourly 4@ms_centOS6_vmwaretoolsD2022-04-07T144924_F0CB.vib", :Type=>"BackupFileReference", :Rel=>"Up"}, {:Href=>"https://10.63.0.92:9398/api/vmRestorePoints/2e9b79cb-f1ff-4d63-8bf7-c3efdcf0a83c?format=Entity", :Name=>"ms_centOS6_vmwaretools-VNAN@2022-04-07 11:49:48", :Type=>"VmRestorePoint", :Rel=>"Alternate"}]}, :UID=>"urn:veeam:VmRestorePoint:2e9b79cb-f1ff-4d63-8bf7-c3efdcf0a83c", :Name=>"ms_centOS6_vmwaretools-VNAN@2022-04-07 11:49:48", :Href=>"https://10.63.0.92:9398/api/vmRestorePoints/2e9b79cb-f1ff-4d63-8bf7-c3efdcf0a83c", :Type=>"VmRestorePointReference"}

It will work


backup_file_id = refs.detect { |hash| hash[:Type] == 'BackupFileReference' }&.fetch(:Href, '')&.rpartition('/')&.last

return 0 unless backup_file_id

api_get("backupFiles/#{backup_file_id}?format=Entity").dig(:BackupFile, :BackupSize)
rescue RestClient::BadRequest
0
end
Expand Down