机房一台监控服务器由于但是系统规划有问题,var、 tmp等目录都在/目录下面,由于var目录数据比较多,导致/分区空间不够使用,但是系统还剩下将近100G空间没有,因此考虑迁移var同时考虑到为了以后空间能自由变动我们使用LVM来扩展var。
原来分区如下
[ITIproject:root@netmon rhcl6]# fdisk -l
Disk /dev/sda: 145.9 GB, 145999527936 bytes
255 heads, 63 sectors/track, 17750 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 514048+ 83 Linux
/dev/sda2 65 1339 10241437+ 83 Linux
/dev/sda3 1340 2614 10241437+ 83 Linux
/dev/sda4 2615 17750 121579920 5 Extended
/dev/sda5 2615 3634 8193118+ 82 Linux swap / Solaris
[ITIproject:root@netmon rhcl6]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 9.5G 8.3G 733M 93% /
/dev/sda2 9.5G 2.5G 6.6G 27% /usr
/dev/sda1 487M 16M 446M 4% /boot
tmpfs 4.0G 0 4.0G 0% /dev/shm
/dev/scd4 2.8G 2.8G 0 100% /mnt
[ITIproject:root@netmon rhcl6]# df -h /var /tmp
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 9.5G 8.3G 733M 93% /
/dev/sda3 9.5G 8.3G 733M 93% /
二.创建lvm
空余空间创建分区sda6使用fidisk过程省略
完成后如下:
[ITIproject:root@netmon rhcl6]# fdisk -l /dev/sda
Disk /dev/sda: 145.9 GB, 145999527936 bytes
255 heads, 63 sectors/track, 17750 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 514048+ 83 Linux
/dev/sda2 65 1339 10241437+ 83 Linux
/dev/sda3 1340 2614 10241437+ 83 Linux
/dev/sda4 2615 17750 121579920 5 Extended
/dev/sda5 2615 3634 8193118+ 82 Linux swap / Solaris
/dev/sda6 3635 17750 113386738+ 83 Linux
1. 创建pv
pvcreate --help
pvcreate /dev/sda6
pvscan
[ITIproject:root@netmon rhcl6]# pvdisplay
-- Physical volume --
PV Name /dev/sda6
VG Name vg
PV Size 108.13 GB / not usable 1.24 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 27682
Free PE 16162
Allocated PE 11520
PV UUID dw2Fzv-Jy36-j3MY-2boP-AyOy-VaWi-Luxh8m
1. 创建vg
vgcreate --help
vgcreate vg /dev/sda6
vgdisplay
1. 创建lv
lvcreate --help
lvcreate -L 15G -n var vg
lvcreate -L 30G -n data vg
[ITIproject:root@netmon rhcl6]# lvdisplay
-- Logical volume --
LV Name /dev/vg/var
VG Name vg
LV UUID zs9vyK-o4rp-sFdY-wxXM-UQR0-5c39-cgP4UF
LV Write Access read/write
LV Status available
1. open 1
LV Size 15.00 GB
Current LE 3840
Segments 1
Allocation inherit
Read ahead sectors auto
* currently set to 256
Block device 253:0
o
+ Logical volume --
LV Name /dev/vg/data
VG Name vg
LV UUID PRG4c4-EmSr-C2b7-Br5V-1nq7-WUif-10ICod
LV Write Access read/write
LV Status available
1. open 1
LV Size 30.00 GB
Current LE 7680
Segments 1
Allocation inherit
Read ahead sectors auto
* currently set to 256
Block device 253:1
1. 格式化lv
mkfs.ext3 /dev/mapper/vg-var
mkfs.ext3 /dev/mapper/vg-data
1. 手动挂载vg-var到/var1
[ITIproject:root@netmon rhcl6]# mkdir /var1
[ITIproject:root@netmon rhcl6]# mount /dev/mapper/vg-var /var1
[ITIproject:root@netmon rhcl6]# df -h /var1 /var
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-data 30G 173M 28G 1% /var1
/dev/sda3 9.5G 8.3G 733M 93% /
1. 手挂载vg-data到data目录作为临时目录
[ITIproject:root@netmon rhcl6]# mkdir /data
[ITIproject:root@netmon rhcl6]# mount /dev/mapper/vg-data /data
三.迁移
var迁移方法比较多可以使用cp(不推荐使用)、可以使用链接ln或者使用dump\restore,这里我们使用dump\restore来完成
使用dump备份var到data目录
[ITIproject:root@netmon data]# dump -0 -f /data/var.dump /var
DUMP: Date of this level 0 dump: Wed Jan 19 11:34:07 2011
DUMP: Dumping /dev/sda3 (/ (dir var)) to /data/var.dump
DUMP: Label: /
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [ITIproject:regular files]
DUMP: mapping (Pass II) [ITIproject:directories]
DUMP: estimated 8271984 blocks.
DUMP: Volume 1 started with block 1 at: Wed Jan 19 11:34:08 2011
DUMP: dumping (Pass III) [ITIproject:directories]
DUMP: dumping (Pass IV) [ITIproject:regular files]
DUMP: 26.81% done at 7393 kB/s, finished in 0:13
DUMP: 52.68% done at 7263 kB/s, finished in 0:08
DUMP: 79.91% done at 7344 kB/s, finished in 0:03
DUMP: Closing /data/var.dump
DUMP: Volume 1 completed at: Wed Jan 19 11:52:55 2011
DUMP: Volume 1 8312500 blocks (8117.68MB)
DUMP: Volume 1 took 0:18:47
DUMP: Volume 1 transfer rate: 7375 kB/s
DUMP: 8312500 blocks (8117.68MB) on 1 volume(s)
DUMP: finished in 1127 seconds, throughput 7375 kBytes/sec
DUMP: Date of this level 0 dump: Wed Jan 19 11:34:07 2011
DUMP: Date this dump completed: Wed Jan 19 11:52:55 2011
DUMP: Average transfer rate: 7375 kB/s
DUMP: DUMP IS DONE
查看备份文件
[ITIproject:root@netmon data]# du -sh var.dump
8.0G var.dump
恢复备份到var1目录
[ITIproject:root@netmon data]# restore -rf /data/
lost+found/ var.dump
[ITIproject:root@netmon data]# restore -rf /data/var.dump /var1
./lost+found: (inode 11) not found on tape
./usr: (inode 2171873) not found on tape
./boot: (inode 1134561) not found on tape
./sys: (inode 162081) not found on tape
./proc: (inode 1069729) not found on tape
./.autofsck: (inode 97249) not found on tape
./tmp: (inode 1426305) not found on tape
./dev: (inode 2269121) not found on tape
./etc: (inode 2139457) not found on tape
./root: (inode 1037313) not found on tape
./selinux: (inode 2236705) not found on tape
./bin: (inode 194497) not found on tape
./home: (inode 129665) not found on tape
./lib: (inode 421409) not found on tape
./media: (inode 226913) not found on tape
./mnt: (inode 2204289) not found on tape
./opt: (inode 1977377) not found on tape
./sbin: (inode 388993) not found on tape
./srv: (inode 1847713) not found on tape
./misc: (inode 2009793) not found on tape
./net: (inode 64833) not found on tape
./data: (inode 648322) not found on tape
./var1: (inode 680737) not found on tape
restore: ./var/run/cups/certs/0: EA set system.posix_acl_access: failed: Operation not supported
restore interrupted, continue? [ITIproject:yn] y
查看var1目录以及后续工作
[ITIproject:root@netmon var1]# ls
restoresymtable var var.dump
[ITIproject:root@netmon var1]# rm -rf var.dump
[ITIproject:root@netmon var1]# mv var/* .
[ITIproject:root@netmon var1]# ls
account db games local mail opt restoresymtable tmp yp
cache empty gdm lock net-snmp preserve run var
cvs ftp lib log nis racoon spool www
卸载var1,修改fstab实现自动挂载vg-var
[ITIproject:root@netmon var1]# cd /
[ITIproject:root@netmon /]# umount /var1
[ITIproject:root@netmon /]# vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/usr /usr ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
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-sda5 swap swap defaults 0 0
/dev/mapper/vg-data /data ext3 defaults 0 0
/dev/mapper/vg-var /var ext3 defaults 0 0
[ITIproject:root@netmon /]# mount -a
[ITIproject:root@netmon /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 9.5G 8.4G 662M 93% /
/dev/sda2 9.5G 2.5G 6.6G 27% /usr
/dev/sda1 487M 16M 446M 4% /boot
tmpfs 4.0G 0 4.0G 0% /dev/shm
sunrpc 15G 8.1G 6.0G 58% /var/lib/nfs/rpc_pipefs
/dev/scd1 2.8G 2.8G 0 100% /media
/dev/scd2 2.8G 2.8G 0 100% /media
/dev/scd3 2.8G 2.8G 0 100% /media
/dev/scd4 2.8G 2.8G 0 100% /mnt
/dev/scd5 2.8G 2.8G 0 100% /media
/dev/mapper/vg-data 30G 8.1G 20G 29% /data
/dev/mapper/vg-var 15G 8.1G 6.0G 58% /var
重新启动服务器测试
lang110 于 2013-01-31 19:44:04发表:
谢谢分享啊,怎么长!
tan0620 于 2011-08-11 15:46:56发表:
感谢分享
tan0620 于 2011-08-11 15:45:33发表:
感谢分享
sxmt1999 于 2011-03-16 10:33:01发表:
对!
要是的0的话就是全备,其他文件小就没有必要增量,恢复起来麻烦。
emilangel 于 2011-03-15 13:00:37发表:
请问恢复时生成的restoresymtable这个文件,是做用什么用处的,在网上查说是用于增量的,如果每天都是全0备份恢复的话,是否可以删除呢。
sxmt1999 于 2011-03-14 10:31:26发表:
谢谢emilangel指教~~~
我上面的步骤有一下问题
如果我们需要把备份的文件还原到指定的文件中,那么我们需要进入到指定的文件中,然后使用restore命令就行了
restore -rf 备份
sxmt1999 于 2011-03-14 08:37:24发表:
./lost+found: (inode 11) not found on tape
./usr: (inode 2171873) not found on tape
./boot: (inode 1134561) not found on tape
./sys: (inode 162081) not found on tape
./proc: (inode 1069729) not found on tape
./.autofsck: (inode 97249) not found on tape
./tmp: (inode 1426305) not found on tape
./dev: (inode 2269121) not found on tape
./etc: (inode 2139457) not found on tape
./root: (inode 1037313) not found on tape
./selinux: (inode 2236705) not found on tape
./bin: (inode 194497) not found on tape
./home: (inode 129665) not found on tape
./lib: (inode 421409) not found on tape
./media: (inode 226913) not found on tape
./mnt: (inode 2204289) not found on tape
./opt: (inode 1977377) not found on tape
./sbin: (inode 388993) not found on tape
./srv: (inode 1847713) not found on tape
./misc: (inode 2009793) not found on tape
./net: (inode 64833) not found on tape
./data: (inode 648322) not found on tape
./var1: (inode 680737) not found on tape
这个信息是正常的,因为我没有还原这些目录
emilangel 于 2011-03-12 21:43:39发表:
求助:(自己做实验有点不太明白)
第一步:我想把emilangel这个目录备份,执行如下命令:
[root@nanji home]# ls
emilangel svnuser
[root@nanji home]# dump -0f emilangel.dump emilangel
DUMP: Date of this level 0 dump: Thu Dec 2 19:23:02 2010
DUMP: Dumping /dev/mapper/VolGroup00-LogVol00 (/ (dir home/emilangel)) to emilangel.dump
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 600 blocks.
DUMP: Volume 1 started with block 1 at: Thu Dec 2 19:23:02 2010
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing emilangel.dump
DUMP: Volume 1 completed at: Thu Dec 2 19:23:03 2010
DUMP: Volume 1 600 blocks (0.59MB)
DUMP: Volume 1 took 0:00:01
DUMP: Volume 1 transfer rate: 600 kB/s
DUMP: 600 blocks (0.59MB) on 1 volume(s)
DUMP: finished in 1 seconds, throughput 600 kBytes/sec
DUMP: Date of this level 0 dump: Thu Dec 2 19:23:02 2010
DUMP: Date this dump completed: Thu Dec 2 19:23:03 2010
DUMP: Average transfer rate: 600 kB/s
DUMP: DUMP IS DONE
[root@nanji home]# ls
emilangel emilangel.dump svnuser
[root@nanji home]#
应该是成功了吧?
第二步:我打算在home目录下建立一个data1文件夹,把dump备份还原到data1文件夹下
[root@nanji home]# mkdir data1
[root@nanji home]# ls
data1 emilangel emilangel.dump svnuser
[root@nanji home]# restore -rf emilangel.dump data1
./lost+found: (inode 11) not found on tape
./boot: (inode 786433) not found on tape
./sys: (inode 589825) not found on tape
./proc: (inode 1179649) not found on tape
./dev: (inode 1114113) not found on tape
./etc: (inode 2228225) not found on tape
./.autorelabel: (inode 98305) not found on tape
./var: (inode 917505) not found on tape
./tmp: (inode 1212417) not found on tape
./root: (inode 1441793) not found on tape
./selinux: (inode 622593) not found on tape
./lib: (inode 2162689) not found on tape
./usr: (inode 1998849) not found on tape
./bin: (inode 2260993) not found on tape
./home/svnuser: (inode 267702) not found on tape
./home/.svn: (inode 270135) not found on tape
./media: (inode 950273) not found on tape
./mnt: (inode 196609) not found on tape
./opt: (inode 1900545) not found on tape
./sbin: (inode 557057) not found on tape
./srv: (inode 262145) not found on tape
./misc: (inode 1933313) not found on tape
./.autofsck: (inode 98306) not found on tape
./net: (inode 425993) not found on tape
./data1: (inode 1376257) not found on tape
./svn: (inode 1048587) not found on tape
./restoresymtable: (inode 98307) not found on tape
[root@nanji home]# ls
data1 emilangel emilangel.dump home restoresymtable svnuser
[root@nanji home]# ls -l data1
total 0
[root@nanji home]# ls -l home
total 4
drwxr-xr-x 3 emilangel emilangel 4096 Sep 8 07:27 emilangel
[root@nanji home]#
可是还原时确还原在当前目录,并没有还原到我指定的目录,而且还原的目录为在home目录下的/home/emilangel。并且多出一个文件 restoresymtable 不知是什么用处,谢谢楼主能帮忙看一下吗?
emilangel 于 2011-03-12 21:27:38发表:
./lost+found: (inode 11) not found on tape
./usr: (inode 2171873) not found on tape
./boot: (inode 1134561) not found on tape
./sys: (inode 162081) not found on tape
./proc: (inode 1069729) not found on tape
./.autofsck: (inode 97249) not found on tape
./tmp: (inode 1426305) not found on tape
./dev: (inode 2269121) not found on tape
./etc: (inode 2139457) not found on tape
./root: (inode 1037313) not found on tape
./selinux: (inode 2236705) not found on tape
./bin: (inode 194497) not found on tape
./home: (inode 129665) not found on tape
./lib: (inode 421409) not found on tape
./media: (inode 226913) not found on tape
./mnt: (inode 2204289) not found on tape
./opt: (inode 1977377) not found on tape
./sbin: (inode 388993) not found on tape
./srv: (inode 1847713) not found on tape
./misc: (inode 2009793) not found on tape
./net: (inode 64833) not found on tape
./data: (inode 648322) not found on tape
./var1: (inode 680737) not found on tape
这些信息显示的是正常的吗?刚学习DUMP,可以生成解DUMP文件,但用restore恢复时会出现如上信息,发现在楼主也出错这种信息,想问一下是否正常?
cwnlinux 于 2011-03-12 15:45:35发表:
不错。。支持一下。。
theset 于 2011-03-11 21:17:58发表:
对这个不是很了解,补一下
pallana 于 2011-03-11 20:10:04发表:
技术活,看1.2.3步骤就是了,具体的就复杂了
tiany524 于 2011-03-11 19:06:13发表:
这么复杂 没看懂呢