I just created my very first PHP/MySQL site and was looking into creating a mirror of the db for backup. This is of course, in case some hacker manages to go snooping and wrecks the main db. Is there a right or wrong way of doing this?
Edit: Yes, I have a hosting plan in some other host that I’d like the mirror to be placed in.
There are mainly two ways for backing up your mysql databases: cold(static/offline) backup & hot(dynamic/online) backup.
1 Using a crontab script backup your db every day/week/month, etc. We call it cold backup. The script maybe like this:
you can find manual of mysqldump here. Actually, the whole chp.6 is talking about database backup and recovery. After this, you’ll get the mirror of your data(eg. 6am.) every day.
2 Using mysql replication solutions(master-slave structure) for online backup. All the queries on master leading to data modifications will also performed on slave.
comparation:
Basicly, cold backup is easier. But when bad things happen, first method can only recover the data to the time you dumping the mirror. With hot backup and mysqldump tool, you can recover the data to anytime.
In my experience, we always compose these two methods together:
that would be safe.