Backup and Restore with sitelock option
This is just a little FYI to save you some time. When you do a backup of your SharePoint site it is a good practice to use the stsadm command "setsitelock" so users aren't making changes that can corrupt the backup. While this is good you need to remember this when you are trying to restore your site. If you find yourself unable to access the site or add users, which are common actions when moving to a dev environment, then be sure to "unlock" your site. Here's some quick commands you can put in a batch file for backing up and restoring your sites. Have fun!
Backup.bat
@echo off
IF "%1" == "" goto err
IF "%2" == "" goto err2
setlocal
set SITE=%1
set FILENAME=%2
ECHO Backing up %SITE%
stsadm.exe -o setsitelock -url %SITE% -lock readonly
stsadm -o backup -url %SITE% -filename E:\BackupFiles\%FILENAME%
stsadm.exe -o setsitelock -url %SITE% -lock none
if not errorlevel 0 goto err
goto success
REM error message if no argument or site does not exist
:err
echo.
echo Site URL is required.
echo Here an example:
echo.
echo BackupSite.bat http://my.sharepoint.site site.bak
echo.
echo.
REM error message if no argument or site does not exist
:err2
echo.
echo Output file name is required.
echo Here an example:
echo.
echo BackupSite.bat http://my.sharepoint.site site.bak
echo.
echo.
:success
echo %SITE% backed up successfully
Restore.bat
@echo off
IF "%1" == "" goto err
IF "%2" == "" goto err2
setlocal
set SITE=%1
set FILENAME=%2
ECHO Restoring %SITE%
stsadm -o restore -url %SITE% -filename E:\RestoreFiles\%FILENAME% -overwrite
ECHO Unlocking %SITE%
stsadm.exe -o setsitelock -url %SITE% -lock none
if not errorlevel 0 goto err
goto success
REM error message if no argument or site does not exist
:err
echo.
echo Site URL is required.
echo Here an example:
echo.
echo RestoreSite.bat http://my.sharepoint.site site.bak
echo.
echo.
REM error message if no argument or site does not exist
:err2
echo.
echo Output file name is required.
echo Here an example:
echo.
echo RestoreSite.bat http://my.sharepoint.site site.bak
echo.
echo.
:success
echo %SITE% restored successfully
Update:
With the release of SP2 the site is automatically set to read-only so you don't need to include this in your batch file. However, if you don't want it to be set as read-only then you need to run the backup command with the -nositelock option.
Backup.bat
@echo off
IF "%1" == "" goto err
IF "%2" == "" goto err2
setlocal
set SITE=%1
set FILENAME=%2
ECHO Backing up %SITE%
stsadm.exe -o setsitelock -url %SITE% -lock readonly
stsadm -o backup -url %SITE% -filename E:\BackupFiles\%FILENAME%
stsadm.exe -o setsitelock -url %SITE% -lock none
if not errorlevel 0 goto err
goto success
REM error message if no argument or site does not exist
:err
echo.
echo Site URL is required.
echo Here an example:
echo.
echo BackupSite.bat http://my.sharepoint.site site.bak
echo.
echo.
REM error message if no argument or site does not exist
:err2
echo.
echo Output file name is required.
echo Here an example:
echo.
echo BackupSite.bat http://my.sharepoint.site site.bak
echo.
echo.
:success
echo %SITE% backed up successfully
Restore.bat
@echo off
IF "%1" == "" goto err
IF "%2" == "" goto err2
setlocal
set SITE=%1
set FILENAME=%2
ECHO Restoring %SITE%
stsadm -o restore -url %SITE% -filename E:\RestoreFiles\%FILENAME% -overwrite
ECHO Unlocking %SITE%
stsadm.exe -o setsitelock -url %SITE% -lock none
if not errorlevel 0 goto err
goto success
REM error message if no argument or site does not exist
:err
echo.
echo Site URL is required.
echo Here an example:
echo.
echo RestoreSite.bat http://my.sharepoint.site site.bak
echo.
echo.
REM error message if no argument or site does not exist
:err2
echo.
echo Output file name is required.
echo Here an example:
echo.
echo RestoreSite.bat http://my.sharepoint.site site.bak
echo.
echo.
:success
echo %SITE% restored successfully
Update:
With the release of SP2 the site is automatically set to read-only so you don't need to include this in your batch file. However, if you don't want it to be set as read-only then you need to run the backup command with the -nositelock option.
Comments