6 scriptdir=$(dirname $0)
7 if [ -d "$scriptdir/../../src" ]
9 UTILS_PATH=$(cd $scriptdir/../../src ; pwd)
11 UTILS_PATH=$(cd $scriptdir/../.. ; pwd)
13 export PATH=$PATH:$UTILS_PATH/utils:$UTILS_PATH/bin
14 if type forge_get_config
16 database=`FUSIONFORGE_NO_PLUGINS=true forge_get_config database_name`
18 echo "$0: FATAL ERROR : COULD NOT FIND forge_get_config"
22 if [ "x$database" = "x" ]
24 echo "Forge database name not found"
27 echo "Forge database is $database"
30 echo "Stopping apache"
31 if type invoke-rc.d 2>/dev/null
33 invoke-rc.d apache2 stop
39 echo "select count(*) from users;" | su - postgres -c "psql $database" > /dev/null 2>&1
42 echo "Stopping the database"
43 if type invoke-rc.d 2>/dev/null
45 invoke-rc.d postgresql stop
47 service postgresql stop
50 echo "Waiting for database to be down..."
52 while [ $i -lt 10 ] && is_db_up ; do
53 echo "...not yet ($(date))..."
60 echo "... FAIL: database still up?"
65 echo "Starting the database"
66 if type invoke-rc.d 2>/dev/null
68 invoke-rc.d postgresql start
70 service postgresql start
73 echo "Waiting for database to be up..."
75 while [ $i -lt 10 ] && ! is_db_up ; do
76 echo "...not yet ($(date))..."
83 echo "... FAIL: database still down?"
86 echo "Dropping database $database"
87 su - postgres -c "dropdb -e $database"
91 echo "Restore database from dump file: psql -f- < /root/dump"
92 su - postgres -c "psql -f-" < /root/dump > /var/log/pg_restore.log 2>/var/log/pg_restore.err
94 # TODO: reinit the db from scratch and create the dump
95 echo "Couldn't restore the database: No /root/dump found"
99 echo "Starting apache"
100 if type invoke-rc.d 2>/dev/null
102 invoke-rc.d apache2 start