Results 1 to 3 of 3
Thread: mySQL backup script & cronjob
-
05-31-2005, 06:33 AM #1New Member
- Join Date
- May 2005
- Location
- Chicago
- Posts
- 2
mySQL backup script & cronjob
Hi!
I've got no idea in the world about what I'm doing here, so seeking help from experts
Our school runs a forum and is now too large to backup fully via phpmyadmin and I've been advised I need to create a "cronjob" and a "shell script" to create a mySQL backup of a database running off Plesk 7
First time I had ever heard the word "cronjob" but was advised to seek help here
So basically if anybody could help, what do I need to achieve a mysql database backup once a week on an early Sunday morning (in gzip format is preferred if possible) to output to a folder on our server called root/private
Our database details are
db - forum
u - forumuser
p - forumpass
and it is in the path of ourdomain.edu/forum/index.php
in our Plesk panel there is a crontab tab - so assuming I would want for 3am Sundays (if I worked this out right)
Minute 0
Hour 3
Day of the Month *
Month *
Day of the Week 0
Command (command for the script I need?)
So I think I have the "cronjob" part worked out (maybe?) - just need a "shell script" now to spit out the backup
Thanks
-
05-31-2005, 06:52 AM #2Web Hosting Master
- Join Date
- Feb 2004
- Posts
- 772
hai browne,
here are differences in environment when you run a cron, and when you run a script while logged in. It's typically a stripped-down shell, with a minimal $PATH, etc etc.
What I'd suggest doing is echoing everything that you're going to execute.
So, when you have your exec, echo what is actually being exec'd and so on. It may be that it doesn't know where gzip is, etc. It's usually something minor that screws up the whole thing, that's hard to track down, but easy to fix.
To spit out the database
-----------------------------------
As an additional note, if you wanted all of the potential output from all streams (stdout and stderr rather than just stdout), use:
*/1 * * * * /usr/local/bin/php -f /kunden/homepages/33/d85254132/htdocs/SQLbackup.php > /path/to/log.txt 2>&1
I agree with nalin that you should be using a shell script rather than PHP's exec function, since you're using the shell anyway with the exec function.
Also, whenever you're calling a command, use the full path. If you're using mysqldump, then use /usr/local/mysql/bin/mysqldump, or whatever the path is. It can save a lot of trouble in the future.
thanksBright Info Solutions
-
05-31-2005, 07:25 AM #3New Member
- Join Date
- May 2005
- Location
- Chicago
- Posts
- 2
Would this work as my script?
outfile='/private/db-'`date +%m`'-'`date +%d`'-'`date +%y`'.tar.gz'
mkdir /private/temp
mysqldump -u forumuser -p forumpass --databases forum > /private/temp/forum.sql
tar -czf $outfile /private/temp/*
rm -rf /private/temp
rm -f temptar