Showing posts with label Content Database. Show all posts
Showing posts with label Content Database. Show all posts

Monday, 9 November 2015

Why a Content DataBase is not cleaning the free space after Move-SPSite or Delete-SPSite?

Hi all,

I was faced to a full Database, and the quick-win solution, was to move some sites to another Database.

After making the list of the site collection present in the database, I found that the moved sites were no more present, as expexted.
But on the SQL side, the Database was still full…

I’ve asked our SQL Team to Shrink the Database, but nothing was changed.

Then, I’ve search why the space used by the moved sites was not cleared by the Timer Job.
Timer Job… The Gradual Site Delete timer job.

I’ve found why the Database didn’t change the free space after moving sites.
The timer job in SharePoint wasn’t correctly set.

After checking, the job supposed to be run automatically every day from 10PM to 6AM, but it wasn’t run.


Reason: start time is before end time. Seems that Microsoft logic is … special.

In the drop down list, the time for the timer job (same problem for all timer jobs in all SharePoint versions) start at 12AM and ends at 11PM.

The problem, is that by default, the Gradual Site Delete timer job is set as below: from 10PM to 6AM
This is quite logic for us (human), but I’ve the impression that the timer job doesn’t see the 6AM after 10PM in the drop-down list.
Also, I found that clicking on the “Run Now” button didn’t free the space in the concerned Database.


Thus, this default setting seems not allowing the Timer Job to run:




Solution: instead  of starting at 10PM, I’ve set it to start at 12AM
                                Now, no more red warning message.
                                And clicking on “Run Now” button is directly clearing the free space of all the                                      databases of my Web App.




So, I’ve had to check all my Gradual Site Delete timer job for each Web App I have.
Also, I found this problem to my SharePoint 2010 Farm and my brand new SharePoint 2013 Farms.


Hope this could help.



That’s all Folks


Wednesday, 8 June 2011

Move Sites from one Content Database to another


When a Content DB contains too many sites, we can script the migration process of the selected sites to be moved to another Content DB.

The purpose, is to reduce the number of sites from the DataBase1_site, and balance them between the 2 other DB, leaving Sharepoint the ability to distribute the sites on the DB's.

Step 1 :
First things first, the DataBase1_site Maximum Number of Sites is set to a lower limit (in this case, I divided by 2 the Warning and Number  - my choice)
This will leave Sharepoint to restore the sites to the lowest populated DB ( DataBase3_site in my case)

Step 2 :
Then, it's time to give some work to the SQL Team :
-          Full backup of the DataBase1_site as it is a customer requirement (and this time, I was happy to have it done !!! )

When backup is completed, I've locked all the sites that will be moved.

Then, time for SQL Team to do a differential backup of the DataBase1_site.


Step 3 :

I've written a .bat file with all those commands (according to the explanations of my SharePoint Guru), for each site that will be moved :

stsadm -o backup -url "http://<URL>/sites/<SiteToMove>" -filename "<SiteToMove>.bak"
stsadm -o setsitelock -url "http://<URL>/sites/<SiteToMove>" -lock none
stsadm -o deletesite -url "http:// <URL>/sites/<SiteToMove>"
stsadm -o restore -url "http:// <URL>/sites/POL_CONINO" -filename "<SiteToMove>.bak"
stsadm -o setsitelock -url "http:// <URL>/sites/<SiteToMove>" -lock none

1-      Backup:               Local backup to restore the site into to new DataBase
2-      SetSiteLock:      Unlock the site, or the DeleteSite will not be possible
3-      DeleteSite:        Delete the site from DataBase1_site
4-      Restore:              Restore the deleted site into the allowed DataBase
5-      SetSiteLock:      Unlock the site, as the restore was made from the backup of a locked site

If all is correctly done, job is finish.


But …. In case of problem … as the backup command didn't succeed for any reason, the restore of the full DB is needed, and must be done on SQL side.

Step 4 :

Now, the restore of the DB is done by SQL Team, and we must add the Content DB to Sharepoint, then create a backup of the lost site.

I've wrote a little script that will do all step, with a little "pause" to check the restore of the lost site, before deleting the Backup DB from Sharepoint.
As the Backup DB contains exactly the same sites as the production DB, a new ID must be set to the Backup DB using the stsadm.exe parameter :  –assignnewdatabaseid .

You can find all the details to the Microsoft TechNet Site:



stsadm -o addcontentdb -url http://backupsitemove -assignnewdatabaseid -databasename xxxxxxxxxx1_Site -databaseserver SQLServer\InstanceName
stsadm -o backup -url http://backupsitemove/sites/<SiteName> -filename "<BackupPath>\Backup\<SiteName>.BAK"
stsadm -o restore -url http://<Destination _URL>/sites/<SiteName> -filename "<BackupPath>\Backup\<SiteName>.BAK"
pause
stsadm -o deletesite -url http://backupsitemove/sites/<SiteName>
stsadm -o unextendvs -url http://backupsitemove -deletecontent -deleteiissites
pause


The last command will delete the Database from SharePoint AND from the SQL Server if the used account is set as dbo of the Content DB.


Step 5 :

A full Cralw had to be done to refresh the Search engine.


Step 6 :

Take a deep breath, a coffee and be proud of your job done without losing any user's data.



Nb:  for the little story, I've done all this recovery for one site… that had its last modified document/folder set to 2009 …


That's all folks