dbatools: Backup-DbaDatabase and Restore-DbaDatabase samples


I have played around with Backup-DbaDatabase and Restore-DbaDatabase cmdlets from dbatools. The following snippets are: backup selected databases and restore them with a different name on the same server.

  
  
  
#create a shared folder
$Network_Folder = '\\myfileshare\backups\'


#clean up backup folder --shared
Get-ChildItem -Path $Network_Folder -Include *.bak -File -Recurse | foreach { $_.Delete() }

#backup selected databases
Backup-DbaDatabase -SqlInstance my2019Machine -Database myDB1,myDB2,myDB3 -Type Full -CompressBackup -CopyOnly -BackupDirectory $Network_Folder

# restore a copy with new name
Restore-DbaDatabase -SqlInstance my2019Machine -Path $Network_Folder -RestoredDatabaseNamePrefix 'daily_' -DestinationDataDirectory d:\restoreedDB -WithReplace

# clean up
Remove-DbaDatabase -SqlInstance my2019Machine -Database daily_myDB1,daily_myDB2,daily_myDB3 -Confirm:$false

 
 

 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s