Simple mysql utility that dumps data from all databases on a server into a date stamped directory - can either be called either through a web site or automated with a PHP binary and entry into your crontab.
By : ov_m
<?php
//Full Source at http://www.ov-m.com/mysqlphpbak/
$MYSQL_SERVER="localhost"; // server name
$MYSQL_USER="foo"; // authorized mysql user
$MYSQL_PASSWD="bar"; // authorized user password
$PATHTOMYSQLDUMP="/www/bin/"; // path to mysqldump utility
$DIRNAME="/path/to/database/backup/dir/"; // where to do the backups
$DIRNAME.=date("Ymd"); // add date identifier
$DIRNAME.="/"; // add trailing slash
echo "Creating New Back Up Directory\n\n";
echo "Using Directory : $DIRNAME<br>\n";
if (@mkdir ($DIRNAME,0700)) {
echo "New Directory Created<br>\n";
} else {
echo "Directory already exists!\n";
}
echo "Backing Up all Databases on $HOSTNAME\n\n";
//***************************************************************************
mysql_connect($MYSQL_SERVER,$MYSQL_USER,$MYSQL_PASSWD);
$result = mysql_list_dbs();
$i = 0;
while ($i < mysql_num_rows ($result)) {
$tb_names[$i] = mysql_tablename ($result, $i);
$i++;
}
//***************************************************************************
// Loop through the table names, and do the dump.
//***************************************************************************
for ($i=0; $i<count($tb_names); $i++) {
$COMMAND_DO=$PATHTOMYSQLDUMP. "mysqldump -h".$MYSQL_SERVER." -u".$MYSQL_USER." -p".$MYSQL_PASSWD." ".$tb_names[$i]." > ".$DIRNAME.$tb_names[$i].".sql";
//echo $COMMAND_DO."\n"; // uncomment these lines if you want to see all
//flush(); // back-ups made on the server
exec($COMMAND_DO); // execute each backup
}
echo "\n\nDONE!\n";
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Database Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
|
|
|
|
You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development. FREE! Go There Now!
|
|
|
|
In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |