当前位置: 首页 > article >正文

linux中cpio文件如何,linux cpio命令的使用

linux cpio命令的使用

cpio -o  > [file|device] <==备份

cpio -i  < [file|device] <==还原

-o :将数据 copy 输出到档案或装置上

-i :将数据自档案或装置 copy 出来系统当中

-t :查看 cpio 建立的档案或装置的内容

-c :一种较新的 portable format 方式储存

-v :让储存的过程中文件名称可以在屏幕上显示

-B :让预设的 Blocks 可以增加至 5120 bytes ,预设是 512 bytes !

这样的好处是可以让大档案的储存速度加快(请参考 i-nodes 的观念)

-d :自动建立目录!由于 cpio 的内容可能不是在同一个目录内,

如此的话在反备份的过程会有问题! 这个时候加上 -d 的话,

就可以自动的将需要的目录建立起来了!

-u :自动的将较新的档案覆盖较旧的档案!

准备数据

[root@node1 tmp]# ll

total 104

-rw-r--r-- 1 root root     8 Jan 13 12:35 test

-rw-r--r-- 1 root root  3071 Jan 13 12:13 top.bak

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak1

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak2

-rw-r--r-- 1 root root 21473 Jan 13 12:02 top.bak3

-rw-r--r-- 1 root root 21473 Jan 13 12:34 top.txt

[root@node1 tmp]# mkdir abc

[root@node1 tmp]# ll

total 108

drwxr-xr-x 2 root root  4096 Jan 13 12:35 abc

-rw-r--r-- 1 root root     8 Jan 13 12:35 test

-rw-r--r-- 1 root root  3071 Jan 13 12:13 top.bak

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak1

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak2

-rw-r--r-- 1 root root 21473 Jan 13 12:02 top.bak3

-rw-r--r-- 1 root root 21473 Jan 13 12:34 top.txt

[root@node1 tmp]# cd abc

[root@node1 abc]# echo "hello cpio" > abc1.txt

[root@node1 abc]# ll

total 4

-rw-r--r-- 1 root root 11 Jan 13 12:35 abc1.txt

[root@node1 tmp]# pwd

/tmp

[root@node1 tmp]# ll

total 108

drwxr-xr-x 2 root root  4096 Jan 13 12:35 abc

-rw-r--r-- 1 root root     8 Jan 13 12:35 test

-rw-r--r-- 1 root root  3071 Jan 13 12:13 top.bak

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak1

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak2

-rw-r--r-- 1 root root 21473 Jan 13 12:02 top.bak3

-rw-r--r-- 1 root root 21473 Jan 13 12:34 top.txt

1、使用cpio备份

[root@node1 tmp]# cpio -ov top.bak > top.bak.cpio  --cpio不支持直接写入文件名,需要使用ls或echo或find或

cpio: Too many arguments

1)使用ls

[root@node1 tmp]# ls top.bak1 top.bak2

top.bak1  top.bak2

[root@node1 tmp]# ls top.bak1 top.bak2 | cpio -ov > top.bak12.cpio

top.bak1

top.bak2

85 blocks

[root@node1 tmp]# cpio -tv < top.bak12.cpio  --查看 cpio 建立的档案或装置的内容

-rw-r--r--   1 root     root        21473 Jan 13 12:22 top.bak1

-rw-r--r--   1 root     root        21473 Jan 13 12:22 top.bak2

85 blocks

2)使用echo

[root@node1 tmp]# echo top.bak | cpio -ov > top.bak.rel.cpio  --相对路径的备份

top.bak

7 blocks

[root@node1 tmp]# echo /tmp/top.bak | cpio -ov > top.bak.abs.cpio --绝对路径的备份

/tmp/top.bak

7 blocks

[root@node1 tmp]# cpio -tv < top.bak.rel.cpio

-rw-r--r--   1 root     root         3071 Jan 13 12:13 top.bak

7 blocks

[root@node1 tmp]# cpio -tv < top.bak.abs.cpio

cpio: Removing leading `/' from member names

-rw-r--r--   1 root     root         3071 Jan 13 12:13 tmp/top.bak

7 blocks

3)使用find

[root@node1 tmp]# find /tmp -name abc1.txt

/tmp/abc/abc1.txt

[root@node1 tmp]# find /tmp -name abc1.txt -print

/tmp/abc/abc1.txt

[root@node1 tmp]# find /tmp -name abc1.txt | cpio -ov > abc1.txt.cpio

/tmp/abc/abc1.txt

1 block

4)使用

[root@node1 tmp]# cat test

top.txt

[root@node1 tmp]# cpio -ov < test > top.txt.cpio

top.txt

43 blocks

[root@node1 tmp]# cpio -tv <  top.txt.cpio

-rw-r--r--   1 root     root        21473 Jan 13 12:34 top.txt

43 blocks

2、使用cpio恢复

[root@node1 dev]# cd /tmp

[root@node1 tmp]# ll

total 164

drwxr-xr-x 2 root root  4096 Jan 13 12:35 abc

-rw-r--r-- 1 root root   512 Jan 13 12:37 abc1.txt.cpio

-rw-r--r-- 1 root root     8 Jan 13 12:35 test

-rw-r--r-- 1 root root  3071 Jan 13 12:13 top.bak

-rw-r--r-- 1 root root  3584 Jan 13 12:36 top.bak.abs.cpio

-rw-r--r-- 1 root root     0 Jan 13 12:36 top.bak.cpio

-rw-r--r-- 1 root root  3584 Jan 13 12:36 top.bak.rel.cpio

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak1

-rw-r--r-- 1 root root 43520 Jan 13 12:36 top.bak12.cpio

-rw-r--r-- 1 root root 21473 Jan 13 12:22 top.bak2

-rw-r--r-- 1 root root 21473 Jan 13 12:02 top.bak3

-rw-r--r-- 1 root root 21473 Jan 13 12:34 top.txt

[root@node1 /]# pwd

/

[root@node1 /]# mkdir tmp2

[root@node1 /]# cd /tmp2

[root@node1 tmp2]# cpio -iv < /tmp/top.bak.rel.cpio

top.bak

7 blocks

[root@node1 tmp2]# ll

total 4

-rw-r--r-- 1 root root 3071 Jan 13 12:38 top.bak

[root@node1 tmp2]# cpio -iv < /tmp/top.bak.abs.cpio

cpio: Removing leading `/' from member names ---------------------注意这里,不使用绝对路径

