I recently had to move a site collection from one MOSS 2007 Beta 2 server to a VPC for archiving purposes. Even though SharePoint now has an easy way to backup/restore through Central Admin, I found the easiest way to get everything working with control over the process was through the command line admin tool provided by SharePoint: stsadm.exe.

Before running these commands, make sure the SharePoint bin directory is in your path. The SharePoint bin directory is by default located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN.

To back up a site collection, run this command:

stsadm -o backup -url <url> -filename <filename>

where <url> is the url of your site collection and <filename> is the file you want to backup to.

To restore the site collection, run this command:

stsadm -o restore -url <url> -filename <filename> -overwrite

where <url> is the url you want to restore the backup into and <filename> is the backup file.

The -overwrite flag is used to overwrite the existing site if it already exists. However be careful that you don't overwrite an existing working site. You can always run the restore first without the -overwrite flag to determine if you need the overwrite flag. The command will let you know if an existing site is already located at the url you specified. During my testing, I restored a site in the wrong place with the overwrite flag completely killing the original site. Thankfully I backed up everything before I made any changes.

One thing to watch out for when you restore onto a different server is the security. During my first attempt, my user account was not admin of the site collection. Backup went without any problems, but restoring would fail midstream. Turns out the restore process restored the original security permissions to the site. Once authorization kicked in, my account failed the security check causing the entire restore process to fail with a half restored site. If this happens to you, edit the existing site so that you have the needed permissions to perform the backup/restore, then backup/restore again.

Another tip when using the stsadm command is to make sure you review exactly what data is being backed up. Remember the command backs up only the site collection, so anything outside of the site collection scope is not included. Typical data outside of the site collection that still may effect your site include:

  • Application settings in Central Admin
  • Shared Services settings (search scopes, audiences, excel services, ...)
  • Sub site collections

The last bullet is important to watch out for as I later found out that my original backup didn't include any sub site collections. Turns out personal sites (My Site for each user account) are sub site collections of the main site collection. If you just backup the main site collection for personal sites, this does not include any data of the sub site collections. You will have to backup those individually.