一、 将磁盘分区挂载为只读

这一步很重要,并且在误删除文件后应尽快将磁盘挂载为只读。越早进行,恢复的成功机率就越大。

1.  查看被删除文件位于哪个分区

[root@localhost  ~]# mount
/dev/mapper/VolGroup-lv_root
on / type ext4(rw)
/dev/mapper/VolGroup-lv_home
on /home type ext4(rw)

2.  尝试将对应目录重新挂载为只读

[root@localhost  ~]#  mount
-r -n -o remount /home
mount: /home is busy

3.  如果显示 xxx is busy

[root@localhost  ~ ]# fuser
-v -m /data

找出相关进程,kill.

4.  成功将目录挂载为只读

[root@localhost  ~ ] #  mount
-r -n -o remount /home

此时在/home目录 touch文件时,会报错:

[root@localhost  ~ ] # touch
txt
touch: cannot touch `txt’: Read-only
file system

二、 使用数据恢复工具 extundelete

之前尝试了debugfs + dd,未果。

后来安装 extundelete-0.2.4 ,:

1.  下载

(1) 因为sourceforge被墙,服务器上直接wget不成功,所以只能在本地FQ下载,链接如下:

http://superb-dca2.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2

(2) 把下载的文件放到服务器

启动本地的nginx,然后在服务器上wget(当然通过其它方法也可以,只要能传到服务器):

wget http://本机IP/extundelete-0.2.4.tar.bz2  

(3) 解压

tar
jxf extundelete - 0 . 2 . 4 .tar.bz2

2.  编译

(1) configure

[root@localhost  extundelete-0.2.4]# ./configure

configure时报错,看了下config.log,确定是本机没编译环境 。

yum -y install gcc+ gcc-c++

等待,有一点慢。

安装完成后,再次config,依然报错

Configuring extundelete 0.2.4
configure: error: Can’t find ext2fs library

这是因为extundelete依赖e2fsprogs。

安装e2fsprogs后再次configure,成功。

[root@localhost  extundelete-0.2.4]# yum
install e2fsprogs-devel
[root@localhost  extundelete-0.2.4]#
./configure
Configuring extundelete 0.2.4
Writing generated files to disk

(2) make & make install

[root@localhost  extundelete-0.2.4]#make
& make install

如果没有异常信息,基本说明安装成功.

(3) 可以到src目录验证下.

[root@localhost  extundelete-0.2.4]#
cd src
[root@localhost  src]# ./extundelete
No action specified; implying --superblock.
./extundelete: Missing device name.
Usage: ./extundelete [options] [--] device-file
.............

 

[root@localhost  src]# ./extundelete
-v

extundelete version 0.2.4

libext2fs version 1.41.12

Processor is little endian.

如上信息,证明安装成功。

下面才真正开始数据恢复。

三、 挂载新硬盘

(如果原服务器磁盘空间够大,可以跳过这一步。)

因为被误删的数据很大(约200G),原服务器所在的物理机上也没有磁盘空间了。因些需要到远程挂载另一台服务器B上的磁盘,B是xen虚出的机器,空间也不够,但所在的物理机上还有磁盘空间,这时需要从宿主机上分空间给B。

1  在xen上挂载一块磁盘给B

因为是图形操作,就不再细说。只需分配足够大的空间就可以了,我当时选的是300G。

2  登录服务器B, 准备挂载新磁盘。

(1) 查看新磁盘是否已挂载

[nmen@dev -ubuntu-server] ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda5  /dev/sda6  /dev/sda7  /dev/sda8  /dev/sdb

/dev/sdb确实已挂载。

此时新盘是未分区,也未格式化,因此需要先进行这两件事。

(2)  分区

下图是hdb的硬盘,sdb的盘也一样的操作。

(本图来自:http://www.shyw.net/bbs/yxt443333-1-1.html)

(3)  格式化

[nmen@dev -ubuntu-server]:~$ sudo
mkfs -t ext3 /dev/sdb1
mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
22937600 inodes, 91749215 blocks
4587460 blocks (5.00%) reserved for the
super user
First data block=0
Maximum filesystem blocks=4294967296
2800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968
 
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i
to override.

显示以上信息说明已成功格式化。

(4)  设置卷标

sudo e2label /dev/sdb1 /restore

(5)  挂载

[nmen@dev -ubuntu-server]:~$
mkdir /restore
[nmen@dev  - ubuntu - server] : ~ $ mount -vl -t
ext3 /dev/sdb1 /restore

至此服务器B上挂载新硬盘结束,现在有足够空间来做存放要恢复的数据了。

四、通过NFS远程挂载

通过网络, 将远程主机B共享的文件系统,挂载到需要做数据恢复的机器A。

1. 服务器B上安装NFS

(1) 安装

B是ubuntu系统,默认没安装nfs.

#  sudo apt-get install nfs-kernel-server

(2) 配置

修改/etc/exports , 添加如下语句。


# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/restore *(rw,sync,no_root_squash,no_subtree_check)

其中 :

/restore                                                                  -- 需要与客户机共享的目录;

*                                                                            -- 表示任何主机均可访问本目录,也可指定IP;

(w,sync,no_root_squash,no_subtree_check)      -- 配置客户机的权限;

因为是临时使用,并且是服务器位于内网,所以设置相对随意。

(3) 使配置生效

#  exportfs –rv

#  /etc/init.d/nfs-kernel-server restart

(4) 验证是否配置成功

显示NFS服务器输出目录列表:

nmen@dev -ubuntu-server: showmount
-e
Export list for chinahrd-ubuntu-dev:
/restore *

(5) 防火墙

因为时间紧急,并且是内网,所以临时关闭了B上的防火墙:

sudo ufw disable

可通过以下命令启用防火墙:

sudo ufw enable

2.  服务器A上挂载远程目录

将/restore目录从服务器 B 挂载到 /mnt 上。

mount -t nfs [B的IP]:/restore  /mnt

命令详解如下:

# mount -t nfs [-o mount-options] server:/directory /mount-point
 
-o mount-options
     指定可以用来挂载 NFS 文件系统的挂载选项。
server:/directory
     指定包含共享资源的服务器主机名,以及要挂载的文件或目录的路径。
/mount-point
     指定要挂载文件系统的目录。

五、数据恢复

1.   得到删除的大概时间

这一步不是必须,但这个有助于更快的回复想要的数据。

date -d "Fri
Apr 15:40:00 2014" +%s
1397202000

1397202000这个时间值,我们后期会用到。

2.  查看被删除文件

# extundelete /dev/sdb1 --inode 2

File name                                       | Inode number | Deleted status

.                                                 9

..                                                11

lost+found                                        24             Deleted

data                                              82            
Deleted

一个分区挂载到一个目录下时,”根”目录的inode值为一般是2。

状态为deleted的是被删除的文件。

3.  数据恢复

进入刚mount的远程目录/restore;

指定--after "1397202000", 表示恢复这个时间点之后的文件;

文件默认会被恢复到当前目录下的RECOVERED_FILES目录中。

cd /restore
[root@localhost  restore]#[extundelete的安装路径]./extundelete
--restore-all --after "1397202000"/dev/mapper/VolGroup-lv_home

Only show and process deleted entries if they are deleted on or after 1397202000 and before 9223372036854775807.

NOTICE: Extended attributes are not restored.

Loading filesystem metadata ... 6924 groups loaded.

Loading journal descriptors ... 27149 descriptors loaded.

Searching for recoverable inodes in directory / ...

696 recoverable inodes found.

Looking through the directory structure for deleted files ...

Unable to restore inode 27394319 (VMware/9.50_ps/9.55locate.vmx.lck): Space has been reallocated.

Unable to restore inode 27402241 (VMware/9.35win7/9.35win7.vmx.lck): Space has been reallocated.

Unable to restore inode 27396032 (VMware/9.35win7/9.35win7-Snapshot1.vmsn): No undeleted copies found in the journal.

Unable to restore inode 27394051 (VMware/9.36win2008/9.36win2008R2.vmx.lck/E00633.lck): Space has been reallocated.

Unable to restore inode 27394603 (lost+found/E09292.lck): Space has been reallocated.

8 recoverable inodes still lost.

 

一般来说,要等很久。。。

cd restore/RECOVERED_FILES$
ls
110_open_dns  111_open_dns_node1  112_DNS_node2  116_svn

删除的文件回来了,至此松一口气。

六、收尾工作

(1) 重新挂载A上的磁盘为可读写:

[root@localhost  src]#
mount -o remount, rw /home/

卸载服务器B上的目录。

(2) 开启B的防火墙。

sudo ufw enable

(3) 在A上对rm命令启用别名,防止沉默式删除。

vi /etc/bashrc

source /etc/bashrc

 

# do not delete / or prompt if deleting more than 3 files
at a time #
alias rm='rm -I --preserve-root'  
 
# confirmation #
alias mv='mv -i'
alias cp='cp -i' alias
ln='ln -i'  
 
# Parenting changing perms on / #
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'

(4) 在B上使用Rsync,定期备份A上数据。

参考:http://abloz.com/2013/09/12/linux-rm-rf-file-recovery-record.html

linux 基本。。的更多相关文章

  1. Linux 驱动开发

    linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...

  2. Linux 内核概述 - Linux Kernel

    Linux 内核学习笔记整理. Unix unix 已有40历史,但计算机科学家仍认为其是现存操作系统中最大和最优秀的系统,它已成为一种传奇的存在,历经时间的考验却依然声名不坠. 1973 年,在用 ...

  3. 死磕内存篇 --- JAVA进程和linux内存间的大小关系

    运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...

  4. NodeJs在Linux下使用的各种问题

    环境:ubuntu16.04 ubuntu中安装NodeJs 通过apt-get命令安装后发现只能使用nodejs,而没有node命令 如果想避免这种情况请看下面连接的这种安装方式: 拓展见:Linu ...

  5. [linux]阿里云主机的免登陆安全SSH配置与思考

    公司服务器使用的第三方云端服务,即阿里云,而本地需要经常去登录到服务器做相应的配置工作,鉴于此,每次登录都要使用密码是比较烦躁的,本着极速思想,我们需要配置我们的免登陆. 一 理论概述 SSH介绍 S ...

  6. Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级

    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 5.安装Database软件 5. ...

  7. Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part1:准备工作

    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part1:准备工作 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 1.实施前准备工作 1.1 服务器安装操 ...

  8. SQL Server on Linux 理由浅析

    SQL Server on Linux 理由浅析 今天的爆炸性新闻<SQL Server on Linux>基本上在各大科技媒体上刷屏了 大家看到这个新闻都觉得非常震精,而美股,今天微软开 ...

  9. Microsoft Loves Linux

    微软新任CEO纳德拉提出的“Microsoft Loves Linux”,并且微软宣布.NET框架的开源,近期Microsoft不但宣布了Linux平台的SQL Server,还宣布了Microsof ...

  10. Linux 江湖系列阶段性总结

    引言 我使用 Linux 已经有很多年了,最开始接触 Linux 的时候是从 RedHat 9(没有 Enterprise),中途换过 N 个不同的发行版.多年前,我在 BlogJava 上面分享 J ...

随机推荐

  1. SQL Server获取指定行的数据

    SQL Server获取指定行(如第二行)的数据   --SQL Server获取指定行(如第二行)的数据-- --法一(对象法)-- select * from ( select * , numbe ...

  2. search bar 创建的一些文章

    1.   http://blog.csdn.net/oscarxie/article/details/1434608 2.   http://blog.csdn.net/oscarxie/articl ...

  3. windows 版 nginx 运行错误的一些解决方法

    1. 关于文件夹的中文的问题. 错误的截图如下: 看得到这个 failed (1113: No mapping for the Unicode character exists in the targ ...

  4. hadoop之 参数调优

    一. hdfs-site.xml 配置文件 1. dfs.blocksize 参数:hadoop文件块大小描述:新文件的默认块大小,以字节为单位,默认 134217728 字节.可以使用以下后缀(大小 ...

  5. SQL语言:DDL/DML/DQL/DCL

    SQL (Structure Query Language)语言是数据库的核心语言. SQL 的发展是从1974年开始的,其发展过程如下: 1974年-----由Boyce和Chamberlin提出, ...

  6. Angular 4.0 环境搭建

    1.安装node 2.angular cli安装 sudo npm install -g @angular/cli 3. 使用ng -v 查看安装结果 4. 创建项目 ng new helloworl ...

  7. SQL的datetime类型数据转换为字符串格式大全

    Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), GETDATE( ...

  8. Input输入控制

    1.Input只能输入正整数 <html> <head> <title>只能输入正整数</title> </head> <body&g ...

  9. Hadoop专业解决方案之构建Hadoop企业级应用

    一.大数据的挑战 大数据面对挑战是你必须重新思考构建数据分析应用的方式.传统方式的应用构建是基于数据存储在不支持大数据处理的基础之上.这主要是因为一下原因: 1.传统应用的基础设施是基于传统数据库访问 ...

  10. springMVC学习(5)-参数绑定

    接着上一集,记录参数绑定的过程: springmvc中,接收页面提交的数据是通过方法形参来接收: 一.默认支持的类型: 在controller形参中添加如下类型的参数处理适配器会默认识别并进行赋值: ...