hi i played around with the create_demo_db.sh script and made some improvements. apart from better error reporting it is also easier to customize it when starting to build an own database. script is attached, here's the details:
- while the error checking in the old script worked for one line dbmcli commands, it didn't for the multiline commands fed with cat to dbmcli. the captured output seems to be that of cat, so there is never an error reported. in my version all output of these commands goes to a logfile. then the last lines of the logfile are checked with tail and grep for an error ("ERR"). - i added error handling for the stop and drop commands. of course these fail if the database doesn't exists, but the user should at least now about it, the script continues anyway. this way the error will at least be in the log in case it fails for some other reason. - the size of the database file and the logfile can be specified in MB. conversion to the 8KB pages is done with bc. this means a new dependency, i don't really know which distributions install it by default. - moved some other db parameters into variables at the top. - another new dependency is tee to output to the screen and log at the same time, but this should be on all systems, right? - removed usage of $HOME. the data, log and backup files shouldn't be on the same harddrive in a production system, so three different variables are used, they default to /home/sapdb. alternative: leave the $HOME part in and use it as default for the threee. - nicer output ;) so tell me what you think and you sapdb people feel free to include any parts of it if you like. bye fabian p.s. tested on linux debian woody/tgz package 7.3.0.18
#!/bin/sh ### # create a SAPDB database ### # name of the database SID=TST # username and password USERNAME=test PASSWORD=test # size of database and logs in MB DATASIZE=20 LOGSIZE=8 # path to sapdb binaries DEP=/usr/sapdb/depend IND=/usr/sapdb/indep_prog # path to database files DATA=/home/sapdb LOG=/home/sapdb BACKUP=/home/sapdb # more advanced database parameters CATCACHESUPPLY=300 DATACACHE=2500 MAXDATADEVSPACES=5 MAXDATAPAGES=1024000 # logfile for output of this script LOGFILE=create_demo_db.log # end of configuration # no need to go below this line unless something is wrong # calculate database pages from sizes DATAPAGES=`cat <<EOF | bc $DATASIZE*128 EOF` LOGPAGES=`cat <<EOF | bc $LOGSIZE*128 EOF` # script shouldn't be run as root id=`id | sed s/\(.*// | sed s/uid=//` if [ "$id" = "0" ]; then echo "Don't start script as root!" 1>&2 exit 1 fi # set variables INSTROOT=$DEP PATH=$IND/bin:$PATH export PATH # print header echo "Start creating SAPDB database $SID" | tee -a $LOGFILE echo -n `hostname` | tee -a $LOGFILE echo -n " " | tee -a $LOGFILE echo `date` | tee -a $LOGFILE echo | tee -a $LOGFILE # start remote communication server x_server start >/dev/null 2>&1 # try to stop existing database echo -n "Stopping database $SID..." | tee -a $LOGFILE _o=`dbmcli -d $SID -u dbm,dbm db_offline 2>&1` _test=`echo $_o | grep OK` if [ "$_test" = "" ]; then echo "failed." | tee -a $LOGFILE echo $_o >> $LOGFILE echo "Maybe it didn't exists, so continuing." | tee -a $LOGFILE else echo "ok" | tee -a $LOGFILE fi # try to drop existing database echo -n "Dropping database $SID..." | tee -a $LOGFILE _o=`dbmcli -d $SID -u dbm,dbm db_drop 2>&1` _test=`echo $_o | grep OK` if [ "$_test" = "" ]; then echo "failed." | tee -a $LOGFILE echo $_o >> $LOGFILE echo "Maybe it didn't exists, so continuing." | tee -a $LOGFILE else echo "ok" | tee -a $LOGFILE fi # create new demo database echo -n "Creating database $SID..." | tee -a $LOGFILE _o=`dbmcli -s -R $INSTROOT db_create $SID dbm,dbm 2>&1` _test=`echo $_o | grep OK` if [ "$_test" = "" ]; then echo "failed!" | tee -a $LOGFILE echo $_o | tee -a $LOGFILE exit 1 fi echo "ok" | tee -a $LOGFILE # create directories for database files echo -n "Creating directories..." | tee -a $LOGFILE mkdir -p $DATA/$SID mkdir -p $LOG/$SID mkdir -p $BACKUP/$SID echo "ok" | tee -a $LOGFILE # setup database parameters echo -n "Setting parameters for $SID..." | tee -a $LOGFILE cat <<EOF | dbmcli -d $SID -u dbm,dbm >> $LOGFILE 2>&1 param_rmfile param_startsession param_init OLTP param_put LOG_MODE SINGLE param_put CAT_CACHE_SUPPLY $CATCACHESUPPLY param_put DATA_CACHE $DATACACHE param_put MAXDATADEVSPACES $MAXDATADEVSPACES param_put MAXDATAPAGES $MAXDATAPAGES param_checkall param_commitsession param_adddevspace 1 SYS $DATA/$SID/DISKS01 F param_adddevspace 1 DATA $DATA/$SID/DISKD0001 F $DATAPAGES param_adddevspace 1 LOG $LOG/$SID/DISKL001 F $LOGPAGES quit EOF _test=`tail -n 40 $LOGFILE | grep ERR` if [ "$_test" != "" ]; then echo "failed!" | tee -a $LOGFILE echo "See $LOGFILE for details." exit 1 fi echo "ok" | tee -a $LOGFILE # startup database echo -n "Starting database $SID..." | tee -a $LOGFILE _o=`dbmcli -d $SID -u dbm,dbm db_start 2>&1` _test=`echo $_o | grep OK` if [ "$_test" = "" ]; then echo "failed!" | tee -a $LOGFILE echo $_o | tee -a $LOGFILE exit 1 fi echo "ok" | tee -a $LOGFILE # initialize database files echo -n "Initializing database files..." | tee -a $LOGFILE cat <<EOF | dbmcli -d $SID -u dbm,dbm >> $LOGFILE 2>&1 util_connect dbm,dbm util_execute init config util_activate dba,dba quit EOF _test=`tail -n 20 $LOGFILE | grep ERR` if [ "$_test" != "" ]; then echo "failed!" | tee -a $LOGFILE echo "See $LOGFILE for details." exit 1 fi echo "ok" | tee -a $LOGFILE # load database system tables echo -n "Loading system tables..." | tee -a $LOGFILE _o=`dbmcli -d $SID -u dbm,dbm load_systab -u dba,dba -ud domain 2>&1` _test=`echo $_o | grep OK` if [ "$_test" = "" ]; then echo "failed!" | tee -a $LOGFILE echo $_o | tee -a $LOGFILE exit 1 fi echo "ok" | tee -a $LOGFILE # create database demo user echo -n "Creating database user $USERNAME..." | tee -a $LOGFILE cat <<EOF | dbmcli -d $SID -u dba,dba >> $LOGFILE 2>&1 sql_connect dba,dba sql_execute CREATE USER $USERNAME PASSWORD $PASSWORD DBA NOT EXCLUSIVE EOF _test=`tail -n 7 $LOGFILE | grep ERR` if [ "$_test" != "" ]; then echo "failed!" | tee -a $LOGFILE echo "See $LOGFILE for details." exit 1 fi echo "ok" | tee -a $LOGFILE # define backup medium echo -n "Setting backup parameters..." | tee -a $LOGFILE cat <<EOF | dbmcli -d $SID -u dbm,dbm >> $LOGFILE 2>&1 medium_put data $BACKUP/$SID/datasave FILE DATA 0 8 YES medium_put auto $BACKUP/$SID/autosave FILE AUTO util_connect dbm,dbm backup_save data autosave_on quit EOF _test=`tail -n 40 $LOGFILE | grep ERR` if [ "$_test" != "" ]; then echo "failed!" | tee -a $LOGFILE echo "See $LOGFILE for details." exit 1 fi echo "ok" | tee -a $LOGFILE echo echo "All done, see $LOGFILE for details." echo exit 0