Pages

Tuesday, January 23, 2018

All Power shell Backup Commands for SharePoint Site


Backup Site Collection

Backup -SPSite http://spuat/sites/SG -Path C:\Backup\SGSite.bak

Restore Site Collection

Restore-SPSite http://spuat:222/sites/SG  -Path C:\Backup\SGSite.bak -Force

Monday, January 8, 2018

Truncate WSS_Logging MDF and LDF database in the Sharepoint Server

we try to access our SharePoint site and notice that site does not load and instead throws an error. 
we investigate the error and find out that it has something to do with the WSS_Logging database when check WSS_LOGGIN MDF file size has more than 100 GB out of 120 GB Disk space. 
It is a common problem and If you are facing this type of issue, truncate your WSS_Logging DB and you should be follow in the below steps:

1.       Open your SQL UI. Right click WSS_Logging DB and go to Reports > Disk Usage OR Reports > Standard Reports > Disk Usage.

Figure 1: Disk Usage

2.       In the disk usage report, expand the second node to see current disk usage. It should be full.



3.       Right-click WSS_Logging B and select “New Query” and paste the following script in the window and then hit F5 to execute it. NOTE: This script was copied from the following link:


Script:

·         DECLARE @TableName AS VARCHAR(MAX)
DECLARE table_cursor CURSOR
FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_NAME LIKE '%_Partition%'
OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @SQLText AS NVARCHAR(4000)

SET @SQLText = 'TRUNCATE TABLE ' + @TableName

EXEC sp_executeSQL @SQLText

FETCH NEXT FROM table_cursor INTO @TableName
END
CLOSE table_cursor
DEALLOCATE table_cursor


Different people have written different scripts to truncate the table. This one is a tested solution and works perfectly.

4.       After executing the query, go back to the disk usage report and now you should see that the database is empty. Open your SharePoint site and it should work.


After that we shrink MDF files from SQL Server management studio then WSS Logging MDF files has reduced disk size and which is working fine and tested in my environment.