Skip to main content
Trans Am

Todd Klindt's SharePoint Admin Blog

Go Search
Home
Blog
Netcast homepage
SharePoint Terminology Wiki
  

Todd Klindt's home page > Todd Klindt's SharePoint Admin Blog > Posts > Saving multiple STSADM backups
Saving multiple STSADM backups

A reader asked in a comment how to script STSADM backups and be able to keep multiple copies. He's using a command like this:

Stsadm.exe –o backup –url http://www.toddklindt.com –filename tk.stsadm -overwrite

Or

Stsadm.exe –o export –url http://www.toddklindt.com/blog -filename tk-blog.cmp –overwrite

 

He wants to keep more than one instance of the backups, in case someone deletes something and they don't get back to you right away. I have a great way to work around this. Windows has an environment variable that is equal to the date. We can start with this. It's not in a good format, so we'll have to tweak it some:

For one, the backslashes will cause us problems in the file system. Second, leading with the day of the week will not sort very well. What we want is something along the lines of YYMMDD. Fortunately there is a way to parse through variables to get snippets of the information. While this is documented in the SET command, it works fine without it. To get the full skinny type set /? at a Command Prompt to get the full usage. Set has a lot of usage, but here's the part we care about:

We can use this approach to pull out the parts of the %date% variable that we want. Here's what the command would look like:

 

The string "%date:~-2%%date:~4,2%%date:~7,2%" turns into YYMMDD. The first part "%date:~-2%" says 'start at the end and take the last two characters.' The next part, "%date:~4,2%" says 'skip the first four characters and give me the next 2'. The last part, "%date:~7,2%" says 'skip the first seven characters and give me the next 2.' You put all that together and you get YYMMDD. Now just couple that with your STSADM command and you're all set. It would look something like this:

 

I included a filename with spaces to demonstrate how to take care of that. Pretty slick, huh? I can hear some people out there saying, "That's great, but now my drive is going to get full of backups. Some help you turned out to be!" Settle down, I've got the fix for that too. Another built in command FORFILES will fix that right up. Add the following line to your scheduled script:

forfiles /d -7 /m *.stsadm /c "cmd /c del @file"

That command will delete all files that end in .stsadm that are more than seven days old. Now you can keep exactly as many backups of your sites or webs as you want.

Handy?

Thanks to the reader that asked.

tk

 

 

 

Comments

Cool

FO V2 that's all you can do.
For V3 you can use the new stsadm -o backup extension -backuptype full which automagically creates a unique directory structure for each backup
In addition it runs amazingly/blazingly fast and does a mich more granular lock
Our 5-8 hour backup window shrunk to 20 minutes
at 6/4/2008 9:38 PM

Re: Cool

You bring up a couple of good points.  These techniques work for both 2003 and 2007 versions of SharePoint.   Both versions of STSADM support the backup operation.  This technique will also work with the export operation in SharePoint 2007.

SharePoint 2007 adds a new twist to the backup operation.  It supports the usual -filename parameter and it added a new one -directory.  The -filename backups are site collection backups.  The -directory backups are farm level backups.    They're running faster for you because they are doing database dumps directly from the database.  The -filename backups are going through the Object Model and are site collection level.  They're two completely different deals.

Do -filename backups for content recovery.  Do -directory backups for server or farm recovery.

tk
Todd O. Klindt at 6/4/2008 10:25 PM

In Powershell

I put together a powershell script to do something similar.  You can find it and a powershell 'warm up' script at www.mylocalbroadband.com/documentation/home.aspx .
at 6/5/2008 9:46 AM

Powershell here as well

I also made a PowerShell script to do this same thing - I keep a week's worth of backups locally, with the rest being moved to tape and offsite. Also, another handy thing I do is backing up different levels of granularity - so I backup the root site collection, then start iterating down into the subwebs, back up those, and so on. So I end up with a directory structure like this:

06.05.08/root
06.05.08/root/subweb1
06.05.08/root/subweb2
06.05.08/root/subweb2/subweb3

That way at any point I can grab whatever level I need to. Not best for space considerations, of course, but hard drive space is cheap. Unsatisfied end users aren't. :)
at 6/6/2008 9:01 AM

Re: Powershell here as well

Feel free to post a link here.  If you don't have a place to post it let me know and I can host it.   I'm sure others would love to see it.

tk
Todd Klindt at 6/6/2008 6:30 PM

Nice addition to Batch jobs

Thanks for the pointers.
at 6/16/2008 8:11 AM

mod for YYYYMMDD

This is great.  I wrote a fairly complex vb/wsh script to do the same thing, but I like this much better.  Easier to implement and maintain.  One line, I love it!
For those of us who hate 2 char years, and for times when the date is 08/08/08, I prefer 4 character years.  So for anyone who sees this and they can't figure out how to get YYYYMMDD, here it is:
echo %date:~-4%%date:~4,2%%date:~7,2%
returns:
20080813

-Steve
at 8/13/2008 6:05 PM

Re: mod for YYYYMMDD

Steve,
Glad to hear it helped.  That's always good to hear.

tk
Todd Klindt at 8/13/2008 6:31 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Please enter today's date so I know you are a real person
Attachments