LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2003, 01:26 PM   #1
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Rep: Reputation: 32
Need script to dump database, ftp file to backup server


I want to write a script that will dump the mysql database to a file, and then ftp this file to a predefined location for backups.

Anyone know how this can be accomplished in linux?
 
Old 05-12-2003, 02:30 PM   #2
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Oh come on this is pretty easy task. First of all you need to know which database type you use your database with. If it's other than InnoDB you could use the mysqldump one ... if it's InnoDB you can't do a live backup.

Afterwards just a simple FTP ...


Do you actually want help or a script?
 
Old 05-12-2003, 02:34 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 68
How about:
Code:
#!/bin/bash

# Create an archive of the data
tar -czf /tmp/mysql-backup.tar.gz /var/lib/mysql/*

# Then use scp to transfer the file
scp /tmp/mysql-backup.tar.gz user@host:/path/to/backup/dir/

# Remove the local temp file
rm -f /tmp/mysql-backup.tar.gz
 
Old 05-12-2003, 02:42 PM   #4
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by markus1982
Oh come on this is pretty easy task. First of all you need to know which database type you use your database with. If it's other than InnoDB you could use the mysqldump one ... if it's InnoDB you can't do a live backup.

Afterwards just a simple FTP ...


Do you actually want help or a script?
Ok so I can use the mysqldump command which will dump the database to a file. Then I can tar the file up.

But, how do I automate the ftp transfer? I know which ftp server I need to transfer it to, and I know the logon username/pass. By the way, it's a Windows FTP server I don't know if that would matter.

I know how to do the ftp transfer manually, but I don't know how to get the file to be transferred all in one script command

Thanks to whoever knows and can help me.

Last edited by glock19; 05-12-2003 at 02:44 PM.
 
Old 05-12-2003, 02:49 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 68
Write an "expect" script:
man expect
 
Old 05-12-2003, 02:55 PM   #6
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Original Poster
Rep: Reputation: 32
Ok, thanks. I'll work on the expect script thing.

Another question, how do I make a command that will dump the database to a file, but each time the file name is bumped by 1 (to avoid overwriting the existing backup). So for example, dump1 then dump2 then dump3 etc.
 
Old 05-12-2003, 03:15 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 68
What about:
Code:
#!/bin/bash
# Get the number from a file
count=`cat count.txt`

#do what you want with $count

# Increment the count
let newcount=count+1

# Update the file
echo -n $newcount > count.txt
 
Old 05-12-2003, 03:51 PM   #8
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Original Poster
Rep: Reputation: 32
Don't think that script is what I need.

The problem is that I don't want to overwrite the database dump from the previous ftp transfer. That's why I'd like a script that will rename each new database dump to a new name, that way I won't overwrite the old file on the ftp server.
 
Old 05-12-2003, 04:13 PM   #9
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Original Poster
Rep: Reputation: 32
Does anyone have an ftp script setup using expect to copy a file from your local system to the ftp server? If you do, would you please post here? Thanks.
 
Old 05-12-2003, 04:15 PM   #10
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 68
Quote:
Originally posted by glock19
Don't think that script is what I need.

The problem is that I don't want to overwrite the database dump from the previous ftp transfer. That's why I'd like a script that will rename each new database dump to a new name, that way I won't overwrite the old file on the ftp server.
I know - you can append $count to the filename. I was just showing you how to increment a number.
 
Old 05-12-2003, 04:19 PM   #11
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by david_ross
I know - you can append $count to the filename. I was just showing you how to increment a number.
Sorry, I'm not a guru LOL. I consider myself an "experienced newbie" at best hehe.

Would you mind posting the exact command to do the appending to the actual dump file that I need? Thanks.
 
Old 05-12-2003, 04:21 PM   #12
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
May I suggest that there are really good sites on bash scripting out there you may want to check out. Cause you started out asking for help, now your just asking for scripts that others are writing for you. How do you expect to know how they work by just having others do it for you? Oh well.... http://www.google.com/linux?hl=en&lr...bash+scripting
 
Old 05-12-2003, 04:24 PM   #13
glock19
Member
 
Registered: Aug 2001
Distribution: Debian Etch
Posts: 510

Original Poster
Rep: Reputation: 32
Ok fine, point taken. I've already learned alot about this thanks to help from kind members on this forum. But as they say "give em an inch, they take a mile" hehe. I'll go looking on my own now....thanks again for the help.
 
Old 05-12-2003, 04:27 PM   #14
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
Quote:
Originally posted by glock19
Ok fine, point taken. I've already learned alot about this thanks to help from kind members on this forum. But as they say "give em an inch, they take a mile" hehe. I'll go looking on my own now....thanks again for the help.
I didn't mean to be rude or make it sound bad on what your doing, but more of a friendly way of "if your going to have scripts, its best to understand them and what they are doing."

If you run into more specific problems with a script, ask anytime. But I think its just best to know how to do it yourself really. You'll learn more about how your system operates. You can learn alot from examples, but learn more if you can make one yourself.

Regards.
 
Old 05-12-2003, 05:16 PM   #15
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 68
trickykid is right but you should be able to stick the 2 examples I have given you together and get a working script with scp. The only way I know to do ftp is with expect or ftpcopy.
 
  


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
backup server ; network file system / ftp-server ? markus1982 Linux - Security 5 06-06-2007 05:15 PM
My X server took a large file dump. FC2 ight8 Linux - Software 5 05-28-2004 09:32 PM
How to forcely dump the history of user commands to the admin dump file. mcp_achindra Linux - Security 1 03-19-2004 12:04 PM
cron nightly backup to ftp server rkane Linux - Networking 2 03-04-2004 05:05 PM
SCRIPT: backup defined files/dirs to FTP-server markus1982 Linux - Software 0 05-25-2003 06:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:06 PM.

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