zoukankan      html  css  js  c++  java
  • 文件备份与压缩

    . tar

      将多个文件打包在一起,,并可以实现解压打包的文件

      -z    # 通过gzip压缩或解压

      -c    # 创建新的jar包

      -v    # 显示tar命令执行过程

      -f    # 指定文件压缩名字

      -t     # 不解压查看压缩包内容

      -p    # 保持稳健的原有属性

      -P    # 以绝对路径打包,危险参数

      --exclude=PATTERN  # 打包时排除不需要处理的文件或目录

      -h    # 打包软连接文件指向的

      -j    # bzip2命令压缩或解压

      -x    # 加压tar包

      -C    # 解压到指定目录

      --hard-derefrence  #打包硬链接文件

    [root@mysql-141 ~]# mkdir -p /test
    [root@mysql-141 ~]# touch /test/{01..10}.txt
    [root@mysql-141 ~]# ls /test/{01..10}.txt
    /test/01.txt  /test/03.txt  /test/05.txt  /test/07.txt  /test/09.txt
    /test/02.txt  /test/04.txt  /test/06.txt  /test/08.txt  /test/10.txt
    [root@mysql-141 ~]# cd /test/
    [root@mysql-141 ~]# tar zvf test.tar.gz /test/
    [root@mysql-141 test]# tar ztvf test.tar.gz  -C /tmp/
    [root@mysql-141 test]# tar zcvf www.tar.gz ./html/ --exclude=test/A
    [root@mysql-141 test]# tar zxf test.tar.gz  

    . gzip

      将一个大文件通过压缩算法变成一个小文件,gzip命令不能直接压缩目录,因此需要先用tar打包成一个文件,然后tar再调用gzip进行压缩

      -d  # 加开压缩文件

      -v  # 显示指令执行的过程

      -l  # 列出压缩文件的内容消息

      -c  # 将内容输出到标准输出,不改变原始文件

      -r  # 将目录下的所有文件递归进行压缩操作

      -t  # 测试,检查压缩文件是否完整

    [root@mysql-141 test]# ls
    01.txt  03.txt  05.txt  07.txt  09.txt
    02.txt  04.txt  06.txt  08.txt  10.txt
    [root@mysql-141 test]# gzip *.txt
    [root@mysql-141 test]# ls
    01.txt.gz  03.txt.gz  05.txt.gz  07.txt.gz  09.txt.gz
    02.txt.gz  04.txt.gz  06.txt.gz  08.txt.gz  10.txt.gz
    [root@mysql-141 test]# gzip -l *.gz
             compressed        uncompressed  ratio uncompressed_name
                     27                   0   0.0% 01.txt
                     27                   0   0.0% 02.txt
                     27                   0   0.0% 03.txt
                     27                   0   0.0% 04.txt
                     27                   0   0.0% 05.txt
                     27                   0   0.0% 06.txt
                     27                   0   0.0% 07.txt
                     27                   0   0.0% 08.txt
                     27                   0   0.0% 09.txt
                     27                   0   0.0% 10.txt
    [root@mysql-141 test]# echo >11.txt
    [root@mysql-141 test]# ls
    01.txt.gz  03.txt.gz  05.txt.gz  07.txt.gz  09.txt.gz  11.txt
    02.txt.gz  04.txt.gz  06.txt.gz  08.txt.gz  10.txt.gz
    [root@mysql-141 test]# gzip -c 11.txt >11.txt.gz     # 压缩保留源文件
    [root@mysql-141 test]# ls
    01.txt.gz  03.txt.gz  05.txt.gz  07.txt.gz  09.txt.gz  11.txt
    02.txt.gz  04.txt.gz  06.txt.gz  08.txt.gz  10.txt.gz  11.txt.gz

    . unzip

      unzip命令可以解压zip命令或其他压缩软件压缩的zip格式的文件

      

    . scp

      在不同主机之间复制文件,采用ssh协议来保证复制的安全性,scp命令每次都是全量复制,效率不高 

      scp [options]  [[user@]host1:]file1 ... [[user@]host2:]file2

      -C    # 压缩传输

      -l    # 指定传输占用的带宽

      -P port  # 指定端口号传输

      -p    # 传输后保留文件的原始属性

      -q    # 不显示传输进度条

      -r    # 递归复制整个目录

    [root@mysql-141 ~]# ll /etc/services 
    -rw-r--r-- 1 root root 641020 Apr 17 09:27 /etc/services
    [root@mysql-141 ~]# scp /etc/services 10.0.0.201:/tmp     # 推送文件到远程服务器
    The authenticity of host '10.0.0.201 (10.0.0.201)' can't be established
    .
    RSA key fingerprint is 67:e7:85:b7:bf:4a:01:8c:98:98:87:98:64:27:46:d4.Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '10.0.0.201' (RSA) to the list of known host
    s.
    root@10.0.0.201's password: 
    services                             100%  626KB 626.0KB/s   00:00
    
    [root@centos7 ~]# ll /tmp/services 
    -rw-r--r-- 1 root root 641020 Apr 18 13:46 /tmp/services
    
    
    [root@centos7 ~]# touch /tmp/scp.txt    # 远程服务器创建文件
    [root@mysql-141 ~]# scp -rp 10.0.0.201:/tmp/scp.txt /tmp/    # 通过远程服务器拉取文件到本地
    root@10.0.0.201's password: 
    scp.txt                              100%    0     0.0KB/s   00:00    
    [root@mysql-141 ~]# ls /tmp/scp.txt -l
    -rw-r--r-- 1 root root 0 Apr 18 13:50 /tmp/scp.txt

    . rsync

      可以实现全量以及增量的本地或远程数据镜像同步备份的优秀工具,适用于多种操作系统平台

      本身是一个C/S模式服务,被xinetd管理端口

      rsync有三种常见模式:

      1)本地模式      # 数据的传输和cp命类似,一般av参数常用

        rsync [OPTION...] SRC... [DEST]

                 源文件  目标文件

      2)守护进程模式   # 

        Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
                    用户@主机::源文件  目标文件
        Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
                   源文件  用户@主机::目标文件

      3)远程shell模式访问   # 类似scp命令,只不过需要制定用户和主机名  

        Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]

                  用户@主机:源文件   目标文件
        Push: rsync [OPTION...] SRC... [USER@]HOST:DEST    

                  源文件     用户@主机:目标文件

      

      -v  # 详细模式输出进度信息

      -z  # 传输时进行压缩以提高传输效率

      -a  # 以递归方式传输文件,并保持所有文件的属性

      -r  # 对子目录以递归模式传输

      -l  # 保留软连接

      -n  # 测试选项,模拟执行

      --exclude=PATTERN  # 指定排除不需要传输的文件模式

      --exclude-from=file  #从文本文件中读取要排除的文件列表

      --bwlimit=KBPS    # 限制传输速度

      --deldete        # 使目标目录内容和源目录保持一致,删除不同的文件

    [root@centos7 ~]# rsync -av 10.0.0.141:/tmp/passwd.out /tmp
    The authenticity of host '10.0.0.141 (10.0.0.141)' can't be established.
    RSA key fingerprint is SHA256:jYke6mtF+s2Hm5yhAOqJbZuM6aMMlZl+XJ3Ada7f0Zk.
    RSA key fingerprint is MD5:e0:33:96:70:07:e4:bf:c6:c8:a5:2e:86:9b:6b:2d:62.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '10.0.0.141' (RSA) to the list of known hosts.
    root@10.0.0.141's password: 
    receiving incremental file list
    passwd.out
    
    sent 30 bytes  received 266 bytes  45.54 bytes/sec
    total size is 183  speedup is 0.62
    [root@centos7 ~]# ls -l /tmp/passwd.out 
    -rw-r--r-- 1 root root 183 Apr 17 13:21 /tmp/passwd.out
  • 相关阅读:
    LeetCode 842. Split Array into Fibonacci Sequence
    LeetCode 1087. Brace Expansion
    LeetCode 1219. Path with Maximum Gold
    LeetCode 1079. Letter Tile Possibilities
    LeetCode 1049. Last Stone Weight II
    LeetCode 1046. Last Stone Weight
    LeetCode 1139. Largest 1-Bordered Square
    LeetCode 764. Largest Plus Sign
    LeetCode 1105. Filling Bookcase Shelves
    LeetCode 1027. Longest Arithmetic Sequence
  • 原文地址:https://www.cnblogs.com/flashfish/p/10729379.html
Copyright © 2011-2022 走看看