Proclanhosting.com
Proclanhosting Forum
September 09, 2010, 11:08:57 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: We've installed this SMF message board in hopes of helping our customer base share in there experiences with web hosting  and designs. also to offer hosting updates and fixes from proclanhosting.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Semi-automated Backup Of Mysql Databases  (Read 1379 times)
0 Members and 1 Guest are viewing this topic.
Fred
Administrator
Newbie
*****
Posts: 11


View Profile
« on: March 31, 2007, 07:03:27 AM »

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.


Quote
#!/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.
#
# &nbsp; SEE PROGRAMMER'S NOTE SECTION BELOW!!!!
#
# &nbsp; (Make sure you leave OFF your username from the database names.
# &nbsp; 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
# &nbsp; &nbsp;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
# &nbsp; &nbsp;If you want to change this, simply alter the config you see on your screen
#
# &nbsp; &nbsp;For instance, if you want it to run every Sunday, just click on Sunday in
# &nbsp; &nbsp;the weekday selection box.
#
# 7. Test the script out by setting it to run once every minute. After you
# &nbsp; &nbsp;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... &nbsp;(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);

Regards,

Fred
Logged
jquigley15
Newbie
*
Posts: 6


View Profile WWW
« Reply #1 on: March 08, 2010, 12:40:33 PM »

Hello, can you also submit a web form script as I am looking for it for my site. So that the web browser can send me a message form my site directly filling the form. I will be happy if you can do it for me. Thanks.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!