Linux LVM 备份MySQL 数据库

[root@rhel5 ~]# fdisk -l 


Disk /dev/sda: 68.7 GB, 68719476736 bytes
255 heads, 63 sectors/track, 8354 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        7831    62902476   83  Linux
/dev/sda2            7832        8353     4192965   82  Linux swap / Solaris


Disk /dev/sdb: 34.3 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Disk /dev/sdb doesn't contain a valid partition table






[root@rhel5 ~]# fdisk -l /dev/sdb


Disk /dev/sdb: 34.3 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        4177    33551721    5  Extended
/dev/sdb5               1         499     4008154+  8e  Linux LVM
/dev/sdb6             500         998     4008186   8e  Linux LVM
/dev/sdb7             999        1497     4008186   8e  Linux LVM
/dev/sdb8            1498        1996     4008186   8e  Linux LVM


[root@rhel5 ~]# pvcreate /dev/sdb5 
  Writing physical volume data to disk "/dev/sdb5"
  Physical volume "/dev/sdb5" successfully created
[root@rhel5 ~]# pvcreate /dev/sdb6 /dev/sdb7 /dev/sdb8
  Writing physical volume data to disk "/dev/sdb6"
  Physical volume "/dev/sdb6" successfully created
  Writing physical volume data to disk "/dev/sdb7"
  Physical volume "/dev/sdb7" successfully created
  Writing physical volume data to disk "/dev/sdb8"
  Physical volume "/dev/sdb8" successfully created
  
  
[root@rhel5 ~]# vgcreate data /dev/sdb5 /dev/sdb6 /dev/sdb7 /dev/sdb8 
  Volume group "data" successfully created
  
  
[root@rhel5 ~]# lvcreate -n lvdata -L 4096M data
  Logical volume "lvdata" created
  


[root@rhel5 ~]# mkfs.ext3 /dev/data/lvdata 


[root@rhel5 ~]# mount /dev/data/lvdata /data 
[root@rhel5 ~]# df -h 
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda1              59G  4.7G   51G   9% /
tmpfs                 501M     0  501M   0% /dev/shm
/dev/mapper/data-lvdata
                      4.0G  137M  3.7G   4% /data


[root@rhel5 ~]# /etc/init.d/mysql stop
[mysql@rhel5 data]$ cd /usr/local/mysql/data 
[mysql@rhel5 data]$ cp -r * /data/
[root@rhel5 ~]# /etc/init.d/mysql start




[root@rhel5 ~]# more /etc/fstab 
LABEL=/                 /                       ext3    defaults        1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda2         swap                    swap    defaults        0 0
/dev/mapper/data-lvdata /data ext3 defaults 0 0




(root@localhost) [(none)]>flush tables with read lock
    -> ;
Query OK, 0 rows affected (0.00 sec)


(root@localhost) [(none)]>show master status\G
*************************** 1. row ***************************
             File: mysql-binlog.000013
         Position: 120
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)




lvcreate -n lvbackup -L 4096M -s /dev/data/lvdata 


mount /dev/data/lvdata /backup_data


(root@localhost) [(none)]> unlock table;




[root@rhel5 ~]# tar -cvzf full_20140623.tar.gz /backup_data


[root@rhel5 /]# rm -rf /backup_data/*


[root@rhel5 /]# umount /backup_data/


[root@rhel5 /]# echo "y" | lvremove /dev/data/lvbackup

你可能感兴趣的:(MySQL)