前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux笔记04

Linux笔记04

原创
作者头像
用户7271996
发布2023-03-04 15:59:29
4410
发布2023-03-04 15:59:29
举报
文章被收录于专栏:c

压缩

代码语言:javascript
复制
1.gzip 
压缩
[root@localhost ~]# gzip -v 1.txt
1.txt:     50.7% -- replaced with 1.txt.gz
gzip -9 -c 1.txt > 1.txt.gz以最佳比例压缩1.txt,并保留源文件

解压
gzip -d 1.txt.gz
代码语言:javascript
复制
2.zcat 查看压缩以前的内容
[root@localhost ~]# zcat 1.txt.gz
hhkkjkkjskjkjkjkbjbsbjbkjbkjjbjbjkbjbjbbjkbjbjbjbjbjbjbkbjbjbbjbkjbjbjbj
代码语言:javascript
复制
3.zgrep
zgrep -n 'h' 1.txt.gz  在1.txt.gz中查找h

代码语言:javascript
复制
1.bzip
[root@localhost ~]# bzip2 -v 1.txt
  1.txt:    1.177:1,  6.795 bits/byte, 15.07% saved, 73 in, 62 out.
[root@localhost ~]# bzcat 1.txt.bz2
hhkkjkkjskjkjkjkbjbsbjbkjbkjjbjbjkbjbjbbjkbjbjbjbjbjbjbkbjbjbbjbkjbjbjbj
[root@localhost ~]# bzip2 -d 1.txt.bz2
[root@localhost ~]# bzip2 -9 -c 1.txt > 1.txt.bz2

代码语言:javascript
复制
1.[root@localhost ~]# xz -v 1.txt
1.txt (1/1)
  100 %                 96 B / 73 B = 1.315                                    
[root@localhost ~]# xz -l 1.txt.xz
Strms  Blocks   Compressed Uncompressed  Ratio  Check   Filename
    1       1         96 B         73 B  1.315  CRC64   1.txt.xz
[root@localhost ~]# xzcat 1.txt.xz
hhkkjkkjskjkjkjkbjbsbjbkjbkjjbjbjkbjbjbbjkbjbjbjbjbjbjbkbjbjbbjbkjbjbjbj
[root@localhost ~]# xz -d 1.txt.xz
[root@localhost ~]# xz -k 1.txt

2.tar tar -jcv -f filename.tar.bz2 要被压缩的文件或目录名 tar -jtv -f filename.tar.bz2 查询 | grep ' ' tar -jxv -f filename.tar.bz2 -C 与解压的目录 解压

