.bat Scripted Content Backups in CQ 5.x

December 7, 2010

Here’s just a trivial bit of script that builds a defined content package and pulls it from the server.

The curl part is pretty easy and didn’t take much after a brief look in Firebug (although I do miss a “copy as curl command” content menu entry in Firebug’s net panel ;-).

What was harder was to find a way to put a timestamp into a filename in a windows .bat file. I’m sure there are smarter ways to do this (including but not limited to installing bash ;-), but here’s what I came up with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Rem set group and package name as in package manager
Set GROUP=packagegroup
Set PACKAGE=packagename
Set HOST=hostname
 
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP
 
DATE /T > %CURRDATE%
TIME /T > %CURRTIME%
 
Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j
 
Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

Rem -k is only needed if you have a self-signed cert
curl -k -u admin:admin -o backup-%YYYYMMDD%%HHMM%.html -F cmd=build https://%HOST%/etc/packages/%GROUP%/%PACKAGE%.zip/jcr:content.console.html
curl -k -u admin:admin -o backup-%YYYYMMDD%%HHMM%.zip https://%HOST%/etc/packages/%GROUP%/%PACKAGE%.zip.res/%PACKAGE%.zip

Tags