Tuesday, January 13, 2009

Backing up a single web application and a farm

Having a backup and restore plan seems to be the most critical piece of any MOSS implementation that is often overlooked. I can not stress how important it is to figure out a plan before doing any major changes in your farm. While, there is ample amount of documentation on doing this - Nothing goes and puts it in direct terms which can be used. For eg, why is the syntax to backup a web-application and a farm are the same or what do all those spbr folders mean.

First of all, the stsadm.exe operation has the same capability as your sharepoint UI tool. In fact, the ability to use scheduling with stsadm makes me rate it above everything else. First lets talk about backing up from the UI. Here you go in Central administration, browse to operations and then click "Perform a backup". You then select the components that you want to backup and proceed. You will be asked a directory name which you provide. The size that you see that will be needed for the backup is worst case scenario. You almost always will end up with a lesser size backup(I was shown a size of 171 Gb, but my full back up was done in 60 GB). After clicking on finish this will create a backup of the farm for you. (Given that you chose the entire farm earlier).

Lets go inside the backup directory. Here you will see directories named spbr0001, spbr0002 (if you have more than one) and so on. Each directory represents one backup\restore component that can be acted upon. If you go inside the spbr0001 directory you will see a number of *.bak files and an xml file. The bak files are backups of different components within the farm that you backed up. The xml file actually will contain a listing of the nodes that have been backed up and the corresponding nodes. For eg, the web app 1 was backed up as 00000006.bak and its content db was backed up as 000000007.bak. Each of the nodes also contain some tags - such as and . This has a value of true/false. False means that these items were not marked for backup and can not be restored as well from this particular spbr folder. True means that those particular nodes can be restored. For a full farm back up you will see true's. Whereas, if you selected only one webapplication for backup, you will see true against only that webapp and content DB node.

Ok. So how do you restore this farm/webapplication? Pretty simple actually, you just go to back up to Operations and select "restore from backup". Here you provide the directory name where you backed up your content. This for some reason lets you select only the last backup you took. If there is a way to workaround this, I would be interested to know.

So lets get to the stsadm piece. I feel we have more control over how this works and therefore prefer it. The first step is of course to decide what you want to back up. Imagine the tree structure in UI and the selectable nodes. If you can not then fire the command
stsadm -o backup -showtree
This will show you the tree structure on your stsadm console and mark the ones that can not be selected inside []. To execute a full back up of the farm you just execute this -
stsadm -o backup -directory -backupmethod full
To backup a single web application execute this script -
stsadm -o backup -directory -backupmethod full -item eg "sharepoint - 21897"
This will create a similar directory with an xml file. Only the nodes corresponding to the item mentioned will have true against SPCanBackUp and SPCanRestore.

This actually helps while restoring. So if you have a farm level backup done and you want a farm restore, you can do it using this -
stsadm -o restore -directory -restoremethod overwrite
If you have farm level back up and you want to restore only a particular item -
stsadm -o restore -directory -restoremethod overwrite -item
So you really can restore a single web-app from a farm level backup if you want.
But if you back up only a single web-app, you can restore only a single webapp even if you don't give the -item option to stsadm. All attributed to SPCanBackUp and SPCanRestore. While using restore, if you are scripting this for a batch job, dont forget to mention the -suppressprompt -username -password attributes to the restore cmd. Refer here if you want more details. And lest I forget, if your backup operation gets hung at about 50% of your search index while backing up your farm, go to Operations - Timer Job Definitions and kill that Search Back up and Restore item or try to find a permanent fix
here