I could successfully backup database using Backup-Sqldatabase cmdlet to one .bak file. However, I was want to generate stripped backup files for the database. Is this possible using the cmdlet?
2 Answers
The cmdlet has a parameter -backupFile that accetps an array of file names. At least with the -Script parameter the emitted TSQL looks sensible, so it ought to work. Like so,
PS SQLSERVER:\> Backup-SqlDatabase -Script -ServerInstance ".\sqli001" -Database TestDB -BackupFile @("c:\temp\1.bak", "c:\temp\2.bak")
BACKUP DATABASE [TestDB] TO DISK = N'c:\temp\1.bak', DISK = N'c:\temp\2.bak' WITH NOFORMAT, NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10
GO
Comments
This will only generate the code to take backup.
Use the below PowerShell script to execute the backup and I have provided a way to pass the dynamic value to the backup file path as well shown below.
$path = 'D:\BackupFolder\TestDB.Bak,E:\BackupFolder\TestDB.Bak'
$QUERY = Backup-SqlDatabase -Script -ServerInstance ServerName -Database TestDB -BackupFile @($path.split(','))
invoke-sqlcmd -query "$QUERY" -ServerInstance "SQLInstanceName"