LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   backup script (https://www.linuxquestions.org/questions/linux-software-2/backup-script-61893/)

wiltzius 05-26-2003 10:01 AM

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.

manthram 05-26-2003 10:20 AM

i think this thread

should appeal to you alot

wiltzius 05-26-2003 10:41 AM

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?

Crashed_Again 05-26-2003 11:13 AM

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?

wiltzius 05-26-2003 11:34 AM

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.

matix 06-20-2003 04:14 AM

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 ""


Quarterbore 03-23-2005 09:05 AM

Can someone help me ... please :confused:

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?

tangle 03-23-2005 10:01 AM

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.

matix 03-23-2005 05:12 PM

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


All times are GMT -5. The time now is 04:36 PM.