I have tweaked a quick backup method over several development projects. This is the current iteration, and works well for my needs in both WSS and MOSS:
@set spSite=http://wss01
@set spPort=7022
@set FileNamePrefix=GFam
@set targetPath=C:\Projects\GFam\Backup
@set targetPath2=\\tsclient\C\Dox\Dev\GFam\Backup
@set MONTH=%DATE:~4,2%
@set DAY=%DATE:~7,2%
@set YEAR=%DATE:~12,2%
@set FileName=%targetPath%%FileNamePrefix%%spPort%_%YEAR%%MONTH%%DAY%.bak
@set spURL=%spSite%:%spPort%
c:
cd "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"
Stsadm -o backup -url %spURL% -filename %FileName% -overwrite
@if "%targetPath2%"=="" goto finish
copy %FileName% %targetPath2%
:finish
pause
This creates a file named something like GFam7022_080718.bak, based on the parameters at the top and the current date. The params are
- spSite – This is the domain of the SharePoint site
- spPort – This is the port. If the URL does not need a port number, use 80 here.
- FileNamePrefix [optional] – A prefix can be a handy way quickly identifying the source site when browsing backup files.
- targetPath – This is where the file is backed up to. It needs a closing backslash "\"
- targetPath2 [optional] – I am nearly always RDP'ed into a server for development, and sometimes I find it useful to copy the backup file to my local machine. This could also be a file share or whatever.
To restore, use command line stsadm from in the 12-hive, e.g.,
Stsadm -o restore -url http://gfam.com:7022 -filename C:\backups\GFam7022_080718.bak –overwrite
Possible improvements
- Instead of copying to targetPath2, set up a command-line FTP. I currently FTP the backup to the production server by hand, but pretty soon we'll go completely live on the server after. I wonder if it is possible to use \\tsclient\c\... to point back to the local machine for an input file to keep the login off the server, e.g.,
ftp -s://tsclient/c/dox/ftpLogin.in ftp.gfam.com
- Currently, I just create a new batch file for each new project. I suppose I could parameterize it, and call a single instance of this batch file from another batch file, something like
call spBackup http://wss01 7022 GFam ...
- Omit the "http://" from spSite, and default FileNamePrefix to its value.