Linux - SoftwareThis 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
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.
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:
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:
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.
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?
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?
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.
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 ""
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:
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?
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)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.