LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-06-2011, 08:35 AM   #1
ramecare
Member
 
Registered: Feb 2011
Posts: 179

Rep: Reputation: 0
tar backup & restore in mysql


Hi to all,

Can anyone help me on command how to take tar backup and restore in mysql,Iam new to mysql,i searched in google but i did not get the exact one.

Thanks,
 
Old 05-06-2011, 09:54 AM   #2
hua
Member
 
Registered: Oct 2006
Location: Slovak Republic
Distribution: Slackware 14.2, current
Posts: 463

Rep: Reputation: 79
Backup with mysqldump and use tar to archive it.
Code:
mysqldump -u root -pYOURPASSWORD databasename > databasename.sql
tar -cvvf databasename.sql.tar databasename.sql
Untar and restore the database:
Code:
tar -xvvf databasename.sql.tar
mysql -u root -pYOURPASSWORD databasename < databasename.sql
Note that after -p (password) there is no space! You can use any other user then root but the user must have the required privileges on the actual database.
This will overwrite your database so create backup of the actual database first. (Just for sure)

Last edited by hua; 05-06-2011 at 10:00 AM.
 
1 members found this post helpful.
Old 05-06-2011, 11:38 AM   #3
ramecare
Member
 
Registered: Feb 2011
Posts: 179

Original Poster
Rep: Reputation: 0
But when i run in shell script iam getting the below error
Shell program:
#/bin/bash
mount -t cifs -o user="$1",password="$2" "$3"/"$1" "$4"
cd "$4""$5"
date=`/bin/date "+\%Y-\%m-\%d-\%H-\%M-\%S"`
mysqldump -u"$6" -p"$7" "$8" > $date.sql
tar -zcvf $date.sql.tgz $date.sql

command:
[root@itsupport Desktop]# ./newshell ramkannan Linux123@ //10.200.1.125 /MT /test root ecare2@ employeedb
tar: \2011-\005-\006-\020-%-\f.sql: Cannot stat: No such file or directory ------------------> ERROR
tar: Error exit delayed from previous errors ---------------------> ERROR

Can u help on the above error.

Thanks,
 
Old 05-06-2011, 12:45 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You would do yourself a service to lose the backslashes in the filename you are trying to compose. These will inevitably cause you grief, since these characters get specail treatment in shells and elsewhere. Also, your transcript of the output seems to differ from the code you posted. When I run
Code:
/bin/date "+\%Y-\%m-\%d-\%H-\%M-\%S"
I get
Code:
\2011-\05-\06-\09-\37-\12
I don't know where you are getting the extra leading zero's and the mysterious '%-f' in your output. Did you manually transcribe your posting, or did you use a copy & paste method? Are you sure it is accurate?
Also, the use of the variable 'date' is asking for confusion with the date command. It is probably better practice to avoid the use of such overlapping uses; perhaps the name 'datestamp' is at least as meaningful.

--- rod.

Last edited by theNbomr; 05-06-2011 at 12:46 PM.
 
Old 05-07-2011, 12:12 AM   #5
ramecare
Member
 
Registered: Feb 2011
Posts: 179

Original Poster
Rep: Reputation: 0
Hi,

Shell program is working now,I have taken the \ from the date,tat is the problem,Thank u very much.

#/bin/bash
mount -t cifs -o user="$1",password="$2" "$3"/"$1" "$4"
cd "$4""$5"
date=`/bin/date "+%Y.%m.%d.%H.%M.%S"`
mysqldump -u"$6" -p"$7" "$8" > $date.sql
tar -zcvf $date.sql.tgz $date.sql
rm -rf $date.sql
 
  


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
[SOLVED] Mysql Backup & Restore scripts ramecare Linux - Server 3 04-11-2011 06:29 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 03:53 AM
Backup and Restore with TAR jay2809 Linux - Newbie 7 08-25-2004 05:47 PM
Backup & Restore plan using tar markcasazza Linux - Newbie 1 04-14-2004 02:11 PM
tar backup & restore of current directory wishbone42 Linux - General 3 02-09-2004 03:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:51 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration