一cpio的介绍
功能:复制文件从或到归档
cpio命令是通过重定向的方式将文件进行打包备份,还原恢复的工具,它可以解压以“.cpio”或者“.tar”结尾的文件。
cpio [选项] > 文件名或者设备名
cpio [选项] < 文件名或者设备名
选项
-o 将文件拷贝打包成文件或者将文件输出到设备上
-i 解包,将打包文件解压或将设备上的备份还原到系统
-t 预览,查看文件内容或者输出到设备上的文件内容
-v 显示打包过程中的文件名称。
-d 解包生成目录,在cpio还原时,自动的建立目录
-c 一种较新的存储方式
二cpio的使用
(一)-o 将文件拷贝打包成文件或者将文件输出到设备上
将etc目录备份:
[[email protected] ~]# ls /app/etc/ -ld drwxr-xr-x 3 root root 23 May 3 10:59 /app/etc/ [[email protected] ~]# find /app/etc/ /app/etc/ /app/etc/sysconfig /app/etc/sysconfig/ip6tables-config /app/etc/sysconfig/iptables-config /app/etc/sysconfig/cbq /app/etc/sysconfig/cbq/avpkt /app/etc/sysconfig/cbq/cbq-0000.example /app/etc/sysconfig/rdisc /app/etc/sysconfig/console /app/etc/sysconfig/init /app/etc/sysconfig/modules /app/etc/sysconfig/netconsole /app/etc/sysconfig/network-scripts /app/etc/sysconfig/network-scripts/ifcfg-lo /app/etc/sysconfig/network-scripts/ifdown-bnep /app/etc/sysconfig/network-scripts/ifdown-eth /app/etc/sysconfig/network-scripts/ifdown-ippp /app/etc/sysconfig/network-scripts/ifdown-ipv6 /app/etc/sysconfig/network-scripts/ifdown-isdn /app/etc/sysconfig/network-scripts/ifdown-post /app/etc/sysconfig/network-scripts/ifdown-ppp /app/etc/sysconfig/network-scripts/ifdown-routes /app/etc/sysconfig/network-scripts/ifdown-sit /app/etc/sysconfig/network-scripts/ifdown-tunnel /app/etc/sysconfig/network-scripts/ifup-aliases /app/etc/sysconfig/network-scripts/ifup-bnep /app/etc/sysconfig/network-scripts/ifup-eth /app/etc/sysconfig/network-scripts/ifup-ippp /app/etc/sysconfig/network-scripts/ifup-ipv6 /app/etc/sysconfig/network-scripts/ifup-isdn /app/etc/sysconfig/network-scripts/ifup-plip /app/etc/sysconfig/network-scripts/ifup-plusb /app/etc/sysconfig/network-scripts/ifup-post /app/etc/sysconfig/network-scripts/ifup-ppp /app/etc/sysconfig/network-scripts/ifup-routes /app/etc/sysconfig/network-scripts/ifup-sit /app/etc/sysconfig/network-scripts/ifup-tunnel /app/etc/sysconfig/network-scripts/ifup-wireless /app/etc/sysconfig/network-scripts/init.ipv6-global /app/etc/sysconfig/network-scripts/network-functions /app/etc/sysconfig/network-scripts/network-functions-ipv6 /app/etc/sysconfig/network-scripts/ifdown-Team /app/etc/sysconfig/network-scripts/ifdown-TeamPort /app/etc/sysconfig/network-scripts/ifup-Team /app/etc/sysconfig/network-scripts/ifup-TeamPort /app/etc/sysconfig/network-scripts/ifcfg-ens33 /app/etc/sysconfig/network-scripts/ifcfg-ens37 /app/etc/sysconfig/network-scripts/ifup /app/etc/sysconfig/network-scripts/ifdown /app/etc/sysconfig/Readonly-root /app/etc/sysconfig/crond /app/etc/sysconfig/run-parts /app/etc/sysconfig/wpa_supplicant /app/etc/sysconfig/ebtables-config /app/etc/sysconfig/irqbalance /app/etc/sysconfig/man-db /app/etc/sysconfig/rsyslog /app/etc/sysconfig/firewalld /app/etc/sysconfig/kdump /app/etc/sysconfig/sshd /app/etc/sysconfig/authconfig /app/etc/sysconfig/cpupower /app/etc/sysconfig/kernel /app/etc/sysconfig/network /app/etc/sysconfig/anaconda /app/etc/sysconfig/chronyd /app/etc/sysconfig/ntpdate /app/etc/sysconfig/ntpd /app/etc/sysconfig/keepalived /app/etc/sysconfig/ipvsadm-config /app/etc/sysconfig/Nginx /app/etc/sysconfig/Nginx-deBUG /app/etc/sysconfig/htcacheclean /app/etc/sysconfig/httpd /app/etc/sysconfig/grub /app/etc/sysconfig/selinux
通过管道传输给cpio,并且把文件重定向到一个文件里面
[[email protected] ~]# find /app/etc/ | cpio -ov > /app/etc.cpio /app/etc/ /app/etc/sysconfig /app/etc/sysconfig/ip6tables-config /app/etc/sysconfig/iptables-config /app/etc/sysconfig/cbq /app/etc/sysconfig/cbq/avpkt /app/etc/sysconfig/cbq/cbq-0000.example /app/etc/sysconfig/rdisc /app/etc/sysconfig/console /app/etc/sysconfig/init /app/etc/sysconfig/modules /app/etc/sysconfig/netconsole /app/etc/sysconfig/network-scripts /app/etc/sysconfig/network-scripts/ifcfg-lo /app/etc/sysconfig/network-scripts/ifdown-bnep /app/etc/sysconfig/network-scripts/ifdown-eth /app/etc/sysconfig/network-scripts/ifdown-ippp /app/etc/sysconfig/network-scripts/ifdown-ipv6 /app/etc/sysconfig/network-scripts/ifdown-isdn /app/etc/sysconfig/network-scripts/ifdown-post /app/etc/sysconfig/network-scripts/ifdown-ppp /app/etc/sysconfig/network-scripts/ifdown-routes /app/etc/sysconfig/network-scripts/ifdown-sit /app/etc/sysconfig/network-scripts/ifdown-tunnel /app/etc/sysconfig/network-scripts/ifup-aliases /app/etc/sysconfig/network-scripts/ifup-bnep /app/etc/sysconfig/network-scripts/ifup-eth /app/etc/sysconfig/network-scripts/ifup-ippp /app/etc/sysconfig/network-scripts/ifup-ipv6 /app/etc/sysconfig/network-scripts/ifup-isdn /app/etc/sysconfig/network-scripts/ifup-plip /app/etc/sysconfig/network-scripts/ifup-plusb /app/etc/sysconfig/network-scripts/ifup-post /app/etc/sysconfig/network-scripts/ifup-ppp /app/etc/sysconfig/network-scripts/ifup-routes /app/etc/sysconfig/network-scripts/ifup-sit /app/etc/sysconfig/network-scripts/ifup-tunnel /app/etc/sysconfig/network-scripts/ifup-wireless /app/etc/sysconfig/network-scripts/init.ipv6-global /app/etc/sysconfig/network-scripts/network-functions /app/etc/sysconfig/network-scripts/network-functions-ipv6 /app/etc/sysconfig/network-scripts/ifdown-Team /app/etc/sysconfig/network-scripts/ifdown-TeamPort /app/etc/sysconfig/network-scripts/ifup-Team /app/etc/sysconfig/network-scripts/ifup-TeamPort /app/etc/sysconfig/network-scripts/ifcfg-ens33 /app/etc/sysconfig/network-scripts/ifcfg-ens37 /app/etc/sysconfig/network-scripts/ifup /app/etc/sysconfig/network-scripts/ifdown /app/etc/sysconfig/Readonly-root /app/etc/sysconfig/crond /app/etc/sysconfig/run-parts /app/etc/sysconfig/wpa_supplicant /app/etc/sysconfig/ebtables-config /app/etc/sysconfig/irqbalance /app/etc/sysconfig/man-db /app/etc/sysconfig/rsyslog /app/etc/sysconfig/firewalld /app/etc/sysconfig/kdump /app/etc/sysconfig/sshd /app/etc/sysconfig/authconfig /app/etc/sysconfig/cpupower /app/etc/sysconfig/kernel /app/etc/sysconfig/network /app/etc/sysconfig/anaconda /app/etc/sysconfig/chronyd /app/etc/sysconfig/ntpdate /app/etc/sysconfig/ntpd /app/etc/sysconfig/keepalived /app/etc/sysconfig/ipvsadm-config /app/etc/sysconfig/Nginx /app/etc/sysconfig/Nginx-deBUG /app/etc/sysconfig/htcacheclean /app/etc/sysconfig/httpd /app/etc/sysconfig/grub /app/etc/sysconfig/selinux 348 blocks
对比文件的大小
[[email protected] ~]# ls /app/etc.cpio /app/etc.cpio [[email protected] ~]# ls /app/etc.cpio -lh -rw-r--r-- 1 root root 174K May 3 11:51 /app/etc.cpio [[email protected] ~]# du -sh /app/etc 368K /app/etc [[email protected] ~]# du -sh /app/etc/ 368K /app/etc/
[[email protected] ~]# du -sh /app/etc/sysconfig/ 368K /app/etc/sysconfig/ [[email protected] ~]# du -sh /app/etc/sysconfig 368K /app/etc/sysconfig [[email protected] ~]# tree /app/etc /app/etc └── sysconfig ├── anaconda ├── authconfig ├── cbq │ ├── avpkt │ └── cbq-0000.example ├── chronyd ├── console ├── cpupower ├── crond ├── ebtables-config ├── firewalld ├── grub -> ../default/grub ├── htcacheclean ├── httpd ├── init ├── ip6tables-config ├── iptables-config ├── ipvsadm-config ├── irqbalance ├── kdump ├── keepalived ├── kernel ├── man-db ├── modules ├── netconsole ├── network ├── network-scripts │ ├── ifcfg-ens33 │ ├── ifcfg-ens37 │ ├── ifcfg-lo │ ├── ifdown -> ../../../usr/sbin/ifdown │ ├── ifdown-bnep │ ├── ifdown-eth │ ├── ifdown-ippp │ ├── ifdown-ipv6 │ ├── ifdown-isdn -> ifdown-ippp │ ├── ifdown-post │ ├── ifdown-ppp │ ├── ifdown-routes │ ├── ifdown-sit │ ├── ifdown-Team │ ├── ifdown-TeamPort │ ├── ifdown-tunnel │ ├── ifup -> ../../../usr/sbin/ifup │ ├── ifup-aliases │ ├── ifup-bnep │ ├── ifup-eth │ ├── ifup-ippp │ ├── ifup-ipv6 │ ├── ifup-isdn -> ifup-ippp │ ├── ifup-plip │ ├── ifup-plusb │ ├── ifup-post │ ├── ifup-ppp │ ├── ifup-routes │ ├── ifup-sit │ ├── ifup-Team │ ├── ifup-TeamPort │ ├── ifup-tunnel │ ├── ifup-wireless │ ├── init.ipv6-global │ ├── network-functions │ └── network-functions-ipv6 ├── Nginx ├── Nginx-deBUG ├── ntpd ├── ntpdate ├── rdisc ├── Readonly-root ├── rsyslog ├── run-parts ├── selinux -> ../selinux/config ├── sshd └── wpa_supplicant 5 directorIEs,70 files
(二)内容预览
-t 预览,查看文件内容或者输出到设备上的文件内容
[[email protected] ~]# cpio -tv < /app/etc.cpiodrwxr-xr-x 3 root root 0 May 3 10:59 /app/etc/ drwxr-xr-x 6 root root 0 May 2 14:46 /app/etc/sysconfig -rw------- 1 root root 2393 Nov 5 01:03 /app/etc/sysconfig/ip6tables-config -rw------- 1 root root 2374 Nov 5 01:03 /app/etc/sysconfig/iptables-config drwxr-xr-x 2 root root 0 Jan 13 00:15 /app/etc/sysconfig/cbq -rw-r--r-- 1 root root 11 Apr 11 2018 /app/etc/sysconfig/cbq/avpkt -rw-r--r-- 1 root root 79 Apr 11 2018 /app/etc/sysconfig/cbq/cbq-0000.example -rw-r--r-- 1 root root 15 Aug 4 2017 /app/etc/sysconfig/rdisc drwxr-xr-x 2 root root 0 Oct 31 2018 /app/etc/sysconfig/console -rw-r--r-- 1 root root 798 Oct 31 2018 /app/etc/sysconfig/init drwxr-xr-x 2 root root 0 Oct 31 2018 /app/etc/sysconfig/modules -rw-r--r-- 1 root root 634 Oct 31 2018 /app/etc/sysconfig/netconsole drwxr-xr-x 2 root root 0 May 2 14:45 /app/etc/sysconfig/network-scripts -rw-r--r-- 1 root root 254 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifcfg-lo -rwxr-xr-x 1 root root 654 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-bnep -rwxr-xr-x 1 root root 6532 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-eth -rwxr-xr-x 1 root root 781 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-ippp -rwxr-xr-x 1 root root 4540 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-ipv6 lrwxrwxrwx 1 root root 11 May 2 14:45 /app/etc/sysconfig/network-scripts/ifdown-isdn -> ifdown-ippp -rwxr-xr-x 1 root root 2130 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-post -rwxr-xr-x 1 root root 1068 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-ppp -rwxr-xr-x 1 root root 870 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-routes -rwxr-xr-x 1 root root 1456 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-sit -rwxr-xr-x 1 root root 1462 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifdown-tunnel -rwxr-xr-x 1 root root 12415 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-aliases -rwxr-xr-x 1 root root 910 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-bnep -rwxr-xr-x 1 root root 13475 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-eth -rwxr-xr-x 1 root root 12075 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-ippp -rwxr-xr-x 1 root root 11893 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-ipv6 lrwxrwxrwx 1 root root 9 May 2 14:45 /app/etc/sysconfig/network-scripts/ifup-isdn -> ifup-ippp -rwxr-xr-x 1 root root 650 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-plip -rwxr-xr-x 1 root root 1064 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-plusb -rwxr-xr-x 1 root root 4997 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-post -rwxr-xr-x 1 root root 4154 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-ppp -rwxr-xr-x 1 root root 2001 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-routes -rwxr-xr-x 1 root root 3303 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-sit -rwxr-xr-x 1 root root 2711 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-tunnel -rwxr-xr-x 1 root root 1836 Aug 24 2018 /app/etc/sysconfig/network-scripts/ifup-wireless -rwxr-xr-x 1 root root 5419 Aug 24 2018 /app/etc/sysconfig/network-scripts/init.ipv6-global -rw-r--r-- 1 root root 20671 Aug 24 2018 /app/etc/sysconfig/network-scripts/network-functions -rw-r--r-- 1 root root 31027 Aug 24 2018 /app/etc/sysconfig/network-scripts/network-functions-ipv6 -rwxr-xr-x 1 root root 1621 Mar 18 2017 /app/etc/sysconfig/network-scripts/ifdown-Team -rwxr-xr-x 1 root root 1556 Mar 18 2017 /app/etc/sysconfig/network-scripts/ifdown-TeamPort -rwxr-xr-x 1 root root 1755 Mar 18 2017 /app/etc/sysconfig/network-scripts/ifup-Team -rwxr-xr-x 1 root root 1876 Mar 18 2017 /app/etc/sysconfig/network-scripts/ifup-TeamPort -rw-r--r-- 1 root root 206 Apr 15 17:16 /app/etc/sysconfig/network-scripts/ifcfg-ens33 -rw-r--r-- 1 root root 210 Apr 15 17:18 /app/etc/sysconfig/network-scripts/ifcfg-ens37 lrwxrwxrwx 1 root root