BHARATH RAJ
BHARATH RAJ

Reputation: 69

how to backup data in MySQL database automatically everyday to cloud

I have designed a web application and connected to MySQL database. Now i want to backup my data in the database automatically everyday as my data in database changes everday. When I have tried mysqldump through command line and export option through workbench i can only able to backup table structure but not data in it.

please someone tell me how to backup my data everyday to the cloud.any help is appreciated

Upvotes: 2

Views: 7256

Answers (1)

Himel Nag Rana
Himel Nag Rana

Reputation: 744

You can use a simple php script + crontab to do that.

I am sharing a sample code for dumping data in csv format (you can change this to any format you want by changing the given regular expression in the commands):

exec('mysql -B -u '.$dbUser.' -p'.$dbPassword.' '.$dbName.' -h '.$dbHost.' -e "SELECT * FROM user;" | sed "s/\t/,/g" > '.$uploadPath.'user.csv');

exec('mysql -B -u '.$dbUser.' -p'.$dbPassword.' '.$dbName.' -h '.$dbHost.' -e "SELECT * FROM profile;" | sed "s/\t/,/g" > '.$uploadPath.'profile.csv');

---
---
---

Configure / generate the $uploadPath dynamically (for example: /var/log/yourApp/20160406/) in your script.

Run the script everyday with crontab (assuming you are on linux server):

1 0 * * * /usr/bin/php /var/www/yourscript.php

Everyday at 12.01am your script will run the data will be backed up.

Upvotes: 1

Related Questions