zoukankan      html  css  js  c++  java
  • Linux基础文件打包

    一、打包与解压

    (一)、打包压缩

    [root@linux ~]# tar -czf etc1.tar.gz /etc                            //-z 调用gzip
    [root@linux ~]# tar -cjf etc2.tar.bz2 /etc                            //-j  调用bzip2
    [root@linux ~]# tar -cJf etc3.tar.xz /etc                            //-J  调用xz
    [root@linux ~]# ll -h etc*
    -rw-r--r--. 1 root root 8.7M 3月  12 00:08 etc1.tar.gz
    -rw-r--r--. 1 root root 7.5M 3月  12 00:08 etc2.tar.bz2
    -rw-r--r--. 1 root root 4.8M 3月  12 00:09 etc3.tar.xz

    (二)、解压、解包

    [root@linux ~]# tar -tf sys.tar.xz
    [root@linux ~]# tar -xzvf etc1.tar.gz                
    [root@linux ~]# tar -xvf etc1.tar.gz                                    //无需指定解压工具,tar会自动判断
    [root@linux ~]# tar -xvf etc2.tar.bz2  -C /tmp                  //-C重定向到//tmp目录
    [root@linux ~]# tar xf etc3.tar.xz

    (三)、解压ZIP

    [root@linux ~]# unzip xxx.zip

    二、案例

    (一)、案例1:mysql物理备份及恢复

    [root@localhost ~]# tar -cJf /backup/mysql.tar.xz /var/lib/mysql
    [root@localhost ~]# tar -xf /backup/mysql.tar.xz -C /

    (二)、  mysql物理备份及恢复

    [root@localhost ~]# cd /var/lib/mysql
    [root@localhost mysql]# tar -cJf /backup/mysql.tar.xz *
    [root@localhost mysql]# tar -xf /backup/mysql.tar.xz -C /var/lib/mysql

    (三)案例3:host A /etc (海量小文件)

    [root@localhost ~]# tar -czf - /etc |tar -xzf - -C /tmp

    (四)、案例4:host A /etc(海量小文件)

    常规方法:
    [root@localhost ~]# scp -r /etc 172.16.20.21:/tmp

    建议方法:

    ==host B 监听端口==
    [root@hostb ~]# systemctl stop firewalld.service
    [root@hostb ~]# nc -l 8888 |tar -xzf - -C /tmp
    
    ==host A ==
    [root@localhost ~]# tar -czf - /etc | nc 172.16.20.21 8888
    tar: Removing leading `/' from member names
  • 相关阅读:
    Log4j学习
    HttpURLConnection请求
    正则表达式验证中文、图片上传
    freemarker学习
    参数中带有“&”符号问题
    禁止打印页面
    myEclipse 界面窗口打不开问题
    屏蔽网页右键
    分享功能
    table表格某一td内容太多导致样式混乱的解决方案
  • 原文地址:https://www.cnblogs.com/sky-k/p/9392814.html
Copyright © 2011-2022 走看看