If you are reading this, please get modern browser.
skip to main content | skip to main navigation | skip to secondary content

Send Database Backup to Your Mailbox with Backup2Mail

~ 5th June 2005. · 20:02 CET · permanent link · printer friendly ~

Backup and downloading a web site’s database can be really annoying sometimes. It’s something we don’t want to miss, yet we often do. I never lost any of my databases, but I know some guys who unfortunately did.

This PHP script will — with a help of Cron Jobs — backup your MySQL database and send it to specified e-mail address. I suggest creating a separate account, for example backup@yourdomain.com, which will be accessed via web mail if needed. If you have really big database, you wouldn’t want to download it every day (or few times a day). Gmail will do in case you don’t have overly sensitive data.

So, without further ado, I’m releasing this life-saving piece of code. Download Backup2Mail v0.1b. Instructions included.

If you are adventurous type, uncomment the last line in the config.php and feel free to report me errors. Also ask in the comments if you run into a trouble.

13 Comments

  1. Wow, sounds great. Gonna try it ASAP! Due to various reasons, I have problems with my database, so I really hope this will make my life a bit easier. More feedback when I test this :)

  2. May I ask a question? If my database is more than 10MB, does this script still work? Would the attachment be cut apart into several parts? I wanna send my databse to the Gmail. The Gmail attachement maxmium size is 10MB. Thanks.

  3. roncon, the script will probably send attachment, but I don’t know how Gmail will handle this.

    If you are dealing with a database of that size, I wouldn’t recommend sending it via e-mail regularly, because some hosting companies count all traffic made by e-mails into your account bandwidth limit. Instead, leave a copy at the root of your server and download it via FTP.

  4. Thank you for answering my question. Will you continue developing this script? I have run this script on my website, it worked very well. Thank you very much. I suggest that maybe you could add the FTP function. That user can backup the database through FTP or email way or both. The FTP port may be variable, 21 or 926 ,etc.

  5. What about if your db server is different from your web host server as is sometimes the case on a third party host.

  6. [Fri Jun 24 07:04:54 2005] [error] PHP Warning: passthru() has been disabled for security reasons in /blablabla/backup2mail/index.php on line 29

    :-(

    nice work, works not for me.

  7. tobstone, apparently you run your web site on a server with safe mode enabled. Create PHP file and place the following code in it:
    <?php
        phpinfo();
    ?>

    then upload to your server and open it in browser.

    Find the safe_mode_exec_dir directive (it’s under Configuration -> PHP Core). This is the directory in which the passthru() should be allowed. If you run into a trouble, contact your system administrator for exact details.

  8. Jon - i think it is possible to put in a -h option in the mysqldump command part in index.php – give this option the parameter $db_host which you need to add a few lines above as a global and then also in the config file with other vars.

  9. I did exactly this for a customer, but i was using ASP and an Access DB. The only problem I had was that i had no way of scheduling the process on the server. So I just stuck a ‘back-up db’ link in the customers admin section of the site, and told them it was up to them to click it regularly. Another trick you could use is to mark the email as spam in gmail, that way you will only ever retain 30 days of backups, which if your backing up regularly should be enough.

  10. Your idea is very good!
    I think I will try your tool one day

  11. Awesom script! I’ve tried different cron job scripts and this one works perfectly fine! :)
    I hope you could also develop a script that woul backup public_html files and send it to an email.

  12. Hi.
    great job.
    I’m thinking of enhancements in order to use it without the needs for cron.
    I hope I’ll have the time to do it.

    Thanks for your work

  13. @azimuth: If you place the script somewhere in the public directory, it will backup and send via simple request in a browser.

    However, I advise some kind of login system, since I’m sure, you don’t want someone mean to send you tons of e-mails by simply requesting the script’s URL

Sorry, the comment form is closed at this time, but if you have anything to say, please send me a message.

* Please keep in mind that this is a personal web site and it does not reflect the position or opinion of my respective employers, organizations or partners.

Typetester – compare screen type Supported by Veer.

What is this?

A web log of Marko Dugonjić, web professional from Croatia. Topics covered:

Translate this site

German, Spanish, Italian, French or Japanese (via).

See you there!

Feel like buying a book?

Try with maratz.com aStore

Worth visiting

top of the page | skip to main content | skip to main navigation | skip to secondary content