The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

If running from shell, put this above the <?php "#! /usr/bin/php -q" without the quotes!!!

This script is dedicated to "Salk". You know who you are :)

This script runs a backup of your database that you define below. It then gzips the .sql file
and emails it to you or ftp's the file to a location of your choice.

It is highly recommended that you leave gzip on to reduce the file size.

You must chown the directory this script resides in to the same user or group your webserver runs
in, or CHMOD it to writable. I do not recommend chmod 777 but it's a quick solution. If you can setup
a cron, you can probably chown your directory!

IMPORTANT!!! I recommend that you run this outside of your
web directory, unless you manually want to run this script. If you do upload it inside your web
directory source tree, I would at least apply Apache access control on that directory. You don't
want people downloading your raw databases!

This script is meant to be setup on a crontab and run on a weekly basis
You will have to contact your system administrator to setup a cron tab for this script
Here's an example crontab:

$use_gzip = "yes"; // Set to No if you don't want the files sent in .gz format
$remove_sql_file = "no"; // Set this to yes if you want to remove the .sql file after gzipping. Yes is recommended.
$remove_gzip_file = "no"; // Set this to yes if you want to delete the gzip file also. I recommend leaving it to "no"

// Configure the path that this script resides on your server.

$savepath = ""; // Full path to this directory. Do not use trailing slash!

$send_email_w_file = "yes"; // Do you want this database backup sent to your email? Fill out the next 2 lines
$to = ""; // Who to send the emails to
$from = ""; // Who should the emails be sent from?
$senddate = date("j F Y");
$subject = "MySQL Database Backup - $senddate"; // Subject in the email to be sent.
$headers = "From: $from";
if ($send_email_w_file == "yes") {
$message = "Your MySQL database has been backed up and is attached to this email."; // Brief Message.
} else {
$message = "Your MySQL database has been backed up and placed in $savepath."; // Brief Message.
}

// adds "directory" to archive - do this before putting any files in directory!
// $name - name of directory... like this: "path/"
// ...then you can add files using add_file with names like "path/file.txt"
{
$name = str_replace("\\", "/", $name);

This is good for awhile but what happens when the db gets to be larger than a few mb compressed ? Email doesn't work anymore. Eventually, you'll have to make the script create a backup of the db on the server itself and maybe automatically ftp it to the client or to you. Or the client could periodically ftp the file down.

If anything happens to the file backup while it's on the server, the hosting provider should be able to provide a backup. Just be careful that the permissions are set appropriately so that some stranger can't come along and download the db themselves.