cp 命令 rsync –delete 删除文件和用extundelete 恢复文件

3年前 (2016-11-10) Jason Liu 命令相关, 运维 0评论 已收录 1059℃
昨天同事让帮忙把一个目录覆盖到线上环境去
于是执行如下命令
cp -r ddbill/   /usr/local/ddbill
结果把ddbill目录复制到/usr/local/ddbill/ddbill去了
 纠结了很久
最后用cp -r ddbill/ /usr/local/  达到了想要的目的
原因:
    1、如果目标地址存在ddbill这个目录,那么执行 cp -r ddbill/   /usr/local/ddbill  这个命令就会在ddbill下面再建立一个ddbill的目录,就像这样 /usr/local/ddbill/ddbill
    2、如果目标地址不存在ddbill这个目录,那么执行 cp -r ddbill/   /usr/local/ddbill  这个命令就会把ddbill目录复制到/usr/local下面去
这里感觉有点怪怪的,于是想用rsync命令试试看是什么效果
发现rsync和cp命令复制文件还是有区别的
cp -r ddbill/ /usr/local/ddbill   和cp -r ddbill /usr/local/ddbill   功能是一样的
rsync -avzP ddbill/ /usr/local/ddbill 和 rsync -avzP ddbill  /usr/local/ddbill 功能是不一样的
ddbill带了斜线说明是把ddbill目录下面的文件同步过去
ddbill没带斜线说明是把ddbill目录同步过去
而且发现rsync同步过去只要目标地址中不存在目标中写的那个目录,都会先创建目录再复制
rsync -avzP test /tmp/test
不管在/tmp目录下有没有test目录,要同步的那个test目录都是直接放到/tmp/test/test这里去
弄完了之后又试了下rsync --delete参数,这下简直出大问题了
因为我执行了
rsync -avzP ddbill  /usr/local/
---> rsync -avzP dbill /usr/local/    意思是把ddbill目录推送到/usr/local/下面去
---> rsync -avzP ddbill/ /usr/local/ 意思是把ddbill目录下的文件推送到/usr/local/下面去
rsync  -avzP --delete ddbill/  /usr/local
结果把/usr/local/下面的文件全部删除了。。。。。
欲哭无泪呀。。。
于是去网上找了下恢复工具,顺便学习下数据恢复软件的使用。。。简直是教训呀
网上和书籍上找到了这个软件  extundelete
直接google搜索下载 然后编译安装 很简单  ./configure的时候貌似需要安装e2fs一个库包
[[email protected] ~]#  extundelete
No action specified; implying --superblock.
extundelete: Missing device name.
Usage: extundelete [options] [--] device-file
Options:
--version, -[vV]       Print version and exit successfully.
--help,                Print this help and exit successfully.
--superblock           Print contents of superblock in addition to the rest.
If no action is specified then this option is implied.
--journal              Show content of journal.
--after dtime          Only process entries deleted on or after 'dtime'.
--before dtime         Only process entries deleted before 'dtime'.
Actions:
--inode ino            Show info on inode 'ino'.
--block blk            Show info on block 'blk'.
--restore-inode ino[,ino,...]
Restore the file(s) with known inode number 'ino'.
The restored files are created in ./RECOVERED_FILES
with their inode number as extension (ie, file.12345).
--restore-file 'path'  Will restore file 'path'. 'path' is relative to root
of the partition and does not start with a '/'
The restored file is created in the current
directory as 'RECOVERED_FILES/path'.
--restore-files 'path' Will restore files which are listed in the file 'path'.
Each filename should be in the same format as an option
to --restore-file, and there should be one per line.
--restore-directory 'path'
Will restore directory 'path'. 'path' is relative to the
root directory of the file system.  The restored
directory is created in the output directory as 'path'.
--restore-all          Attempts to restore everything.
-j journal             Reads an external journal from the named file.
-b blocknumber         Uses the backup superblock at blocknumber when opening
the file system.
-B blocksize           Uses blocksize as the block size when opening the file
system.  The number should be the number of bytes.
--log 0                Make the program silent.
--log filename         Logs all messages to filename.
--log D1=0,D2=filename   Custom control of log messages with comma-separated
Examples below:       list of options.  Dn must be one of info, warn, or
--log info,error      error.  Omission of the '=name' results in messages
--log warn=0          with the specified level to be logged to the console.
--log error=filename  If the parameter is '=0', logging for the specified
level will be turned off.  If the parameter is
'=filename', messages with that level will be written
to filename.
-o directory          Save the recovered files to the named directory.
The restored files are created in a directory
named 'RECOVERED_FILES/' by default.
extundelete: Error parsing command-line options.

这个是执行命令后默认输出的帮助信息
例子:
extundelete  /dev/sda4 --restore-directory "boot"
之前/dev/sda4是挂载在/mnt下面的。里面有个boot目录
删除后要恢复boot目录 用上面的命令就可以了
extundelete /dev/sda4  --inode 2
这个命令可以查看哪些文件被删除了需要恢复

相关推荐

嗨、骚年、快来消灭0回复。