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

New-DcnImage: Properly record database size from backup files #172

Closed
lowlydba opened this issue Feb 16, 2022 · 2 comments · Fixed by #202
Closed

New-DcnImage: Properly record database size from backup files #172

lowlydba opened this issue Feb 16, 2022 · 2 comments · Fixed by #202
Labels
bug Something isn't working

Comments

@lowlydba
Copy link
Contributor

lowlydba commented Feb 16, 2022

If the database image is being created from a backup that already exists, the function defaults to a size of 1MB:

else {
$DatabaseCollection = @{
Name = $Database
Size = 1
};
}

The size could be grabbed from the restored version of the database in either case (new backup or existing) after any provided SQL scripts are run against it to provide a more accurate size value when logging it to the metadata store.

This value is also used (pre-restore) to check size requirements, but could probably be replaced with the backup size (via Read-DbaBackupHeader?) as a fallback, which would be more accurate than 1:

if ($PSCmdlet.ShouldProcess($db, "Checking available disk space for database")) {
# Check the database size to the available disk space
if ($computer.IsLocalhost) {
$availableMB = (Get-PSDrive -Name $ImageLocalPath.Substring(0, 1)).Free / 1MB
}
else {
$command = [ScriptBlock]::Create("(Get-PSDrive -Name $($ImageLocalPath.Substring(0, 1)) ).Free / 1MB")
$availableMB = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $commandGetLocalPath -Credential $DestinationCredential
}
$dbSizeMB = $db.Size
if ($availableMB -lt $dbSizeMB) {
Stop-PSFFunction -Message "Size of database $($db.Name) does not fit within the image local path" -Target $db -Continue
}
}

@lowlydba lowlydba changed the title New-DcnImage - Properly record database size from backup files New-DcnImage: Properly record database size from backup files Feb 16, 2022
@lowlydba
Copy link
Contributor Author

May need to be on hold until dataplat/dbatools#8302 is fixed

sanderstad added a commit that referenced this issue Apr 19, 2022
New-DcnImage: Get backup time from restore if needed. 

Fixes #184 and #172
@sanderstad sanderstad added the bug Something isn't working label Apr 19, 2022
@lowlydba
Copy link
Contributor Author

lowlydba commented May 6, 2022

I'll see about getting a PR for this soon now that the upstream issue is resolved, should be easy now that we're capturing the restore header info already from #184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants