Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-12-2005, 02:01 PM MySQL backup
Average Talker

Posts: 20
Trades: 0
Hello, I've been searching all over the place for a script that I can cron to backup my database. It also needs to have the ability to email me the archived file. I have found a few, but cannot use them as my current host does not have DBI, MIME Lite or MUTT modules installed.

Does anyone know of a free script that will email me the file without needing any of those 3 modules? Perhaps one that can just POP me the attached file??
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
DavidB is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-12-2005, 02:10 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Well if you know much about php this would not be hard to implement. You can use a DUMP sql statement to dump the database to a file then email the file as an attachment.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 02:38 PM
Average Talker

Posts: 20
Trades: 0
It's probably a pretty simple thing, but I have no clue how to do it as I don't know PHP at all. I'm using a script right now, and it dumps the database to a file with no problems. But I can't get it to mail me the results (as the script is designed to do) because of the missing modules. Basically, I'm using half the script.

From your reply, there IS a way to have the file emailed to me even without MIME Lite, MUTT, etc????
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
DavidB is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 03:29 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Yep, PHP has some built in MIME features that can be used. I'll put something together and post it here later for the whole community to use.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 03:40 PM
Average Talker

Posts: 20
Trades: 0
OK, thanks for the good news! You don't have to go through all that trouble for me, but it might be good for the community to see it

I did find a php script that looks like it might work to mail the attachment. But I CAN'T get the script to run!

I keep getting this error:

/usr/bin/php: bad interpreter: No such file or directory

I'm sure it's simple, but I have tried every path I can think of, and it still won't recognize it. Anybody know what I'm doing wrong?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
DavidB is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 04:32 PM
Average Talker

Posts: 20
Trades: 0
Okay, did some research. The PHP on my host is installed as Apache, and not CGI. From what I gather, I need access to Lynx, so I can edit my /etc/crontab file??? I don't have access to Lynx, nor can I even get into my /etc directory. Do I need to just find another host???????????
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
DavidB is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 05:46 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
How are you calling the script in your crontab? Are you calling it directly or are you prepending php to it?

Here is what I came up with regardless. However, perhaps the community can help me out on this one I keep getting an error yet it sends the file fine.

Here is MyDump.php:
PHP Code:
<?php
// Database Settings
$user 'root';
$pass '';
$db 'test';

// Email Settings
$from '';
$fromName '';
$to '';
$toName '';
$subject 'MySQL dump file ' date("M-d-Y");
$message 'You\'ve got a new backup';

// Backup File Settings
$save_path '/home/civilis/public_html'// without trailing slash
$file_name 'mybackup.sql';
// Stop editing here


exec("mysqldump -u $user -p$pass $db > $save_path/$file_name");

$data implode(""file("$save_path/$file_name"));
$gzdata gzencode($data9);
$fp fopen("$save_path/$file_name.gz""w");
fwrite($fp$gzdata);
fclose($fp);

exec("rm $save_path/$file_name");

include 
'class.phpmailer.php';

$mail = new PHPMailer();
$mail->From $from;
$mail->FromName $fromName;
$mail->AddAddress($to$toName);
$mail->AddAttachment($file_name.'.gz');
$mail->IsHTML(false);
$mail->Subject $subject;
$mail->Body $message;
$mail->Send();
?>
This script requires PHPMailer which is very easy to use, just drop it into the same directory as this file.

However, I get this error by email along with a seperate email with the proper backed up file...

Code:
Content-type: text/html
X-Powered-By: PHP/4.3.10

<br />
<b>Warning</b>:  fopen(/home/civilis/public_html/path/changed/MyDump/mybackup.sql.gz): failed to open stream: Permission denied in <b>/home/civilis/public_html/path/changed/MyDump/MyDump.php</b> on line <b>23</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in <b>/home/civilis/public_html/path/changed/MyDump/MyDump.php</b> on line <b>24</b><br />
<br />
<b>Warning</b>:  fclose(): supplied argument is not a valid stream resource in <b>/home/civilis/public_html/path/changed/MyDump/MyDump.php</b> on line <b>25</b><br />
I don't get this because the very next email is the correct email with the attachment...Anyone else have a clue?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 06:37 PM
Average Talker

Posts: 20
Trades: 0
Ok, I just finished toying with that script. I haven't tried with cron yet, just ran it from the browser. I got it to where I don't get a screen full of errrors, and it's mailing me a mail with "You've got a new backup"

I don't get 2 mails like you are. No error mail at all. It is sending me an attachment, but it's only 1K in size. My database is like 3MB when gzipped. So something's wrong there. Did you get an actual DB backup mailed to you in the correct size?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
DavidB is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 07:17 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Yeah, I got the full backup. What errors were you getting on the screen? As far as my other email error that would only happen when I cronned it.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 07:39 PM
Average Talker

Posts: 20
Trades: 0
I was getting the usual permission and path errors. Nothing to do with your script, just me. This thing still won't work. It's not a PHPMailer problem, as it's not even backing up my database onto the server. Well, it does, but it's 1K as well.

I'll just switch hosting companies and get MUTT. All these scripts I've been trying is driving me nuts. Thanks for the help, cptn.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
DavidB is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 07:51 PM
Super Talker

Posts: 110
Trades: 1
A very quick and easy way is to run a cron job consisting of a script:

shutdown MySQL
tarzip the data directories
restart mysql
move the tarzip to an ftp'able directory and chmod it to the ftp user
on a windows PC run a schedule task to ftp download the file

This is what I do and it requires no user intervention. The script runs at 4:00am so there is hardly any traffic. If there was, the database is only down for about 30seconds.

When I boot my windows PC in the morning a schedule task waits until 9:00am and downloads the tarzip.

I don't have to do anything - except switch the PC on before 9:00am

I have a second server on the net which also grabs the file at 5:00am. Really, this is idiot proof!
Frank Rizzo is offline
Reply With Quote
View Public Profile Visit Frank Rizzo's homepage!
 
Old 03-12-2005, 09:11 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
If your host uses cPanel, then you'll most likely have the ability to schedule automatic backups through that.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 09:35 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
I'm not sure whether the exec function will work on windows, is your hosting windows based?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 09:52 PM
Average Talker

Posts: 20
Trades: 0
Anacrusis, no I don't have cpanel. My host offers h-sphere, but there is a cron function that allows me to set up these jobs. I already have the auto backups running, but would like the files sent to an email adde like gmail or yahoo, since I have a slow dial-up that takes forever.

Cptnwinky, yes, I'm running on Linux. I don't know why it's not working. It's okay though. I just signed up for another host and waiting activation. I will get this all settled in a jiffy after that.

I couldn't get the script to work, but others probably will. It's a very good script to have, so thanks for taking the time to write it up. I will try it on the new server as well
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
DavidB is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to MySQL backup
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46544 seconds with 12 queries