root/trunk/deployment/dumprestore/shellscr/resources/dumpres.bat

Revision 1325 (checked in by johnsa, 6 years ago)

fixed up windows dump/restore bat file

Line 
1 :: Run the bedework dump/restore program
2 :: First arg defines the action, dump, restore etc
3 :: Second arg should be the filename
4
5 :: JAVA_HOME needs to be defined
6
7 @echo off
8 setlocal
9
10 if not "%JAVA_HOME%"=="" goto noJavaWarn
11 ECHO
12 ECHO
13 ECHO ***************************************************************************
14 ECHO          Warning: JAVA_HOME is not set - results unpredictable
15 ECHO ***************************************************************************
16 ECHO
17 ECHO
18 :noJavaWarn
19
20 SET cp=@CP@
21
22 SET DUMPCMD="%JAVA_HOME%/bin/java" -cp %cp% @DUMP-CLASS@
23 SET RESTORECMD="%JAVA_HOME%/bin/java" -cp %cp% @RESTORE-CLASS@
24 SET SCHEMACMD="%JAVA_HOME%/bin/java" -cp %cp% org.hibernate.tool.hbm2ddl.SchemaExport
25
26 SET APPNAME=@BW-APP-NAME@
27
28 ECHO.
29 ECHO.
30 ECHO   Bedework Database Tools
31 ECHO   -----------------------
32 ECHO.
33
34 :branch
35   if "%1" == "dump" GOTO dump
36   if "%1" == "restore" GOTO restore
37   if "%1" == "restore-for-quickstart" GOTO restore-for-quickstart
38   if "%1" == "backup" GOTO backup
39   if "%1" == "initdb" GOTO initdb
40   if "%1" == "drop" GOTO drop
41   if "%1" == "drop-export" GOTO drop-export
42   if "%1" == "schema" GOTO schema
43   if "%1" == "schema-export" GOTO schema-export
44
45 :usage
46   ECHO   Usage:
47   ECHO.
48   ECHO     schema-export [--haltonerror]
49   ECHO        Create a schema from the xml schema.
50   ECHO        Also create the database tables, indexes etc.
51   ECHO.
52   ECHO     initdb [--indexroot={lucene-index-root}]
53   ECHO        Populate the database using the provided initial data.
54   ECHO.
55   ECHO     dump {filename}
56   ECHO        Dump the database in xml format suitable for restore.
57   ECHO.
58   ECHO     restore {filename}
59   ECHO        Restore the database from an xml formatted dump.
60   ECHO.
61   ECHO     backup {directory} {prefix}
62   ECHO        Dump the database in xml format suitable for restore.
63   ECHO        Files will have a name built from the prefix and the current date/time.
64   ECHO.
65   ECHO     drop [--haltonerror]
66   ECHO        Create a file in the current directory with sql drop statements
67   ECHO.
68   ECHO     drop-export [--haltonerror]
69   ECHO        Drop tables in the database. Note this may not work if the schema
70   ECHO        was changed.
71   ECHO.
72   ECHO     schema [--haltonerror]
73   ECHO        Create a schema from the xml schema. Placed in a file in the
74   ECHO        current directory
75   ECHO.
76
77   GOTO end
78
79
80 :dump
81   ECHO   Dumping data:
82   ECHO.
83   ECHO   %DUMPCMD% -appname %APPNAME% -f %2 %3 %4 %5 %6 %7 %8 %9
84   %DUMPCMD% -appname %APPNAME% -f %2 %3 %4 %5 %6 %7 %8 %9
85   GOTO end
86   ::
87 :restore
88   ECHO   Restoring data:
89   ECHO.
90   ECHO   %RESTORECMD% -appname %APPNAME% -f %2 %3 %4 %5 %6 %7 %8 %9
91   %RESTORECMD% -appname %APPNAME% -f %2 %3 %4 %5 %6 %7 %8 %9
92   GOTO end
93   ::
94 :restore-for-quickstart
95   ECHO   Restoring data for quickstart:
96   ECHO.
97   ECHO   %RESTORECMD% -appname %APPNAME% -onlyusers "public-user,caladmin,douglm,agrp_*" -f %2 %3 %4 %5 %6 %7 %8 %9
98   %RESTORECMD% -appname %APPNAME% -onlyusers "public-user,caladmin,douglm,agrp_*" -f %2 %3 %4 %5 %6 %7 %8 %9
99   GOTO end
100   ::
101 :backup
102   :: first strip out delimeters from date and time
103   echo %date% > temp.txt
104   for /f "tokens=1-4 delims=/ " %%a in (temp.txt) do (
105     set dname=%%a
106     set mm=%%b
107     set dd=%%c
108     set yy=%%d
109   )
110   echo %time% > temp.txt
111   for /f "tokens=1-3 delims=: " %%a in (temp.txt) do (
112     set hh=%%a
113     set mn=%%b
114     set ss=%%c
115   )
116   echo %hh%%mn%%ss% > temp.txt
117   for /f "tokens=1-2 delims=. " %%a in (temp.txt) do (
118     set tm=%%a
119     set ms=%%b
120   )
121   SET TARGET=%2\%3%yy%%mm%%dd%_%tm%%ms%.xml
122
123   :: now backup the data
124   ECHO   Backing up data into:
125   ECHO   %TARGET%
126   ECHO.
127   ECHO   %DUMPCMD% -appname %APPNAME% -f %TARGET%
128   %DUMPCMD% -appname %APPNAME% -f %TARGET%
129   GOTO end
130   ::
131 :initdb
132   ECHO   Initializing the database:
133   ECHO.
134   ECHO   %RESTORECMD% -appname %APPNAME% -f ./data/initbedework.xml -initSyspars %2 %3 %4 %5 %6 %7 %8 %9
135   %RESTORECMD% -appname %APPNAME% -f ./data/initbedework.xml -initSyspars %2 %3 %4 %5 %6 %7 %8 %9
136   GOTO end
137   ::
138 :drop
139   ECHO   Creating drop sql
140   ECHO.
141   ECHO   %SCHEMACMD% --text --drop --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
142   %SCHEMACMD% --text --drop --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
143   GOTO end
144   ::
145 :drop-export
146   ECHO   Exporting drop sql:
147   ECHO.
148   ECHO   %SCHEMACMD% --drop --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
149   %SCHEMACMD% --drop --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
150   GOTO end
151   ::
152 :schema
153   ECHO   Creating the schema:
154   ECHO.
155   ECHO   %SCHEMACMD% --text --create --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
156   %SCHEMACMD% --text --create --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
157   GOTO end
158   ::
159 :schema-export
160   ECHO   Exporting the schema:
161   ECHO.
162   ECHO   %SCHEMACMD% --create --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
163   %SCHEMACMD% --create --format --delimiter="@SCHEMA-DELIMITER@" --config=./classes/hibernate.cfg.xml --output=schema.sql
164   GOTO end
165   ::
166
167 :end
168 ECHO.
169 ECHO.
Note: See TracBrowser for help on using the browser.