Sunday, June 27, 2010

Backing up SQL Server database files on to a samba shared network folder

Recently i encountered a sitution where we need to take a back up of existing sqlserver and restore it elsewhere. So i immeditely logged on to the server for checking the sie of the existing db files and my jaw dropped looking at the size! Its over 300 gigs. Yeah you guessed it right, the server is not having that much space for taking the backup. 


Immediately i tried for getting a new drive to the box and as usually it is going to take time. But i came to know that there is some 500 gigs of space available on a linux box which i can use temporarily. Great i immediately created a samba share on the linux box and tested the same on the production box for accessibility. Successfully accessed the share with the provided credentials, mapped the drive as z: drive on my server box. 
Started the sql server enterprise manger and open the backup dialog only to find that my Z: was not listed in there!! What's happening? The sad news is sql server does not support network folders as database storage folders. Great! now what to do...? ... That's exactly what i did, again went back to google with more queries. At last, i found that this can be achieved using some under documented features of sql-server. This is how we do it. 


Disclaimer ;) : Using a network folder for storing backups is not supported and there is a good chance of corrupted db files[From MSDN]. 


First of all, there are a set of trace flags which were present in sql server that we need to configure. I used only the flag 1807 for this purpose. 


DBCC TRACESTATUS 


Execute the above sql statement and you should get a results with three coulmns, with the status of configured trace flags on global, and session level's. 


Now, how to turn on that flag? 


DBCC TRACEON( 1807 ) to turn this on for session 


DBCC TRACEON( 1807 , -1) to turn this on globally. 


Once checked the status of the same using tracestatus command, i proceeded to take the backup. Still not working! My mapped network drive is not coming in the list, so i tried by typing in the path directly, that also didn't work. Then tried by giving the UNC folder path, even that also failed. 


Back to MSDN and i found out why, at the very end of the doc there is a suggesstion saying that the trace flags will work better if set as one of the startup parameter using -T option. Great, now i need to restart my db server twice. (but it seems that we need to configure this particular flag as startup param) 


After setting the startup param in the sql server configuratiom utility i restarted the server and issued the tracestatus command, and surprise the flag was set globally now! 


Okay i proceeded to do backup now and still my mapped drive is not showing up in the file browser!. Okay, i tried by directly typing in the UNC path. Still no luck! Arrrgg. What should i do? As per MSDN everything is setup and fine. 


After re-reviewing the whole setup the only thing that was looking odd is the shared folder itself. The share is on a linux box as a samba share (not a windows share), and it requires credentials! Wait a minute, though we already mapped the drive in explorer using credentials the sql server might not be using them. So went back to linux, made the share accessible to everyone (what? To everyone? That's ridiculous. I was going to copy a production db backup on to a drive accessible to everyone? Yeah, but what to do? No other quick option available now, so just made sure that the subnet is not being used by any one at that time by fiddling with the router firewall settings.) Now that's done, i have deleted the already mapped drive and re-mapped the same with out suppling the credentials. It worked. Immediately i tried the backup process and it worked!!!! Finally i was able to backup on to a linux shared folder using sql server. 


So in brief the steps are 


1. Set up a share with public access (Need to check if a windows share with credentials is having any issues)
2. Open the sql server config utility and add the startup parameter ;-T1807 
3. Restart the SQL Server 
4. Check the status of the flag using DBCC TRACESTATUS, it should show 1 for global. 
5. Do the backup by supplying the full UNC path in the destination folder. 
6. Open the sql server config utility and remove the trace flag parameter. 


Now that we have backedup the db on to share it is recommended to restore the backup from the shared folder and check for any corruption issues. 


Sql server does support a shared folder. But SQL Server supports provided that we install a SQL server certified storage driver which in-turn accesses the shared folder. Now obviously that will not come for free. 


Comments, opinions, suggesstions are welcome. 

Sunday, June 13, 2010

Better WTP dynamic project with FileSync

I have been working with eclipse WTP for quite some time for now. But all the time i have been working with small projects implementing some POC's etc. But recently i was confronted with the task of doing the same for a BIG project with some thousands of various types of resources including scripts, jsps, images, xmls, htmls, css and others. The source base is also having thousands of classes. After successfully configuring the WTP project for this new Big boy. As soon as i started the wtp server in eclipse, The Server immediately started the process of publishing the entire project to the deployment folder! It took good 5 minutes to copy the entire structure on my average desktop!.  Okay! i thought and once the server started i placed a set of break points and changed a single line of code and hit the save, in just 2 seconds or so again the process of publishing the entire project started!!! And after that my eclipse started dragging with the load of extra memory.

So the server is publishing the entire project structure with out simply publishing the resources that were changed! and that too everytime!! This is not fair! the WTP should be copying only the differentials rather than the entire project once we change any thing in the project. If this is a small project it might not have taken time at all, but being a Big project it is taking a lot of time :(

So we need to have a intelligent mechanism of copying only the differentials, stop the server from automatically publishing when ever there is a change to the project. And finally we need to manually sync the changes to the deployment folder and start the server for further debugging.

So i after googling around, i found the FileSync plugin which will do a sync of a given source folder in the project to a selected folder on the filesystem.

Finally here is my setup. Install the FileSync plugin first!!! Do everything i mean adding a new server runtime. Do not add the project now. Open the server runtime settings first and change a couple of settings. Set the option to "Never publish automatically." Next select the option to "Use custom location" and browse to a folder. The server will create the wtpwebapps folder underneath this folder. Next under server options select the options "Serve modules with out publishing". Once that's done, go to project properties and set the File Synchronization plugin properties setting the target folder as the new wtpwebapps\ folder and save.
From then on just a "Force File Sync" on the project before starting the project is doing for me.

If the WTP simply does a differential copy/sync i would not do all this stuff. Need to explore further if there is a way to fire the force file sync whenever we start the server :)

Monday, May 31, 2010

Eclipse console!

Recently while I was working on some eclipse plugin project,i came to know about a couple of commands and features of eclipse which helped me in fixing the problem in matter of 15 min, before which I have spent a couple of hours trying to find my way through the famous "Jar hell" problem.

The first thing that I came to know of is about an eclipse console! Where you can issue commands to eclipse for querying the status of any loaded plugin, logging done by eclipse itself during its run, etc.

Okay now how do we open the eclipse console? 

Simple, pass the command line options "console" to the eclipse executable. Open a command prompt, navigate to the eclipse folder and issue the following command

eclipse -console

Now you can see a new command prompt like window opened along with the eclipse splash screen with a "osgi>" prompt and cursor!!

Next command line option is "consolelog", start eclipse with this option and you can see the logging done by the eclipse plugins if any. Most of the times this will show you any stack traces of any errors which might occur with out your knowledge. 

You can sepcify both -console and -consolelog to get both the console along with logging. 

Next command line option is "clean", start eclipse with this option to start the eclipse by clearing all the temprary information that was saved by all the plugins. This will prevent any issues/errors caused due to the temporary cache that was being maintained by the eclipse plugins.

Let us look at a couple of commands which you can issue in the eclipse console itself.
First command is "ss" which stands for "short status". This command will print a lot of information about all the plugins that were present in the current installation along with their status if they were resolved or not.

Next command "packages ". This will print all the references of the where it is found in the classpath along with the version of the jar class. The listing will denote the exact lookup path of the class that eclipse will provide for loading the classes of . This list will help in checking to see if the required class is being loaded from the desired jar.

Next command "bundles ". This will print all the references of the plugins that were providing the package name.