LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 05-26-2003, 10:01 AM   #1
wiltzius
LQ Newbie
 
Registered: May 2003
Posts: 3

Rep: Reputation: 0
Question backup script


Many apologies if this went to the wrong folder, but I wasn't sure if it should go to "general" or "software"

I've got a small web site that I want to make periodic backups of. However, it gets quite annoying once I have to start going through CPanel and downloading backups of the site and then again backups of the MySQL databases through PHPMyAdmin regularly. I figured I should be able to write a simple script that would do this for me, collecting the data and putting it to a remote ftp server instead. Then I could set up a cron job that would run it however often I wanted.

So far, I've gotten something that looks like this:

#! /bin/sh
mysqldump -uuser -ppass --opt --databases db1 > backup.sql
ncftpput -uuser -ppass my.ftp.com / backup.sql

This, unfortunately, doesn't really do what I want it to - mysqldump doesn't seem to work when put in a script with other things. If I have a script with only that command in it, it manages just fine. However, when put in a script in conjunction with another command (as above) it doesn't seem to do anything at all. I even tried having each of those functions in a different script, and then having one script call both of those other scripts, but that doesn't work any better.

ncftpput has an option to put the whatever the output of a command is to a remote server, which would be ideal for me. However, this:

#! /bin/sh
mysqldump -uuser -ppass --opt --databases db1 | ncftpput -c -uuser -ppass my.ftp.com /

doesn't work any better than my other attempts.

Any idea what I might be missing here? I'm not very experienced with the command line, so I may be doing something very obvious wrong. Thanks for any help.

Last edited by wiltzius; 05-26-2003 at 11:30 AM.
 
Old 05-26-2003, 10:20 AM   #2
manthram
Member
 
Registered: Feb 2002
Location: Fairfax, VA
Distribution: RedHat 8, Mandrake9.1, Slack9
Posts: 456

Rep: Reputation: 31
i think this thread

should appeal to you alot
 
Old 05-26-2003, 10:41 AM   #3
wiltzius
LQ Newbie
 
Registered: May 2003
Posts: 3

Original Poster
Rep: Reputation: 0
That helps a lot with the rest of the site, the normal files, thanks. But, I'd still like a MySQL dump of any appropriate databases. Any idea how to manage that?
 
Old 05-26-2003, 11:13 AM   #4
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
I have a question that may not help you. What is the difference between using the mysqldump command and simply backing up all the files in /var/lib/mysql?
 
Old 05-26-2003, 11:34 AM   #5
wiltzius
LQ Newbie
 
Registered: May 2003
Posts: 3

Original Poster
Rep: Reputation: 0
As far as I can tell, very little. mysqldump just gives you a .sql file that's plain text, which provides all the SQL instructions to set up the tables and then add in all the data back into it. I assume, though, that copying that entire file system would work as well. My one concern is that I may not have direct access to that - this is not my server, and I'm not sure I have access to anything outside of my home directory. Also, I don't have shell access (which is becoming increasingly annoying) so the only way I have to do this is to write a script and then run it using the cron job set up program that is included with CPanel.
 
Old 06-20-2003, 04:14 AM   #6
matix
LQ Newbie
 
Registered: Sep 2002
Location: Tasmania AU
Distribution: Debian Sarge - is stable wooo!
Posts: 21

Rep: Reputation: 15
I use the following script i put together some time ago:
Its not tidy, but it works and should be enough to get you started.
Note that this script also zips up the downloaded site when done. (I plan to automatically rename the zip file to contain the date one day - pointers welcome!

Code:
#!/bin/sh
DEST="/root/backups/sitename.com"
mkdir -p ${DEST}
echo ""
echo "##############################################"
echo "###  sitename.com site BACKUP script  ###"
echo "##############################################"
echo "# author: ME"
echo "# modified: 06.03.2003"
echo "#"
echo "# NOTE: this script does NOT backup the following:"
echo "#    /stats    [folder]"
echo "#    *.log     [log files anywhere on the site]"
echo "#"
echo "Downloading MySQL database data."
echo "Please wait.."
mysqldump -h mysql.server.net -u mysql_username -pmysql_password --add-drop-table -B mysql_database_name > ${DEST}/mysqldata.sql
echo ""
echo ""
cd data
wget -m -X /stats -R.log -C off --passive-ftp ftp://ftp_login:ftp_password@ftp.sitename.com/
echo ""
echo ""
zip -D9r ${DEST}.zip ${DEST}
echo ""
echo "Site backup complete."
echo ""
 
Old 03-23-2005, 09:05 AM   #7
Quarterbore
LQ Newbie
 
Registered: Mar 2005
Posts: 1

Rep: Reputation: 0
Can someone help me ... please

I am trying to backup MYSQL databases on remote servers using a server that has CRON capability... I am dot doing to retype what I have found but please see:

http://forums.hostrocket.com/showthr...5200#post95200

What I need help with however is just how the above script get's run? My MYSQL databasses live on UNIX systems while the site I have that has cron capability is a Linux system.

Can I take the script above and save it as a file that I can execute... if so, what extension (cgi, bin, or what?) and then what command would I need to use to execute the script?
 
Old 03-23-2005, 10:01 AM   #8
tangle
Senior Member
 
Registered: Apr 2002
Location: Smithville, TN
Distribution: Slackware
Posts: 1,744

Rep: Reputation: 70
It might now work because the mysqldump is not done running before the ncftpput starts. You might want to look here.
http://www.linuxquestions.org/questi...23#post1547523

If not, make 2 scripts and set them up in cron to run at differnet times.
 
Old 03-23-2005, 05:12 PM   #9
matix
LQ Newbie
 
Registered: Sep 2002
Location: Tasmania AU
Distribution: Debian Sarge - is stable wooo!
Posts: 21

Rep: Reputation: 15
this script would need to be installed on your backup server.

the script doesnt need any special file name or extention to run under unix/linux.
you just have to make sure that you make it executable with: chmod 700 script_filename.sh
(or if you will not be running it as the user(who owns the file) you may need to chmod 777 script_filename.sh)

use cron to automatically run it at your chosen interval
some info for using cron can be found here:
http://www.tech-geeks.org/contrib/md...ron-howto.html

good luck with it
 
  


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 script raptorman Programming 4 08-22-2005 09:52 AM
What backup script do you use? buldir Linux - Software 1 04-12-2005 02:57 PM
Need a backup script enygma Linux - General 5 11-04-2004 03:49 PM
help with backup script dennis_89 Linux - Networking 2 06-29-2004 09:47 AM
Backup Script imsajjadali Linux - General 7 01-28-2004 03:30 PM


All times are GMT -5. The time now is 10:20 AM.

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