Surendra Sharma

Surendra Sharma

Search This Blog

Monday, August 8, 2016

How to bring database from recovery mode to normal mode



I have published my last article about database restore. This article is also related with database.

I was trying to restore my Sitecore database from script, but that database was in recovery mode. If you try to restore any database which is in recovery mode, you will get sql error

Msg 3101, Level 16, State 1, Line 2
Exclusive access could not be obtained because the database is in use.
RESTORE DATABASE is terminating abnormally.

How to change any database mode from recovery to normal?

Solution:

There may be scripts and other option related with this but I suppose below is pretty straight forward way.

To remove recovery mode 

1. You need to offline database by Right click on Database -> Tasks -> Take Offline as 





2. Bring database to online by Right click on Database -> Tasks -> Bring Online as


 

Please leave your comments or share this trick if it’s useful for you.

Thursday, August 4, 2016

Script for restoring Sitecore databases on DEV, QA and UAT environment



There are some task which are very important but takes time during website development and maintenance. One such task is restoring databases.

After every SPRINT, I have to take backup of Production Sitecore master and web databases and need to restore on Staging, QA and DEV environment. The size of each database is 12 GB ;)

This tasks are very time consuming where one need to wait for SQL server response and complete the restoration process of such a huge database.

I thought that instead of doing this restoration from SQL Server management studio, let’s try with SQL query.

I found a great script on http://blog.sqlauthority.com/ .

There are 4 steps involved with this restoration query

1. Find the Logical name of data and log file from database backup file

RESTORE FILELISTONLY FROM DISK = 'D:\Backup\TestSitecore_Core_20160112014154.BAK'
GO

2. If you are going to restore on existing database, then run below query for making database to single user mode. If you are going to restore as a new database then skip this query 

-- Restore to an existing database
-- Make Database to single user Mode
ALTER DATABASE TestCoreDB1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE

 3. This is the main query which restore below CORE database.

-- Restore Database
RESTORE DATABASE TestCoreDB1
FROM DISK = N'D:\Backup\TestSitecore_Core_20160112014154.BAK'
WITH  REPLACE, RECOVERY, 
MOVE N'Sitecore.Core.Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\TestCoreDB1_01Aug.mdf', 
MOVE N'Sitecore.Core.Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\TestCoreDB1_01Aug.ldf'
GO

Where Sitecore.Core.Data and Sitecore.Core.Log is the logical name returned by first query.

4. Skip this query if you have restored file for a new database or if no error occurred in step 3.

Run this query only if your database goes into single user mode or any error occurred. This query will set the database on multi user mode.

/*If there is no error in statement before database will be in multiuser
mode. If error occurs please execute following command it will convert database in multi user.*/
ALTER DATABASE TestCoreDB1 SET MULTI_USER
GO

That’s it. This script make my life easy and in all DEV, QA and UAT environment, every time I just need to change the database name and backup file path. Rest of the things are taking care by script.

Knowledge of SQL server and its trick can make Sitecore guy and of course gals life easy.

Please leave your comments or share this trick if it’s useful for you.

Monday, August 1, 2016

How to monitor and generate report of different server activities



You need to monitor servers of your hosting environment. 

Especially in production environment you want to monitor website hosted server, database server, SOLR server, manogoDB server or any other server.

You may need to generate and mail daily utilization reports of these servers to client or technical team.

So what are the ways to monitor your server activities?

Solution: 

OpManager is great tool to monitor activities of your servers. There are lots of features provided by OpManager tool.

One such feature is to generate different type of reports like Daily, monthly Server Memory Utilization report etc.

This article covers step to generate different reports from OpManager

·         Login to system where OpManager is installed
·         Double click shortcut icon “ManageEngine OpManager” from Desktop or get it from Start menu
·         This open http://localhost:9000/ webpage in browser. In our case Opmanager is running as local site on port number 9000
·         Login to site
·         Click on Reports located at bottom left side of webpage as marked in red rectangle in below image
·         Opmanager provides different default report as per industry needs
·         Choose one of the report category like "Health and Performance" link as marked in red rectangle in below image
·         Mostly we need to generate and share report with client such as Devices by CPU utilization, Devices by Memory utilization, Devices by Disk utilization etc.
·         Click on any one of the available report type such as "Device by CPU utilization" link as marked in red rectangle in below image





·         Click on “Edit Report” button
·         You can choose different option from Edit Report window such as devices category, period, time window etc. Choose below option for generating monthly report





·         Click on Show Report button.
·         You can Export generated report to PDF, excel etc.
 
Please leave your comments or share this tip if it’s useful for you.