Skip to content

Commit

Permalink
Changed name to PowerShell Standard (#5648)
Browse files Browse the repository at this point in the history
Kept alias
  • Loading branch information
potatoqualitee authored May 30, 2019
1 parent 925f5b9 commit fbdbcfc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
52 changes: 27 additions & 25 deletions functions/Backup-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ function Backup-DbaDatabase {
.PARAMETER ExcludeDatabase
The database(s) to exclude. This list is auto-populated from the server.
.PARAMETER BackupFileName
.PARAMETER FilePath
The name of the file to backup to. This is only accepted for single database backups.
If no name is specified then the backup files will be named DatabaseName_yyyyMMddHHmm (i.e. "Database1_201714022131") with the appropriate extension.
If the same name is used repeatedly, SQL Server will add backups to the same file at an incrementing position.
SQL Server needs permissions to write to the specified location. Path names are based on the SQL Server (C:\ is the C drive on the SQL Server, not the machine running the script).
Passing in NUL as the BackupFileName will backup to the NUL: device
Passing in NUL as the FilePath will backup to the NUL: device
.PARAMETER TimeStampFormat
By default the command timestamps backups using the format yyyyMMddHHmm. Using this parameter this can be overridden. The timestamp format should be defined using the Get-Date formats, illegal formats will cause an error to be thrown
.PARAMETER BackupDirectory
.PARAMETER Path
Path in which to place the backup files. If not specified, the backups will be placed in the default backup location for SqlInstance.
If multiple paths are specified, the backups will be striped across these locations. This will overwrite the FileCount option.
Expand All @@ -40,7 +40,7 @@ function Backup-DbaDatabase {
File Names with be suffixed with x-of-y to enable identifying striped sets, where y is the number of files in the set and x ranges from 1 to y.
.PARAMETER ReplaceInName
If this switch is set, the following list of strings will be replaced in the BackupFileName and BackupDirectory strings:
If this switch is set, the following list of strings will be replaced in the FilePath and Path strings:
instancename - will be replaced with the instance Name
servername - will be replaced with the server name
dbname - will be replaced with the database name
Expand All @@ -59,7 +59,7 @@ function Backup-DbaDatabase {
This is the number of striped copies of the backups you wish to create. This value is overwritten if you specify multiple Backup Directories.
.PARAMETER CreateFolder
If this switch is enabled, each database will be backed up into a separate folder on each of the paths specified by BackupDirectory.
If this switch is enabled, each database will be backed up into a separate folder on each of the paths specified by Path.
.PARAMETER CompressBackup
If this switch is enabled, the function will try to perform a compressed backup if supported by the version and edition of SQL Server. Otherwise, this function will use the server(s) default setting for compression.
Expand Down Expand Up @@ -141,7 +141,7 @@ function Backup-DbaDatabase {
This will perform a full database backup on the databases HR and Finance on SQL Server Instance Server1 to Server1 default backup directory.
.EXAMPLE
PS C:\> Backup-DbaDatabase -SqlInstance sql2016 -BackupDirectory C:\temp -Database AdventureWorks2014 -Type Full
PS C:\> Backup-DbaDatabase -SqlInstance sql2016 -Path C:\temp -Database AdventureWorks2014 -Type Full
Backs up AdventureWorks2014 to sql2016 C:\temp folder.
Expand All @@ -156,17 +156,17 @@ function Backup-DbaDatabase {
Performs a full backup of all databases on the sql2016 instance to the https://dbatoolsaz.blob.core.windows.net/azbackups/ container on Azure blog storage using the Shared Access Signature sql credential "https://dbatoolsaz.blob.core.windows.net/azbackups" registered on the sql2016 instance.
.EXAMPLE
PS C:\> Backup-Dbadatabase -SqlInstance Server1\Prod -Database db1 -BackupDirectory \\filestore\backups\servername\instancename\dbname\backuptype -Type Full -ReplaceInName
PS C:\> Backup-Dbadatabase -SqlInstance Server1\Prod -Database db1 -Path \\filestore\backups\servername\instancename\dbname\backuptype -Type Full -ReplaceInName
Performs a full backup of db1 into the folder \\filestore\backups\server1\prod\db1
.EXAMPLE
PS C:\> Backup-Dbadatabase -SqlInstance Server1\Prod -BackupDirectory \\filestore\backups\servername\instancename\dbname\backuptype -BackupFileName dbname-backuptype-timestamp.trn -Type Log -ReplaceInName
PS C:\> Backup-Dbadatabase -SqlInstance Server1\Prod -Path \\filestore\backups\servername\instancename\dbname\backuptype -FilePath dbname-backuptype-timestamp.trn -Type Log -ReplaceInName
Performs a log backup for every database. For the database db1 this would results in backup files in \\filestore\backups\server1\prod\db1\Log\db1-log-31102018.trn
.EXAMPLE
PS C:\> Backup-DbaDatabase -SqlInstance Sql2017 -Database master -BackupFileName NUL
PS C:\> Backup-DbaDatabase -SqlInstance Sql2017 -Database master -FilePath NUL
Performs a backup of master, but sends the output to the NUL device (ie; throws it away)
Expand All @@ -183,8 +183,10 @@ function Backup-DbaDatabase {
[PSCredential]$SqlCredential,
[object[]]$Database,
[object[]]$ExcludeDatabase,
[string[]]$BackupDirectory,
[string]$BackupFileName,
[Alias('BackupDirectory')]
[string[]]$Path,
[Alias('BackupFileName')]
[string]$FilePath,
[switch]$ReplaceInName,
[switch]$CopyOnly,
[ValidateSet('Full', 'Log', 'Differential', 'Diff', 'Database')]
Expand Down Expand Up @@ -251,17 +253,17 @@ function Backup-DbaDatabase {
$InputObject = $InputObject | Where-Object Name -notin $ExcludeDatabase
}

if ($null -eq $BackupDirectory -and $backupfileName -ne 'NUL') {
if ($null -eq $Path -and $FilePath -ne 'NUL') {
Write-Message -Message 'No backupfolder passed in, setting it to instance default' -Level Verbose
$BackupDirectory = (Get-DbaDefaultPath -SqlInstance $server).Backup
$Path = (Get-DbaDefaultPath -SqlInstance $server).Backup
}

if ($BackupDirectory.Count -gt 1) {
if ($Path.Count -gt 1) {
Write-Message -Level Verbose -Message "Multiple Backup Directories, striping"
$Filecount = $BackupDirectory.Count
$Filecount = $Path.Count
}

if ($InputObject.Count -gt 1 -and $BackupFileName -ne '' -and $True -ne $ReplaceInFile) {
if ($InputObject.Count -gt 1 -and $FilePath -ne '' -and $True -ne $ReplaceInFile) {
Stop-Function -Message "1 BackupFile specified, but more than 1 database."
return
}
Expand Down Expand Up @@ -294,7 +296,7 @@ function Backup-DbaDatabase {
}
}
$FileCount = $AzureBaseUrl.count
$BackupDirectory = $AzureBaseUrl
$Path = $AzureBaseUrl
}

if ($OutputScriptOnly) {
Expand Down Expand Up @@ -420,14 +422,14 @@ function Backup-DbaDatabase {
$BackupFinalName = ''
$FinalBackupPath = @()
$timestamp = Get-Date -Format $TimeStampFormat
if ('NUL' -eq $BackupFileName) {
if ('NUL' -eq $FilePath) {
$FinalBackupPath += 'NUL:'
$IgnoreFileChecks = $true
} elseif ('' -ne $BackupFileName) {
$File = New-Object System.IO.FileInfo($BackupFileName)
} elseif ('' -ne $FilePath) {
$File = New-Object System.IO.FileInfo($FilePath)
$BackupFinalName = $file.Name
$suffix = $file.extension -Replace '^\.', ''
if ( '' -ne (Split-Path $BackupFileName)) {
if ( '' -ne (Split-Path $FilePath)) {
Write-Message -Level Verbose -Message "Fully qualified path passed in"
$FinalBackupPath += [IO.Path]::GetFullPath($file.DirectoryName)
}
Expand All @@ -438,10 +440,10 @@ function Backup-DbaDatabase {

Write-Message -Level Verbose -Message "Building backup path"
if ($FinalBackupPath.Count -eq 0) {
$FinalBackupPath += $BackupDirectory
$FinalBackupPath += $Path
}

if ($BackupDirectory.Count -eq 1 -and $Filecount -gt 1) {
if ($Path.Count -eq 1 -and $Filecount -gt 1) {
for ($i = 0; $i -lt ($Filecount - 1); $i++) {
$FinalBackupPath += $FinalBackupPath[0]
}
Expand Down Expand Up @@ -495,7 +497,7 @@ function Backup-DbaDatabase {
}


if ($null -eq $AzureBaseUrl -and $BackupDirectory) {
if ($null -eq $AzureBaseUrl -and $Path) {
$FinalBackupPath = $FinalBackupPath | ForEach-Object { [IO.Path]::GetFullPath($_) }
}

Expand Down Expand Up @@ -629,7 +631,7 @@ function Backup-DbaDatabase {
$OutputExclude += ('Notes', 'FirstLsn', 'DatabaseBackupLsn', 'CheckpointLsn', 'LastLsn', 'BackupSetId', 'LastRecoveryForkGuid')
}
$headerinfo | Select-DefaultView -ExcludeProperty $OutputExclude
$BackupFileName = $null
$FilePath = $null
}
}
}
2 changes: 1 addition & 1 deletion tests/Backup-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'BackupDirectory', 'BackupFileName', 'ReplaceInName', 'CopyOnly', 'Type', 'InputObject', 'CreateFolder', 'FileCount', 'CompressBackup', 'Checksum', 'Verify', 'MaxTransferSize', 'BlockSize', 'BufferCount', 'AzureBaseUrl', 'AzureCredential', 'NoRecovery', 'BuildPath', 'WithFormat', 'Initialize', 'SkipTapeHeader', 'TimeStampFormat', 'IgnoreFileChecks', 'OutputScriptOnly', 'EnableException'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'Path', 'FilePath', 'ReplaceInName', 'CopyOnly', 'Type', 'InputObject', 'CreateFolder', 'FileCount', 'CompressBackup', 'Checksum', 'Verify', 'MaxTransferSize', 'BlockSize', 'BufferCount', 'AzureBaseUrl', 'AzureCredential', 'NoRecovery', 'BuildPath', 'WithFormat', 'Initialize', 'SkipTapeHeader', 'TimeStampFormat', 'IgnoreFileChecks', 'OutputScriptOnly', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
Expand Down

0 comments on commit fbdbcfc

Please sign in to comment.