devxlogo

SharePoint Applied—Stsadm Is Your Friend

SharePoint Applied—Stsadm Is Your Friend

n this article, I’ll introduce you to my best friend in SharePoint land, Stsadm.exe. No, this article is not a reference on Stsadm, neither is it an introduction to SharePoint. Instead, I introduce you to a few neat tricks using Stsadm that I like to keep in my back pocket.

Managing Sites and Site Collections
SharePoint organizes its data in sites and site collections. When you design a site for a client, you must evaluate a number of pros and cons as you choose between a site and a site collection for a particular set of data. Irrespective of what you picked, you’ll encounter times where you wished you had picked the other. Or sometimes, you just need to shuffle or move things around because the requirements changed, the databases grew, or any other reason. Stsadm is incredibly helpful in such scenarios.

You may backup a site collection using the following command:

   stsadm -o backup -url     -filename 

Similarly, you may restore a site collection using the following command:

   stsadm -o restore -url     -filename 
When you import and export single sites, you need to pay extra attention to site GUID identifiers and versions of items/documents in the site.

Now note that I mentioned “site collection” and not site. In order to backup a site, you may use the following command:

   stsadm -o export -url     -filename 

Similarly, in order to import a site you may use the following command:

   stsadm -o export -url     -filename 

To import and export single sites need you to pay extra attention to site GUID identifiers, and the versions of items/documents in the site.

Now, this brings up some interesting permutations and combinations. Using the preceding commmands, you could:

  • Move site collections to/from servers, or within the same website.
  • Move sites up or down in the hierarchy of a site collection.
  • Convert a site into a site collection.

Now, why would you ever want to convert a site into a site collection? Because, you cannot split a site collection between multiple content databases, and sometimes content databases get too huge to manage. As it turns out, Stsadm can also help you manage your content databases.

Managing Content Databases
Sometimes you might land in a project where you have a content database that is bursting its seams. Usually, when a content database grows to over 50GB, a SharePoint architect’s warning lights should turn yellow. If it crosses 200GB for high I/O sites, or 500GB for read-only sites, the warning lights should glow red. Note that you can tweak these soft limits beyond the numbers I mentioned, but?sooner or later?you’ll have to face the problem of taking an existing website with numerous sites or site collections, and splitting them up into manageable chunks containing separate content databases.

To do so, use the following command to force the creation of a new site collection in a new content database:

   stsadm -o createsiteinnewdb    -url     -owneremail     -ownerlogin     -databasename 

After running the preceding command successfully, you may verify under Central Administration ? Application Management ? Content Databases that a new content database has indeed been added, and that the single site collection specified in the preceding code was created.

You can use the following sequence of commands to move a site collection from to :

   stsadm -o backup -url     -filename    stsadm -o deletesite -url    stsadm -o restore -url     -filename  -overwrite

As you can see, the commands back up the site from the old URL, delete it, and then restore it at the new URL, which exists in a new content database. You accomplished all this with only a few lines using Stsadm, which supports a number of other commands that let you work with content databases. I recommend that you read the MOSS SDK to get more detail about the various possibilities.

Speeding Up Your Development
If only I had a penny for every second spent in front of the SharePoint spinner. It’s true! I spend a lot of my life watching progress bars. For instance, the “my retirement” application has been stuck at two percent for a very long time now. I use Stsadm to help speed up my development in two main ways: Autopilot Mode and Time-Squishing Mode.

Autopilot Mode
While Stsadm won’t speed up SharePoint, it will let you script common and repetitive tasks so you can execute a command and then go grab a cup of coffee while the command executes.

For example, the following sequence of commands deletes whatever I have done on a given URL, and recreates the application and site for me based on an out-of-the-box template:

   stsadm -o deletesite -url    stsadm -o createsite -url     -owneremail     -ownerlogin     -sitetemplate 

I know what you’re thinking! What good is the above sequence of commands if the starting point always has to be one of the built-in site definitions?

Well, whenever I am ready to save a snapshot of my work that I’d like to revert to frequently, I export it as a site template. Then I use stsadm -o addtemplate to add that to a site on a different port. Finally, I use some backup/restore wizardry, all via Stsadm, to revert the site right back to the snapshot after running the preceding script. I leave it up to you to write such a script. You might ask, why not just use backup and restore? Well, sometimes I’d rather see my custom features deployed, just as I would deploy them in production, so I tend to script out Stsadm, just as if I were running it in production.

As I mentioned, this doesn’t speed up SharePoint, but while this script runs, it gives me an opportunity to feverishly check my email and see if I won any Internet lotteries. Maybe that will bump my retirement progress bar a bit?

Time-Squishing Mode
Frequently I find myself writing code or developing functionality against some timer job within SharePoint that runs every few minutes?or worse, every few days or longer. I could keep twiddling with the system date and time to kick the job in, but my virtual machines like to sync their local time with the host time. If I changed both my host time and the virtual machine time, my emails would confuse my co-workers, because I’d end up sending an email without fixing my system time.

Luckily, I found a mechanism to squish time. Well, not quite, but I did find a way to squish such timer jobs to a schedule that runs every few minutes. You can find a generic way of squishing time for any service/job posted on my blog.

However, if all you need to do is to change the schedule of information management policy to minutes, instead of running it daily, you could use the following Stsadm command:

   stsadm -o setpolicyschedule -schedule   "every 1 minutes between 0 and 59"

Now the information management policy will run every minute, so you can test your settings without waiting until tomorrow or changing the date/time manually. Similarly, if you wish to change the frequency at which SharePoint sends alerts from every five minutes to one minute, you could use the following Stsadm command:

   stsadm -o setproperty -propertyname    job-immediate-alerts -url  -   propertyvalue "every 1 minutes    between 0 and 59"

Feel free to explore what other properties exist and how you can use them.

Writing Custom Stsadm Commands
Last but not least, while Stsadm has been around for a while, SharePoint 2007 comes with a number of new Stsadm commands. While Stsadm won’t do everything you need it to out of the box, you can extend it by writing custom operations. You can find further details here.

Conclusion
I hope you enjoyed meeting my best friend in SharePoint land, the Stsadm.exe command. This article didn’t even scratch the surface of the Stsadm iceberg; you can use Stsadm for much more. For example, you could ease deployment pains by packing your code in features, and activating them via the command line. You could deploy your code as solutions. Or you could manage your shared service providers. I highly encourage you to check out Stsadm.exe?it will definitely make your life with SharePoint simpler.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist