MySQL database backup to Email and to FTP Server


Database is very essential and important part of any dynamic system or application. We need to take backup of database time to time. This can be done using the user interface like phpmyadmin on regular basis and stored in a secure location.
The manual process is time consuming and there are change when you forget. We can automate this by making a php application that will backup mysql database and upload it to server using FTP and also mail the backup to user.

Process:
1) Mysql database dump can be taken using command below

mysqldump –opt -h (hostname) -u (database_userbname) –password=(database_password) )(databasename) | gzip > (filename);

This command can be executed using php function passthru() and it will generate backup file of database.

2) Now upload backup to FTP
To upload database to FTP php has some functions like ftp_connect(), ftp_login(), ftp_nb_fput(). using these function backup can be uploaded to FTP.

3) Email backup
Email backup using php function mail().

Click here to download the script.

 

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s