LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-28-2012, 03:49 AM   #1
Volcano
Member
 
Registered: Sep 2005
Posts: 159

Rep: Reputation: 15
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]"
 
Old 12-28-2012, 06:16 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Log iptables drop packet to file but not /var/log/messages? kikilinux Linux - Security 1 10-02-2012 09:42 AM
how to fix "Please have a look at the log file for details: /var/log/jockey.log" harisuciha Linux - Hardware 3 04-29-2012 12:59 PM
In Apache server, How to change log file location and log format for access log fil? since1993 Linux - Server 1 08-19-2009 04:14 PM
setting file permissions for file /var/log/Xorg.0.log mfb Linux - Security 1 07-07-2009 01:41 PM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 06:55 AM


All times are GMT -5. The time now is 05:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration