Need script to dump database, ftp file to backup server
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
#!/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
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
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.
#!/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
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.
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.
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.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.