LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   log file (https://www.linuxquestions.org/questions/linux-newbie-8/log-file-4175443227/)

Volcano 12-28-2012 03:49 AM

log file
 
I want to restore mysql database from a dump file.


mysql database restoration command is this :

Quote:
$mysql -u user -pserpassword database_name < dumpfilename.sql


I want to log restoration. How do I log into a file ?


At the start of restoration , log file will log text "restoration started on [date & time] "

At the end of restoration , log file will capture text "restoration completed on [date & time]"

unSpawn 12-28-2012 06:16 AM

Code:

#!/bin/bash --
set -vx # Set debug and error mode when testing.
LANG=C; LC_ALL=C; export LANG LC_ALL # Set default behaviour.
# Logger takes care of the destination to log to and syslog takes care of time stamps:
which logger >/dev/null 2>&1 || logger() { LOGDATE=$(/bin/date +"%b %e %H:%M:%S");
DEST="/var/log/messages"; [ -f $DEST ] || DEST="/var/log/syslog"; echo "${LOGDATE} $@" >> "${DEST}"; }
which mysql >/dev/null 2>&1 || { logger "No MySQL binary found or not in PATH, exiting."; exit 127; }
logger "restoration started."
mysql -u user -pserpassword database_name < dumpfilename.sql
case $? in 0) RETVAL="OK";; *) RETVAL="NOT OK";; esac
logger "restoration finished ${RETVAL}."
exit 0



All times are GMT -5. The time now is 07:52 AM.