镜像 PHP/MySQL 设置的正确方法 [英] Right way to mirror a PHP/MySQL setup

查看:58
本文介绍了镜像 PHP/MySQL 设置的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了我的第一个 PHP/MySQL 站点,并且正在考虑创建数据库的镜像以进行备份.这是当然的,以防某些黑客设法窥探并破坏主数据库.这样做有对还是错?

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?

是的,我在其他主机上有一个托管计划,我希望将镜像放置在其中.

Yes, I have a hosting plan in some other host that I'd like the mirror to be placed in.

推荐答案

mysql 数据库的备份主要有两种方式:cold(static/offline) backup &热(动态/在线)备份.

There are mainly two ways for backing up your mysql databases: cold(static/offline) backup & hot(dynamic/online) backup.

1 每天/每周/每月等使用 crontab 脚本备份您的数据库.我们称之为冷备份.脚本可能是这样的:

1 Using a crontab script backup your db every day/week/month, etc. We call it cold backup. The script maybe like this:

!#/bin/sh
mysqldump -usample_name -S/tmp/sample.sock --databases db1 db2 > db_backup_time.sql

你可以在这里找到mysqldump的手册.实际上,整个 chp.6 都在谈论数据库备份和恢复.在此之后,您将每天获得数据的镜像(例如早上 6 点).

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 使用 mysql 复制解决方案(master-从属结构)用于在线备份.所有在 master 上导致数据修改的查询也将在 slave 上执行.

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.

比较:

基本上,冷备份更容易.但是当发生不好的事情时,第一种方法只能将数据恢复到您转储镜像时的数据.借助热备份和mysqldump工具,您可以将数据恢复到任何时候.

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:

  1. 每天早上写镜子,并且,
  2. 在另一台物理机器上构建 master db 的 slave.

这样就安全了.

这篇关于镜像 PHP/MySQL 设置的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