场景: 在挂载磁盘前忘记把之前目录下的文件(或者隐藏文件)拷出来,目前新数据盘已有服务在使用,无法停服执行umount卸载操作。
实验演示:
代码语言:txt复制
# 在/mnt下创建几个文件和文件夹,模拟老的数据
[root@VM-30-16-centos ~]# cd /mnt/
[root@VM-30-16-centos ~]# touch old1 old2
[root@VM-30-16-centos ~]# mkdir old3 old4
# 格式化一块硬盘,并挂载到/mnt路径下,覆盖掉原先的文件
[root@VM-30-16-centos ~]# mkfs.ext4 /dev/vdb
[root@VM-30-16-centos ~]# mount /dev/vdb /mnt/
# 可以看到新的数据盘挂载了,里面只有个默认的lost found文件夹
[root@VM-30-16-centos ~]# ll /mnt/
total 16
drwx------ 2 root root 16384 Aug 29 15:18 lost found
# 创建一个临时挂载点,将之前的盘挂载到这个临时挂载点上
[root@VM-30-16-centos ~]# mkdir /home/recover_old_data
[root@VM-30-16-centos ~]# mount /dev/vda1 /home/recover_old_data
[root@VM-30-16-centos ~]# cd /home/recover_old_data/
[root@VM-30-16-centos recover_old_data]# ll
total 80
lrwxrwxrwx. 1 root root 7 Mar 7 2019 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 Jul 8 21:55 boot
drwxr-xr-x 2 root root 4096 Nov 5 2019 data
drwxr-xr-x. 2 root root 4096 Mar 7 2019 dev
drwxr-xr-x. 86 root root 4096 Aug 29 15:13 etc
drwxr-xr-x. 3 root root 4096 Aug 29 15:23 home
lrwxrwxrwx. 1 root root 7 Mar 7 2019 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Mar 7 2019 lib64 -> usr/lib64
drwx------. 2 root root 16384 Mar 7 2019 lost found
drwxr-xr-x. 2 root root 4096 Apr 11 2018 media
drwxr-xr-x. 4 root root 4096 Aug 29 15:17 mnt
drwxr-xr-x. 3 root root 4096 Mar 7 2019 opt
drwxr-xr-x. 2 root root 4096 Mar 7 2019 proc
dr-xr-x---. 6 root root 4096 Jul 8 21:55 root
drwxr-xr-x. 2 root root 4096 Mar 7 2019 run
lrwxrwxrwx. 1 root root 8 Mar 7 2019 sbin -> usr/sbin
drwxr-xr-x. 2 root root 4096 Apr 11 2018 srv
drwxr-xr-x. 2 root root 4096 Mar 7 2019 sys
drwxrwxrwt. 9 root root 4096 Aug 29 15:23 tmp
drwxr-xr-x. 13 root root 4096 Mar 7 2019 usr
drwxr-xr-x. 19 root root 4096 Mar 7 2019 var
# 可以看到之前创建的文件了
[root@VM-30-16-centos recover_old_data]# cd mnt/
[root@VM-30-16-centos mnt]# ll
total 8
-rw-r--r-- 1 root root 0 Aug 29 15:17 old1
-rw-r--r-- 1 root root 0 Aug 29 15:17 old2
drwxr-xr-x 2 root root 4096 Aug 29 15:17 old3
drwxr-xr-x 2 root root 4096 Aug 29 15:17 old4
# 将文件拷贝出来
[root@VM-30-16-centos mnt]# mkdir -pv /tmp/abc
[root@VM-30-16-centos mnt]# cp -a * /tmp/abc/
# 从临时挂载点卸载掉刚才的盘
[root@VM-30-16-centos mnt]# cd
[root@VM-30-16-centos ~]# umount /dev/vda1
# 删除临时挂载点
[root@VM-30-16-centos ~]# rm -fr /home/recover_old_data