database files movement from one drive to another drive in sql server
Get link
Facebook
X
Pinterest
Email
Other Apps
1) Capture the .mdf and ldf file namesof that particular datbase to which you want tomoveSELECT*FROM sys.master_files
2) Ensure that you have latest .BAK file available forrollback plan
3) Take that particular database alone into OFFLINE
ALTERDATABASE database_name
SET OFFLINE
4) Move the files tonewlocation5) Run the below command make changes atsystem catlogue level
USE master
GOALTERDATABASE AdventureWorks2012
MODIFY FILE( NAME = AdventureWorks2012_Log,
FILENAME ='C:\NewLoc\AdventureWorks2012_Log.ldf');
GOALTERDATABASE AdventureWorks2012
MODIFY FILE ( NAME = AdventureWorks2012_Data,
FILENAME ='C:\NewLoc\AdventureWorks2012_data.mdf');
6) Bring the database ONLINE
ALTERDATABASE database_name
SET ONLINE
7)Once the database came online run the below commmand to chek whether the new path appearing at catlogue levelSELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'<database_name>');
We can run below PowerShell and SQL Server commands when we want to find ou when the failover has happened. cls Get-winEvent -ComputerName ListerNameHere -filterHashTable @{logname = 'Microsoft-Windows-FailoverClustering/Operational' ; id = 1641 } | Where-Object { $_ . Timecreated -like '*05/09/2020*' } | Format-Table -AutoSize -Wrap <# 35201-->timeout alert run this by changing -LogName to System 41-->41 is power shutdown run this in system #> clear Get-EventLog -LogName Application -After ( Get-Date ) . AddHours( -48 ) | Where-Object { $_ . EventID -in ( 1100 , 1074 , 35201,41,1561,7024,1135,7032,1146 )} | Format-Table -AutoSize -Wrap cls Get-EventLog ` -LogName System |Where-Object{$_.EventID -in (1054,1053,1055,1138,1141,1142,5140,5142,1559,1560,1563,1588,1068,5144,1562,5143,5168,1564,1177)}|Format-Table -AutoSize -Wrap EXEC sp_readerrorlog 0,1,'lease worker' EXEC sp_readerrorlog 0,1,'...
We can use below dbatools to restore database. Export-DbaUser will export all the respective database users to a spcific file. If you want all the user script need to add single file then user -FilePath parameter.If you want indivual files need to created user -Path parameter. cls Export - DbaUser ` - SqlInstance InstanceNameHere ` - Database DatabaseNameHere ` - FilePath C : \ Temp \ Users_DatbaseNameHere_InstanceNameHere. sql ` - Verbose In the below command -Path parameter you no need pass .BAK file it will automatically read file. -WithReplace option will overwrite the existing database. Restore - DbaDatabase ` - SqlInstance InstanceNameHere ` - DatabaseName DatabaseNameHere ` - Path H: \ TodayRestore ` - DestinationDataDirectory "F:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Data\DatabaseName_Data.mdf" ` - DestinationLogDirectory "G:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Data\DatbaseName_Log.ldf" ` - Wit...
Comments