Most Rated Articles

Installing Apache and Apache Modules the easy way

The Essential steps on how to Sysprep Windows 7

SSH is very much similar to telnet. SSH is a shell program which allows a user remote access and the ability to execute commands over a network.

It is important to protect your wireless networks from unwanted and abusive users. Unauthorized users may reduce the bandwidth and may lock up your network

There are many methods on how to optimize apache. It could be on the software side, but upgrading the hardware also makes a difference.

With Windows 7 as a new OS in the market, one may worry about any problems that could be encountered especially network issues such as compatibility with older OS. Windows 7 might encounter problems communicating with older Windows models such as XP. The following are ways on how to network Windows 7 and XP.

One way of installing windows over the network is through the use of RIS or Remote Installation Services. However, you must have the following prerequisites in order to install Windows over the network.

Installing a printer on a mac is just as easy as installing a printer on an OS of Windows. The following steps are just some of the steps on how to connect your printer a Mac operating system.

Nowadays, it is important to have access to Wi-Fi. However, not everyone has their own internet connection so most people leech wherever there is free Wi-Fi. Most routers with Wi-Fi access require passwords but nowadays, there are other places to look around and search for free Wi-Fi.

Some applications cannot install in Windows 7 due to incompatibility issues. A solution would be to enable XP mode in a virtual environment of Windows 7. This configuration may be used to run and install programs that were incompatible in Windows 7.

Database  »  MySQL
 Picture

Backup up mysql databases with mysqldump

By: Jerry Slagger
Date Added : June 6, 2009 Views : 1279



There are a few ways you can use mysqldump to backup MySQL databases. You can write a php or bash script and then automate the process by scheduling it in cron. Here is an example of an sh script to backup a single database.

mysqldump --user=USER --password=PASSWORD DBNAME | gzip > DBNAME.gz

The above command will backup the database into a compressed gzip file. If you wanted to run the same command from a php script you could use the exec() command.

exec("mysqldump --user=USER --password=PASSWORD DBNAME | gzip > DBNAME.gz");

To backup all databases from a MySQL server at once you can use the --all-databases switch for mysqldump. The issue with this option though is that all databases get backed up into one .sql file. This will make it hard if you need to recover a single database as you will have to go through the backup file and try to extract only the database your want.

mysqldump --user=USER --password=PASSWORD --all-databases | gzip > DBBACKUP.gz

I have found that it is better to write a script that backs up all the databases into their own backup files. Now if you had hundreds or even thousands for databases you would want to create a script that gets all the database names and then loops through the backups. But if you one have a dozen or so you could just put multiple mysqldump commands in the script like this.

mysqldump --user=USER --password=PASSWORD DBNAME1 | gzip > DBNAME1.gz
mysqldump --user=USER --password=PASSWORD DBNAME2 | gzip > DBNAME2.gz
mysqldump --user=USER --password=PASSWORD DBNAME2 | gzip > DBNAME2.gz

After you have them backed up into gzip files you could download them via ftp, store them on another server, or backup that up to tape. This also comes in hand for moving a site from one server to another. Just transfer the db.gz file to the new server and restore the database to the new server.

To restore a database you would change the > to < in the command.

mysqldump --user=USER --password=PASSWORD < DBNAME.sql

So you could use the exec() function in a php script to restore a database like this.

exec("mysqldump --user=USER --password=PASSWORD < DBNAME.sql");




Comments

vipan kumar , 2010-05-25 15:52:48
Good very helpfull
Colin Jensen , 2010-05-25 15:52:36
Great article, I used something VERY similiar to this earlier today. It creates the .sql file and then attaches it to an email - best thing is you can schedule it as a cron job. If you are interested see here: http://www.thephpanswers.com/viewtopic.php?f=11&t=8&start=0 All source code is available :)

Article Categories