Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2796943
  • 博文数量: 587
  • 博客积分: 6356
  • 博客等级: 准将
  • 技术积分: 6410
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 10:54
个人简介

器量大者,福泽必厚

文章分类

全部博文(587)

文章存档

2019年(3)

2018年(1)

2017年(29)

2016年(39)

2015年(66)

2014年(117)

2013年(136)

2012年(58)

2011年(34)

2010年(50)

2009年(38)

2008年(16)

分类: Mysql/postgreSQL

2009-10-08 14:20:43

mylvmbackup备份mysql
1:我是用的vmware虚拟机做的这个实验, 另外添加了一个硬盘(做lvm)
如下所示:
[root@qht143 ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         268     2048287+  83  Linux
/dev/sda3             269         333      522112+  82  Linux swap / Solaris
/dev/sda4             334        1044     5711107+   5  Extended
/dev/sda5             334         588     2048256   83  Linux
/dev/sda6             589        1044     3662788+  83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  2:先在/dev/sdb上创建一个分区,
如下:[root@qht143 ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
然后两次回车,最后输入w, 就可以将此分区创建。 但这是普通的linux 分区, 可以看到id为83,我们需要的是lvm分区。 需要将普通的linux分区转化为lvm分区。
如下:
[root@qht143 tmp]# fdisk  /dev/sdb

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
[root@qht143 tmp]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         268     2048287+  83  Linux
/dev/sda3             269         333      522112+  82  Linux swap / Solaris
/dev/sda4             334        1044     5711107+   5  Extended
/dev/sda5             334         588     2048256   83  Linux
/dev/sda6             589        1044     3662788+  83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1305    10482381   8e  Linux LVM

显然可以看到8e(红色所示)的标记, 就表示这个是一个lvm分区
3:创建pv, 如下:
[root@qht143 tmp]# pvcreate  /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@qht143 tmp]# pvdisplay
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name              
  PV Size               10.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               0RLWGC-2iyB-e1RE-dwEw-JxhX-uwPz-5RMRWx
4:创建vg, 如下:
[root@qht143 tmp]# vgcreate mysql /dev/sdb1
  Volume group "mysql" successfully created
[root@qht143 tmp]# vgs
  VG    #PV #LV #SN Attr   VSize  VFree
  mysql   1   0   0 wz--n- 10.00G 10.00G
[root@qht143 tmp]# vgdisplay
  --- Volume group ---
  VG Name               mysql
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               10.00 GB
  PE Size               4.00 MB
  Total PE              2559
  Alloc PE / Size       0 / 0  
  Free  PE / Size       2559 / 10.00 GB
  VG UUID               dMNaiO-suC9-RJro-pm9i-NOjC-PhxL-R6PY9L
5:创建lv,如下:
[root@qht143 tmp]# lvcreate --name maindb --size 9.9G mysql
  Rounding up size to full physical extent 9.90 GB
  Logical volume "maindb" created
查看:
[root@qht143 mysql]# ll /dev/mysql/
total 0
lrwxrwxrwx 1 root root 24 Oct  8 13:48 maindb -> /dev/mapper/mysql-maindb

6:格式化分区:
[root@qht143 mysql]# mkfs.ext3 /dev/mysql/maindb
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1297920 inodes, 2595840 blocks
129792 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2659188736
80 block groups
32768 blocks per group, 32768 fragments per group
16224 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  
7:挂载:创建snap目录
   mkdir  /snap
  [root@qht143 mysql]# mount /dev/mysql/maindb  /snap
8:安装mylvmbackup工具的先决条件
必须确认是否有:
Config::IniFiles
*DBI
*DBD::mysql
*Sys::Syslog
*Date::Format

我确少Config::IniFiles 和*Date::Format

会出现错误如下:


解决方法:下载Config-Inifiles-*.tar.gz,安装方法如下图:

还有一个错误是:
Can't locate Date/Format.pm
就是因为缺少*Date::Format模块
解决方法:下载perl-TimeDate-*.noarch.rpm(*和你的os有关系)

如果缺少其他的模块, 安装方法和以上雷同!
9:安装mylvmbackup
 tar xzvf mylvmbackup-0.13.tar.gz
 cd mylvmbackup-0.11
 make install
即可将其安装。
10:修改/etc/mylvmbackup.conf文件
我的内容如下:
[mysql]
user=root
password=root
host=qht143
port=3306
socket=/tmp/mysql.sock
mycnf=/etc/my.cnf

#
# LVM-specific options
#
[lvm]
vgname=mysql
lvname=maindb
backuplv=
lvsize=2G
.......
.......
红色字体为需要修改的部分!
10:mkdir -p  /var/tmp/mylvmbackup/backup
    mkdir -p  /var/tmp/mylvmbackup/mnt
这两个和你的/etc/mylvmbackup.conf 中的 mountdir=/var/tmp/mylvmbackup/mnt/
backupdir=/var/tmp/mylvmbackup/backup/
对应即可
11:执行mylvmbackup
[root@qht143 mysql]# mylvmbackup
20091008 13:54:59 Info: Connecting to database...
20091008 13:54:59 Info: Flushing tables with read lock...
20091008 13:54:59 Info: Taking position record into /tmp/mylvmbackup-backup-20091008_135459_mysql-fXUZDB.pos...
20091008 13:54:59 Info: Running: lvcreate -s --size=2G --name=maindb_snapshot /dev/mysql/maindb
File descriptor 4 left open
  Logical volume "maindb_snapshot" created
20091008 13:55:00 Info: DONE: taking LVM snapshot
20091008 13:55:00 Info: Unlocking tables...
20091008 13:55:00 Info: Disconnecting from database...
20091008 13:55:00 Info: Mounting snapshot...
20091008 13:55:00 Info: Running: mount -o rw /dev/mysql/maindb_snapshot /var/tmp/mylvmbackup/mnt/backup
20091008 13:55:00 Info: DONE: mount snapshot
20091008 13:55:00 Info: Copying /tmp/mylvmbackup-backup-20091008_135459_mysql-fXUZDB.pos to /var/tmp/mylvmbackup/mnt/backup-pos/backup-20091008_135459_mysql.pos...
......
20091008 13:55:00 Info: DONE: create tar archive
20091008 13:55:00 Info: Cleaning up...
20091008 13:55:00 Info: Running: umount /var/tmp/mylvmbackup/mnt/backup
20091008 13:55:00 Info: DONE: Unmounting /var/tmp/mylvmbackup/mnt/backup
20091008 13:55:00 Info: LVM Usage stats:
20091008 13:55:00 Info:   LV              VG    Attr   LSize Origin Snap%  Move Log Copy%
20091008 13:55:00 Info:   maindb_snapshot mysql swi-a- 2.00G maindb   0.00               
20091008 13:55:00 Info: Running: lvremove -f /dev/mysql/maindb_snapshot
  Logical volume "maindb_snapshot" successfully removed
20091008 13:55:01 Info: DONE: Removing snapshot

在学习过程中遇到的问题,
[root@qht143 mysql]# mylvmbackup
20091008 13:53:00 Info: Connecting to database...
20091008 13:53:00 Info: Flushing tables with read lock...
20091008 13:53:00 Info: Taking position record into /tmp/mylvmbackup-backup-20091008_135259_mysql-xY3776.pos...
20091008 13:53:00 Info: Running: lvcreate -s --size=9.9G --name=maindb_snapshot /dev/mysql/maindb
File descriptor 4 left open
  Rounding up size to full physical extent 9.90 GB
  Insufficient free extents (24) in volume group mysql: 2535 required
20091008 13:53:00 Error: FAILED: taking LVM snapshot (exit status 5)
20091008 13:53:00 Info: Unlocking tables...
20091008 13:53:00 Info: Disconnecting from database...
20091008 13:53:00 Info: Cleaning up...
[root@qht143 mysql]# ls

是因为磁盘空间的问题,磁盘空间不够用所致, 所以后来我就用2G(lvcreate时)。浪费了好多的空间,这个只是个学习之用, 也没在做修改!
12:测试是否已经备份成功:


到此为止备份完成, 留为自己笔记之用!





阅读(2321) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~