-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.sh
executable file
·69 lines (63 loc) · 2.23 KB
/
save.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
if [ "$JAVA_HOME" = "" ]
then
echo "ERROR: JAVA_HOME is not set" >&2
exit 1
fi
export PATH=$JAVA_HOME/bin:$PATH
[ "$TOMCAT_ROOT" = "" ] && TOMCAT_ROOT=$(dirname $0)
TOMCAT_ROOT=$(realpath $TOMCAT_ROOT)
echo "Tomcat root: $TOMCAT_ROOT"
export JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"
DB_DIR=$TOMCAT_ROOT/webapps/${TOMCAT_WEBAPP:-ROOT}/WEB-INF/db
if [ ! -d $DB_DIR ]
then
echo "ERROR: No database directory ($DB_DIR)" >&2
exit 2
elif [ ! -w $DB_DIR ]
then
echo "ERROR: Database directory is not writable ($DB_DIR)" >&2
exit 3
fi
[ "$DB_VENDOR" = "" ] && DB_VENDOR=hsqldb
[ "$DB_VENDOR" = "mariadb" ] && DB_VENDOR=mysql
[ "$DB_VENDOR" = "pgsql" -o "$DB_VENDOR" = "postgres" ] && DB_VENDOR=postgresql
[ "$DB_VENDOR" = "sqlserver" ] && DB_VENDOR=mssql
echo "Database vendor: $DB_VENDOR"
if [ $DB_VENDOR = "mysql" ]
then
echo "HSQLDB database: Embedded"
# Nothing to do
exit 0
elif [ $DB_VENDOR = "mysql" ]
then
[ "$DB_HOST" = "" ] && DB_HOST=127.0.0.1
[ "$DB_PORT" = "" ] && DB_PORT=3306
echo "MySQL database: $DB_HOST / $DB_PORT / $DB_NAME / $DB_USER"
mysqldump --host=$DB_HOST --port=$DB_PORT --user=$DB_USER --password=$DB_PASSWORD $DB_NAME > $DB_DIR/simplicite-mysql.dmp
exit $?
elif [ $DB_VENDOR = "postgresql" ]
then
[ "$DB_HOST" = "" ] && DB_HOST=127.0.0.1
[ "$DB_PORT" = "" ] && DB_PORT=5432
echo "PostgreSQL database: $DB_HOST / $DB_PORT / $DB_NAME / $DB_USER"
PGPASSWORD=$DB_PASSWORD pg_dump -h $DB_HOST -p $DB_PORT -U $DB_USER $DB_NAME --no-owner --clean > $DB_DIR/simplicite-postgresql.dmp
exit $?
elif [ $DB_VENDOR = "oracle" ]
then
[ "$DB_HOST" = "" ] && DB_HOST=127.0.0.1
[ "$DB_PORT" = "" ] && DB_PORT=1521
echo "Oracle database: $DB_HOST / $DB_PORT / $DB_NAME / $DB_USER"
exp $DB_USER/$DB_PASSWORD@//$DB_HOST:$DB_PORT/$DB_NAME file=$DB_DIR/simplicite-oracle.dmp log=$DB_DIR/simplicite-oracle.log owner=$DB_USER
exit $?
elif [ $DB_VENDOR = "mssql" ]
then
[ "$DB_HOST" = "" ] && DB_HOST=127.0.0.1
[ "$DB_PORT" = "" ] && DB_PORT=1433
echo "SQLServer database: $DB_HOST / $DB_PORT / $DB_NAME / $DB_USER"
sqlcmd -S $DB_HOST,$DB_PORT -U $DB_USER -P $DB_PASSWORD -b -Q "backup database $DB_NAME to disk='$DB_DIR/simplicite-mssql.dmp' with no_log"
exit $?
else
echo "ERROR: Unknown database vendor ($DB_VENDOR)" >&2
exit 4
fi