cpio: tmp/top.bak: No such file or directory

tmp/top.bak

7 blocks

[root@node1 tmp2]# ll

total 4

-rw-r--r-- 1 root root 3071 Jan 13 12:38 top.bak

--由于/tmp2下没有tmp目录,所以报错,未恢复成功

[root@node1 tmp2]# cpio -idv < /tmp/top.bak.abs.cpio   --加上-d自动创建目录

cpio: Removing leading `/' from member names

tmp/top.bak

7 blocks

[root@node1 tmp2]# ll

total 8

drwxr-xr-x 2 root root 4096 Jan 13 12:39 tmp

-rw-r--r-- 1 root root 3071 Jan 13 12:38 top.bak

[root@node1 tmp2]# cpio -iv < /tmp/abc1.txt.cpio

cpio: Removing leading `/' from member names

cpio: tmp/abc/abc1.txt: No such file or directory

tmp/abc/abc1.txt

1 block

[root@node1 tmp2]# cpio -idv < /tmp/abc1.txt.cpio

cpio: Removing leading `/' from member names

tmp/abc/abc1.txt

1 block

加上--absolute-filenames参数使用绝对路径来恢复

[root@node1 tmp]# pwd

/tmp

[root@node1 tmp]# rm -f top.bak

[root@node1 tmp2]# pwd

/tmp2

[root@node1 tmp2]# cpio -iv --absolute-filenames < /tmp/top.bak.abs.cpio

/tmp/top.bak

7 blocks

[root@node1 tmp2]# cpio -iv --absolute-filenames < /tmp/top.bak.abs.cpio

cpio: /tmp/top.bak not created: newer or same age version exists

/tmp/top.bak

7 blocks

[root@node1 tmp2]# cpio -uiv --absolute-filenames < /tmp/top.bak.abs.cpio  --加上-u参数自动的将较新的档案覆盖较旧的档案

/tmp/top.bak

7 blocks

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26524307/viewspace-1071207/,如需转载,请注明出处,否则将追究法律责任。

http://www.lryc.cn/news/2414684.html

相关文章:

  • ElasticSearch学习篇10_Lucene数据存储之BKD动态磁盘树(论文Bkd-Tree: A Dynamic Scalable kd-Tree)
  • Unity ECS小知识1 - PhysicsTrigger Event
  • 利用Interceptor拦截NetKeeper账户:技术创新与实用性探析
  • 稳压二极管和雪崩二极管的工作原理及选型学习总结
  • Android UI 详解之ToggleButton按钮和Swith按钮
  • 怎么在桌面上嵌入窗口(使用FindWindow(),FindWindowEx(),EnumChildWindows())
  • ADODB用法详解
  • 去掉字符串首尾逗号_去除字符串首尾空格和特殊字符
  • C/C++数据结构课程设计(15题)[2023-10-29]
  • 致敬mentohust,路由器使用Socket认证华科校园网
  • Python 中如何使用 @property
  • 使用TerminateProcess结束进程时,错误码为5的解决方法
  • 常量指针与指针常量的区别
  • 信道估计(channel estimation)图解——从SISO到MIMO原理介绍
  • tbody标签的作用介绍
  • CreateEvent的理解
  • 短剧小程序源码|小程序短剧平台源码搭建
  • background属性介绍
  • [翻译] LaTeX 中的列表
  • 内存地址的计算方法
  • ROS2 学习笔记(一)新建项目的基础流程
  • 分享个好用的开源录屏工具 Captura
  • 高速收发器之发送器详解(Transmitter)
  • 计算机程序设计艺术 介绍
  • CreateMutex创建互斥内核对象
  • 目前最受欢迎的12个Python web框架,你用过几个?
  • SqlCommand.ExecuteNonQuery()方法的使用注意
  • Delicatessen音乐名词什么意思
  • Tribon二次开发-COM接口的使用(抽取数据)
  • 全球免费公共 DNS 解析服务器 IP 地址列表推荐 (解决无法上网/加速/防劫持)