Save the following text as a file ending in ".pl" and upload it in text FTP transfer mode (not binary) to your cgi-bin directory, then you can create a cronjob to execute this script every day if you want.
Obviously, you'll need to edit the file below to input your own account information.
#!/usr/bin/perl
use Net::FTP;
# **********************************************************
# This is a simple script to place in your CPanel cron jobs that will FTP your
# backups of your MySQL databases to any FTP server you wish. By doing this,
# you will have automated backups of your databases sent to this FTP server
# on a routine basis. Then, you will have peace of mind knowing that HASWEB's
# servers were to go offline, you'd have recent backups.
# **********************************************************
# ***********
# Installation: *
# ***********
# You will have to rename the file sql_ftp_backup.pl and make sure it has
# executable permission set (mode 755 will work) which can be done with your FTP client
# 1. Download and save this script to your local computer.
# 2. Open the file in a text editor like Notepad with Word Wrap turned off.
# 3. Edit the variables with the <> symbols around them.
#
# SEE PROGRAMMER'S NOTE SECTION BELOW!!!!
#
# (Make sure you leave OFF your username from the database names.
# For a complete list of db names, check out your backup section on CPanel)
#
# 4. Save the document and then rename it to sql_ftp_backup.pl
# 5. Upload the file to your home directory (The main root of your FTP dirs)
# 6. Make sure that it has been renamed to sql_ftp_backup.pl
# 7. Make sure that the CHMOD setting is executable (mode 755)
# ********
# Usage: *
# ********
# 1. Go to your cPanel and click on "Cron Jobs".
# 2. Click on the standard button.
# 3. Enter a valid email address in the top entry. This is where any error output
# from the script will be sent in case the script fails.
# 5. In the entry box "Command to run" enter: /home/simplele/sql_backup.pl
# 6. The default configuration is to have the script run every day at 3am
# If you want to change this, simply alter the config you see on your screen
#
# For instance, if you want it to run every Sunday, just click on Sunday in
# the weekday selection box.
#
# 7. Test the script out by setting it to run once every minute. After you
# are confident that it will work correctly, set it to once a day/once a week.
#
# 8. Click "Save Crontab"
#
# Enjoy!
# October 2003 - David Sierkowski (
scripts@phonism.net)
# EDIT FOR FTP: November 26, 2003 - Justin Tubbs (
justin@simpleletter.com)
# **********************************************************
# (from the BSD license. in short, I'm not accountable for anything this script does to you.)
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# **********************************************************
use MIME::Lite;
# **********************************************************
# PROGRAMMER'S NOTE SECTION:
# In this section, any variables with <> around them need to be filled.
# Remove the "<>" marks and the caps text inside and replace with your parameters.
# **********************************************************
# make sure this is your cPanel username - CASE SENSITIVE
$user = "<CPANEL USERNAME>";
# enter your cPanel password here - CASE SENSITIVE
$password = "<CPANEL PASSWORD>";
# enter the list of databases you want to have sent to you
# leave off your username. use the database names listed on your backup page
# in cPanel
#
# USE THIS FORMAT - CASE SENSITIVE:
# @dbs = qw(addressbook calendar mailingList) etc... (space separated)
#
@dbs = qw(addressbook calendar mailingList);
# this should be /home/yourusername/tmp or /home2/yourusername/tmp
# go with /home/ and if the script fails, switch it to /home2/
$tmp_dir = "/home/<CPANEL USERNAME>/tmp";
# mysqldump options to make a cPanel restore compatible dump
#
# NOTE: if you want to have a backup compatible with cPanel's restore
# mechanism, leave the $dump_opts alone. Only change this if you know what
# you are doing.
$dump_opts = "-c --add-drop-table";
# name the file you want to contain backup log information
$msg_file = $tmp_dir . "/msg.txt";
# set a variable with today's date in it
$date = `date +'%m-%d-%Y'`;
open(MSG,">$msg_file");
print MSG "Here are the MySQL Dumps, generated by SQL_Backup: \n";
print MSG "\nThe following databases are enclosed: \n\n";
# Loop through the array of db names and send each backup script to FTP server
foreach $db (@dbs)
{
system("mysqldump $dump_opts --user=$user --password=$password $user\_$db > $tmp_dir/$db.sql");
print MSG "\t $db\n";
push(@atts,"$tmp_dir/$db.sql");
$ftp = Net::FTP->new("<FTP SERVER IP ADDRESS>", Debug => 0) or die "Cannot connect to <FTP SERVER IP ADDRESS>: $@";
$ftp->login("<FTP USERNAME>","<FTP PASSWORD>") or die "Cannot login ", $ftp->message;
$ftp->cwd("<FTP BACKUP DIRECTORY (CREATE ONE ON YOUR FTP SERVER)>") or die "Cannot change working directory to <FTP BACKUP DIRECTORY>", $ftp->message;
$ftp->put("$tmp_dir/$db.sql") or die "get failed ", $ftp->message;
$ftp->quit;
}
print MSG "\n";
close(MSG);