Chinaunix首页 | 论坛 | 博客
  • 博客访问: 298360
  • 博文数量: 240
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-04 18:14
文章分类

全部博文(240)

文章存档

2017年(8)

2014年(4)

2013年(15)

2012年(4)

2011年(14)

2010年(55)

2009年(140)

我的朋友

分类: Mysql/postgreSQL

2009-05-15 22:05:34

RPM下载
文件: perl-DBD-MySQL-2.9004-3.1.x86_64.rpm
大小: 111KB
下载: 下载
    mysqlhotcopy是一个Perl脚本,最初由Tim Bunce编写并提供。它使用LOCK TABLES、FLUSH TABLES和cp或scp来快速备份数据库。它是备份数据库或单个表的最快的途径,但它只能运行在数据库目录所在的机器上。mysqlhotcopy只用于备份MyISAM。它运行在Unix和NetWare中。
 
 
与mysqldump比较:
1、前者是一个快速文件意义上的COPY,后者是一个数据库端的SQL语句集合。
2、前者只能运行在数据库目录所在的机器上,后者可以用在远程客户端,不过备份的文件还是保存在服务器上。
3、相同的地方都是在线执行 LOCK TABLES 以及 UNLOCK TABLES
4、前者恢复只需要COPY备份文件到源目录覆盖即可,后者需要导入SQL文件到原库中。(source 或 mysql < bakfile.sql)
5、前者只适用于 MyISAM 引擎,而后则则可同时使用于MyISAM引擎和InodDB引擎.
6、前者在使用前必须安装perl-DBD-mysql包,而后者则不需要.
 
 
安装 perl-DBD:

[root@WEB01 ~]# rpm -ivh mysql-4.1.22-2.el4.x86_64.rpm perl-DBD-MySQL-2.9004-3.1.x86_64.rpm

 
 
 
使用方法:
1、备份 RecordServer 整个库:

[root@WEB01 back]# mysqlhotcopy -h 192.168.0.10 -u dbadmin -p 123456 RecordServer /back

 
 
2、同时备份 RecordServer 和 SuperServer 两个库:

[root@WEB01 back]# mysqlhotcopy -h 192.168.0.10 -u dbadmin -p 123456 RecordServer SuperServer /back

 
 
3、备份RecordServer中的USER表(支持正则表达式):

[root@WEB01 back]# mysqlhotcopy -h 192.168.0.10 -u dbadmin -p 123456 RecordServer./USER*/ /back

 
 
 
备份查询:
可以将每次的备份写入数据库,日后查询备份记录.

mysql> create database hotcopy;
mysql> use hotcopy
mysql> create table checkpoint(time_stamp timestamp not null,src varchar(32),dest varchar(60), msg varchar(255));

[root@WEB01 back]# mysqlhotcopy -h 192.168.0.10 -u dbadmin -p 123456 wiki /back
--checkpoint hotcopy.checkpoint


mysql> use hotcopy
Database changed
mysql> select * from checkpoint;
+
---------------------+------+-------------+-----------+

| time_stamp | src | dest | msg |
+
---------------------+------+-------------+-----------+

| 2009-05-11 04:12:50 | wiki | /back/wiki | Succeeded |
| 2009-05-11 04:23:27 | wiki | /back/wiki | Succeeded |
| 2009-05-11 04:27:03 | wiki | /back/wiki | Succeeded |
+
---------------------+------+-------------+-----------+

 
 
 
支持选项:
[root@WEB01 back]# mysqlhotcopy --help         
/usr/bin/mysqlhotcopy Ver 1.22
Usage: /usr/bin/mysqlhotcopy db_name[./table_regex/] [new_db_name | directory]
  -?, --help           display this helpscreen and exit
  -u, --user=#         user for database login if not current user
  -p, --password=#     password to use when connecting to server (if not set
                       in my.cnf, which is recommended)
  -h, --host=#         Hostname for local server when connecting over TCP/IP
  -P, --port=#         port to use when connecting to local server with TCP/IP
  -S, --socket=#       socket to use when connecting to local server
  --allowold           don't abort if target dir already exists (rename it _old)
  --addtodest          don't rename target dir if it exists, just add files to it
  --keepold            don't delete previous (now renamed) target when done
  --noindices          don't include full index files in copy
  --method=#           method for copy (only "cp" currently supported)
  -q, --quiet          be silent except for errors
  --debug              enable debug
  -n, --dryrun         report actions without doing them
  --regexp=#           copy all databases with names matching regexp
  --suffix=#           suffix for names of copied databases
  --checkpoint=#       insert checkpoint entry into specified db.table
  --flushlog           flush logs once all tables are locked
  --resetmaster        reset the binlog once all tables are locked
  --resetslave         reset the master.info once all tables are locked
  --tmpdir=#           temporary directory (instead of /tmp)
  --record_log_pos=#   record slave and master status in specified db.table
  --chroot=#           base directory of chroot jail in which mysqld operates
  Try 'perldoc /usr/bin/mysqlhotcopy' for more complete documentation
 
 
 
选项解释:
·---help
显示帮助消息并退出。
 
·--allowold
如果目标存在不放弃(加上一个_old后缀重新命名它)。
·--checkpoint=db_name.tbl_name
在指定的db_name.tbl_name插入检查点条目。
·---debug
启用调试输出。
 
·--dryrun,-n
报告动作而不执行它们。
·--flushlog
所有表锁定后刷新日志。
 
·--keepold
完成后不删除以前(重新命名的)的目标。
·-- method=command
复制方法(cp或scp)。
 
·--noindices
备份中不包括全部索引文件。这样使备份更小、更快。可以在以后用myisamchk -rq重新构建索引。
·--password=password,-p password
当连接服务器时使用的密码。请注意该选项的密码值是不可选的,不象其它MySQL程序。
 
·--port=port_num,-P port_num
当连接本地服务器时使用的TCP/IP端口号。
·--quiet,-q
除了出现错误时保持沉默。
 
·--regexp=expr
复制所有数据库名匹配给出的正则表达式的数据库。
·--socket=path,-S path
用于连接的Unix套接字文件。
 
·--suffix=str
所复制的数据库名的后缀。
·--tmpdir=path
临时目录(代替/tmp)。
 
·--user=user_name,-u user_name
当连接服务器时使用的MySQL用户名.要想执行mysqlhotcopy,你必须可以访问备份的表文件,具有那些表的
SELECT权限和RELOAD权限(以便能够执行FLUSH TABLES).
 
阅读(1620) | 评论(0) | 转发(0) |
0

上一篇:/dev/shm 设备空间不足

下一篇:点击率和PV

给主人留下些什么吧!~~