Pages

Sunday, June 13, 2010

SQL 2008 Admin Tasks

SHRINK the LOG
USE [master]
GO
ALTER DATABASE [TestDb] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(TestDbLog, 1)
ALTER DATABASE [TestDb] SET RECOVERY FULL WITH NO_WAIT
GO




samples
USE LRR_PROD
GO
ALTER DATABASE LRR_PROD SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(LRR_Log, 1)
ALTER DATABASE LRR_PROD SET RECOVERY FULL WITH NO_WAIT
GO


USE cliwebservices
GO
ALTER DATABASE cliwebservices SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(cliwebservices_log, 1)
ALTER DATABASE cliwebservices SET RECOVERY FULL WITH NO_WAIT
GO



Backup 
BACKUP DATABASE [db_name] TO DISK = N'\\otfvclicwebuat\webuat\databasesbackup\Web2ServicesPortal.bak' WITH NOFORMAT, NOINIT, NAME = N'CLProjects-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO




Restore
RESTORE DATABASE[db_name] FROM DISK = N'C:\Projects\clic\Dashboard\BI\Others (do not check in)\db\MUM2008_PROD.bak' WITH FILE = 1, MOVE N'MUM08_PROD_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.OTP3222_MSSQL_08\MSSQL\DATA\[db_name].mdf', MOVE N'MUM08_PROD_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.OTP3222_MSSQL_08\MSSQL\DATA\[db_name]_1.ldf', NOUNLOAD, STATS = 10
GO

No comments:

Post a Comment