Moving DPM 2016 DB after JSON Install

Whilst scripting the JSON installation for DPM 2016, i discovered that i couldn’t specify the DPM DB location. There is a parameter for this, but no matter what i tried, the DPM DB files would always be installed on the C Drive, despite the default location being another drive.

To get around this once DPM is installed i scripted a DB move to move it to the correct drive. The PowerShell below is what i used. First i set the DB offline, move the DB files to the new drive, copy ACL’s to the new path, modify the DB file names to match the new location and then set the DB online.

#Set DPM DB Offline
Invoke-Sqlcmd -Query `
“ALTER DATABASE [DPMDB_$dpmvmname] SET OFFLINE WITH ROLLBACK IMMEDIATE
GO”

#Move DPM Db Files
Get-ChildItem -Path “C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA” -Filter “$(‘MSDPM2012’+’$DPMDB’+’_’+$dpmvmname+’.mdf’)” | Move-Item -Destination S:\SQLData\
Get-Acl -Path “C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA” | Set-Acl -Path S:\SQLData\
Get-ChildItem -Path “C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA” -Filter “$(‘MSDPM2012’+’$DPMDB’+’_’+$dpmvmname+’_log’+’.ldf’)” | Move-Item -Destination S:\SQLLogs\
Get-Acl -Path “C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA” | Set-Acl -Path S:\SQLLogs\

#Modify DPM DB FileNames
Invoke-Sqlcmd -Query `
“ALTER DATABASE [DPMDB_$dpmvmname] MODIFY FILE ( NAME = ‘$(‘MSDPM2012’+’$DPMDB’+’_’+$dpmvmname+’_dat’)’, FILENAME = ‘S:\SQLData\$(‘MSDPM2012’+’$DPMDB’+’_’+$dpmvmname+’.mdf’)’ )
ALTER DATABASE [DPMDB_$dpmvmname] MODIFY FILE ( NAME = ‘$(‘MSDPM2012’+’$DPMDB’+’_’+$dpmvmname+’log’+’_dat’)’, FILENAME = ‘S:\SQLLogs\$(‘MSDPM2012’+’$DPMDB’+’_’+$dpmvmname+’_log’+’.ldf’)’ )
GO”

#Set DPM DB Online
Invoke-Sqlcmd -Query `
“ALTER DATABASE [DPMDB_$dpmvmname] SET ONLINE
GO”

Enterprise Mobility Workshops - 24th November 2015 - London | 9:00am – 3:00pm

Leave a Reply

Your email address will not be published. Required fields are marked *