1)打包时排除特定文件 tar -Pczvf /usr/local/web.tar.gz /usr/local/web/* --exclude=/usr/local/web/catalina,log 2)打包时排除特定类型文件 tar -Pczvf /usr/local/web.tar.gz /usr/local/web/* --exclude=/usr/local/web/catalina.* tar -Pczvf /usr/local/web.tar.gz /usr/local/web/* --exclude=*.log tar zcvf nginx.tar.gz /opt/nginx/ --exclude *.jpg --exclude *.png --exclude *.dat --exclude=/opt/nginx/logs 3)打包时排除特定目录: tar -Pczvf /usr/local/web.tar.gz /usr/local/web/* --exclude=/usr/local/web/log //目录后面不要加斜杠 “/” 4)打包时排除多个目录: tar -Pczvf /usr/local/web.tar.gz /usr/local/web/* --exclude=/usr/local/web/log --exclude=/usr/local/web/doc

---------------------------------------------------------------------------------------------

XFS文件系统的备份与还原

xfsdump只能备份已挂载的文件系统 (支持增量备份)

必须root权限

只能备份xfs文件系统

只能备份独立的文件系统如/boot

代码语言:javascript
复制
[root@localhost ~]# xfsdump -l 0 -L boot_all -M boot_all -f /srv/boot.dump /boot
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of localhost.localdomain:/boot
xfsdump: dump date: Tue Feb 28 20:08:31 2023
xfsdump: session id: 8681e7c5-7117-4b9a-b7b9-2fb53ee775af
xfsdump: session label: "boot_all"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 147826304 bytes
xfsdump: /var/lib/xfsdump/inventory created
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 147506784 bytes
xfsdump: dump size (non-dir files) : 147265168 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /srv/boot.dump OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost ~]# ll /srv/boot.dump
-rw-r--r--. 1 root root 147506784 2月  28 20:08 /srv/boot.dump

代码语言:javascript
复制
[root@localhost ~]# xfsdump -I   查看xfsdump备份记录
file system 0:
    fs id:        9fb05e6e-a44e-4827-8419-3f1330fdaabc
    session 0:
        mount point:    localhost.localdomain:/boot
        device:        localhost.localdomain:/dev/sda1
        time:        Tue Feb 28 20:08:31 2023
        session label:    "boot_all"
        session id:    8681e7c5-7117-4b9a-b7b9-2fb53ee775af
        level:        0
        resumed:    NO
        subtree:    NO
        streams:    1
        stream 0:
            pathname:    /srv/boot.dump
            start:        ino 69 offset 0
            end:        ino 1577745 offset 0
            interrupted:    NO
            media files:    1
            media file 0:
                mfile index:    0
                mfile type:    data
                mfile size:    147506784
                mfile start:    ino 69 offset 0
                mfile end:    ino 1577745 offset 0
                media label:    "boot_all"
                media id:    7672496e-604b-449e-aa5e-0688d0a2658e
xfsdump: Dump Status: SUCCESS

xfsdump -l 1 -L boot_2 -M boot_2 -f /srv/boot.dump1 /boot 建立差异备份即增量备份

XFS文件系统还原

xfsrestore -I查看备份文件

1. xfsrestore -f /srv/boot.dump -L boot_all /boot 直接将数据给它覆盖回去

2. 将备份文件在/tmp/boot下面解开

mkdir /tmp/boot

xfsrestore -f /srv/boot.dump -L boot_all /tmp/boot

比较两个文件目录的不同 diff -r /boot /tmp/boot

diff

执行如下命令,比较test1.txt文件和test2.txt文件,以并排格式输出。

diff test1.txt test2.txt -y -W 50

3.仅恢复备份文件内的group2到 /tmp/boot2

mkdir /tmp/boot2

xfsrestore -f /srv/boot.dump -L boot_all -s group2 /tmp/boot2

4.恢复增量备份数据

xfsrestore -f /srv/boot.dump1 /tmp/boot

5.恢复部分备份数据

代码语言:javascript
复制
[root@localhost ~]# xfsrestore -f /srv/boot.dump -i /tmp/boot3
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description: 
xfsrestore: hostname: localhost.localdomain
xfsrestore: mount point: /boot
xfsrestore: volume: /dev/sda1
xfsrestore: session time: Tue Feb 28 20:08:31 2023
xfsrestore: level: 0
xfsrestore: session label: "boot_all"
xfsrestore: media label: "boot_all"
xfsrestore: file system id: 9fb05e6e-a44e-4827-8419-3f1330fdaabc
xfsrestore: session id: 8681e7c5-7117-4b9a-b7b9-2fb53ee775af
xfsrestore: media id: 7672496e-604b-449e-aa5e-0688d0a2658e
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 11 directories and 337 entries processed
xfsrestore: directory post-processing

========================== subtree selection dialog ==========================

代码语言:javascript
复制
the following commands are available:
    pwd 
    ls [ <path> ]
    cd [ <path> ]
    add [ <path> ]
    delete [ <path> ]
    extract 
    quit 
    help 

代码语言:javascript
复制
 -> ls
              75 initramfs-3.10.0-1160.71.1.el7.x86_64.img 
              77 vmlinuz-0-rescue-0c0d2b6deb9b4987bdbb8670b32a5200 
              76 initramfs-0-rescue-0c0d2b6deb9b4987bdbb8670b32a5200.img 
              74 vmlinuz-3.10.0-1160.71.1.el7.x86_64 
              73 symvers-3.10.0-1160.71.1.el7.x86_64.gz 
              72 config-3.10.0-1160.71.1.el7.x86_64 
              71 System.map-3.10.0-1160.71.1.el7.x86_64 
              70 .vmlinuz-3.10.0-1160.71.1.el7.x86_64.hmac 
              68 grub/
         1572928 grub2/
              67 efi/

 -> add grub

 -> add grub2

 -> extract

--------------------------------- end dialog ---------------------------------

代码语言:javascript
复制
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 102 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /srv/boot.dump OK (success)
xfsrestore: Restore Status: SUCCESS
[root@localhost ~]# ls -l /tmp/boot3
总用量 0
drwxr-xr-x. 2 root root 27 2月  26 00:12 grub
drwx------. 5 root root 97 2月  26 00:19 grub2

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 压缩
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档