diff options
author | Chou, Joseph (JC2555) <jc2555@att.com> | 2018-03-22 11:22:35 -0400 |
---|---|---|
committer | Chou, Joseph (JC2555) <jc2555@att.com> | 2018-03-23 18:05:27 -0400 |
commit | 669931e76de18aabb14f9ff873da4783f8c83d7a (patch) | |
tree | d289226c55b0e7adfe9f56ea6dc6f9e32120dbca /packages/base/src/files/install/mysql/bin/db_restore.sh | |
parent | cc7d8f696dd7717493dfc87e41884c7dd9923b83 (diff) |
ONAP code change for log files consolidation
Code change for log files consolidation of PAP, PDP, BRMSGW, Console and db
script
Issue-ID: POLICY-562
Change-Id: I416ba7748b841bb2b1a31682e2b1631e279549e8
Signed-off-by: Chou, Joseph (JC2555) <jc2555@att.com>
Diffstat (limited to 'packages/base/src/files/install/mysql/bin/db_restore.sh')
-rw-r--r-- | packages/base/src/files/install/mysql/bin/db_restore.sh | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/packages/base/src/files/install/mysql/bin/db_restore.sh b/packages/base/src/files/install/mysql/bin/db_restore.sh index d6e21df79..765b0cad3 100644 --- a/packages/base/src/files/install/mysql/bin/db_restore.sh +++ b/packages/base/src/files/install/mysql/bin/db_restore.sh @@ -38,40 +38,48 @@ BACKUP_FILE="" DATABASE="" TABLE="" TEMP_FILE=/tmp/db_restore_$$.sql +DATE=`date +"%Y%m%d"` +LOG="" function restore_all { - echo "restore_all started ...@`date`" - echo "Before restore table ..." + echo "restore_all started ...@`date`" | tee -a $LOG + echo "Before restore table ..." | tee -a $LOG echo "--" mysql -u${DB_USER} -p${DB_PASSWORD} < $BACKUP_FILE echo "--" - echo "restore_all completed ...@`date`" + echo "restore_all completed ...@`date`" | tee -a $LOG } function restore_table { database="${1}" table="${2}" - echo "restore_table [$database] [$table] started ...@`date`" + echo "restore_table [$database] [$table] started ...@`date`" | tee -a $LOG # extract sql statement from backup file - echo "use $database;" > $TEMP_FILE + echo "use $database;" > $TEMP_FILE echo "set foreign_key_checks=0; " >> $TEMP_FILE sed -n -e '/DROP TABLE IF EXISTS `'$table'`;/,/UNLOCK TABLES;/p' $BACKUP_FILE >> $TEMP_FILE echo "set foreign_key_checks=1; " >> $TEMP_FILE echo "--" cat $TEMP_FILE echo "--" - echo "Before restore table ..." + echo "Before restore table ..." | tee -a $LOG mysql -u${DB_USER} -p${DB_PASSWORD} < $TEMP_FILE echo "--" - echo "restore_table [$database] [$table] completed ...@`date`" + echo "restore_table [$database] [$table] completed ...@`date`" | tee -a $LOG } # MAIN -echo "db_restore.sh started ... `date`" +if [ -z ${POLICY_LOGS} ]; then + POLICY_LOGS=/var/log/onap +fi +mkdir -p $POLICY_LOGS/policy/db +LOG=$POLICY_LOGS/policy/db/db_restore_$DATE.log + +echo "db_restore.sh started ... `date`" | tee -a $LOG if [ $# -eq 5 ]; then DB_USER="${1}" DB_PASSWORD="${2}" @@ -86,7 +94,7 @@ if [ $# -eq 5 ]; then restore_all fi else - echo "BACKUP FILE NOT FOUND: $BACKUP_FILE" + echo "BACKUP FILE NOT FOUND: $BACKUP_FILE" | tee -a $LOG fi else echo "Usage : db_restore.sh db_user_id db_password backup_file database table_name" @@ -94,4 +102,4 @@ else fi rm -f $TEMP_FILE -echo "db_restore.sh completed ... `date`" +echo "db_restore.sh completed ... `date`" | tee -a $LOG |