Linux Learning Notes-compression and packaging of files and file systems (reproduced)

Source: Internet
Author: User
Tags bz2

Uses and techniques for compressed files

For example, computers are measured in byte units, and 1byte is 8bit. If the number 1 is stored, then 1byte will empty 7bit. Using a certain calculation method, compressing these spaces can greatly reduce the file storage.

Common compression commands for Linux systems

The extensions for the zip file under Linux are *.tar, *.tar.gz, *.tgz, *.gz, *. Z, *.bz2

The extension is used to describe the type of instruction used by the compression

    • *. Z Compress Program Compressed files
    • *.gz gzip Program Compressed files
    • *.BZ2 BZIP2 Program Compressed files
    • *.tar tar packed data, uncompressed
    • *.tar.gz tar packed data, gzip compressed
    • *.TAR.BZ2 tar packed data, compressed by bzip2
Compress

Very old instructions can be ignored, gzip can decompress its compressed *. Z File

Gzip,zcat

Gzip can decompress compress,zip,gzip compressed files

Parameters:

-C: Output compressed data to the screen

-D: decompressed parameters

-T: Verifying the consistency of compressed files

-V: Show Compression ratio

-#: Compression level, 1 fastest but lowest compression, 9 slowest but best compression, default-6

[Email protected] tmp]# ls-l./auto.smb-rwxr-xr-x. 1 root root 687 June  21:37./auto.smb
compression [[email protected] tmp]# gzip-v./AUTO.SMB./AUTO.SMB: 37.1%--replaced with./auto.smb.gz[[email protected] tmp ]# ls-l./auto.smb.gz-rwxr-xr-x. 1 root root 459 June 21:37./auto.smb.gz
Unzip
[Email protected] tmp]# gzip-d./auto.smb.g

ZCAT instruction can read compressed files after plain text is compressed

[Email protected] tmp]# zcat./auto.smb.gz#!/bin/bash# This file must is executable to work! chmod 755!key= "$" opts= "-fstype=cifs" for P in/bin/sbin/usr/bin/usr/sbindo    If [-X $P/smbclient] then        SMB client= $P/smbclient        break    fidone[-x $SMBCLIENT] | | Exit 1$SMBCLIENT-GNL $key 2>/dev/null| awk-v key= "$key" -V opts= "$opts"-f ' | '--'    BEGIN    {ors= ""; first=1}    /disk/    {          if (first)            print opts; first=0< C11/>dir =          $ $ loc =          $ enclose Mount Dir and location in quotes          # Double Quote "$" in location as it is s Pecial          gsub (/\$$/, "\\$", loc);          Gsub (/\&/, "\\\\&", loc)          print "\\\n\t \"/"dir" \ "", "\":/"Key"/"loc" \ ""        }    END     {if (!fir ST) print "\ n"; else exit 1}    

Bzip2,bzcat

Parameters:

-C: Display data from the compression process to the screen

-D: decompressed parameters

-K: Keep source files

-Z: Compressed parameters

-V: Display Compression ratio information

-#: Compression ratio, same as gzip

[Email protected] tmp]# ls-l./auto.smb-rwxr-xr-x. 1 root root 687 June  21:37/auto.smb[[email protected] tmp]# bzip2-kzv./AUTO.SMB/auto.smb  : 1.314:1,
   
    6.090 Bits/byte, 23.87% saved, 687 in, 523 out. [Email protected] tmp]# ls-l./auto.smb.bz2-rwxr-xr-x. 1 root root 523 June  21:37./auto.smb.bz2
   

Use Bzcat to view compressed file contents

Package Command: Tar

Package multiple files into one file for easy compression of multiple files

Tar

tar [-j|-z] [CV] [-f new filename] filename. .. Packaging and compression

tar [-j|-z] [TV] [-f new FileName]//view file name

tar [-j|-z] [XV] [-f new FileName]

The usual instructions are as follows:

Compression: Tar-jcv-f filename.tar.bz2

Enquiry: Tar-jtv-f filename.tar.bz2

Decompression: Tar-jxv-f filename.tar.bz2-c to extract the directory

 [[email protected] hsperfdata_wuchao]# cd/tmp[[email protected] tmp]# mkdir ./tartest[[email  Protected] tmp]# CD./tartest[[email protected] tartest]# cp/var/spool/mail/root. [[email protected] tartest]# ls-l ROOT-RW-------. 1 root root 571540 June 10:40 root[[email protected] tartest]# Cp/var/spool/mail/wuchao. [[email protected] tartest]# ls-l./wuchao-rw-r-----. 1 root root 0 June 10:41./wuchao 

//Compression [[email protected] tartest]# tar-jcv-f tartest.tar.bz2./root./wuch Ao./root./wuchao

//view compressed file [[email protected] tartest]# tar-jtv-f tartest.tar.bz2-rw-------root/root 571540 2016-06-30 10:40/root-rw-r-----root/root 0 2016-06-30 10:41./wuchao

//unzip [[email protected] tartest]# tar-jxv-f tartest.tar.bz2. /root./wuchao

//extract to a specific directory
[[email protected] tartest]# mkdir./t
[[email protected] tartest]# Tar-jxv-f./tartest.tar.bz2-c./T
Full Backup tool: Dumpdump

For a file system backup, a file system dump backup, the second dump can specify the backup level, level 0 indicates a full backup, level greater than 0 indicates that the newly backed up data will only record the new or changed files compared to the last lower level.

Usage Restrictions:

    1. When the backed up data is a single file system: You can use the full dump feature while backing up with a mount point or a device file name.
    2. When the backed up data is only a directory, not a single file system: for example, to back up/home/someone, but the directory is not a single file system, at this time the backup data will be in this directory, and only use level0, do not support the-u parameter, that is, cannot create/etc/ Dumpdates the time log file for this level backup.

dump [-SUV] [-level] [-f backup file] data to be backed up

Dump-w

Parameters:

-S: Lists the disk space required for the data to be backed up later

-U: Log the time of this dump to the/etc/dumpdates file

-V: Displays the file process of the dump

-J: Add bzip2 support to compress data

-level:dump Rating

-F: Files after backup

-W: Lists whether the partition with the dump setting in the/ETC/FSTAB has been backed up

Back up the full file system with dump

Viewing the file system
[Email protected] tartest]# df-hfilesystem Size used Avail use% mounted on/dev/mapper/centos-root 46G 5.8G 40G 13%/devtmpfs 1.9G 0 1.9G 0%/devtmpfs 1.9G 656K 1.9G 1%/dev/sh Mtmpfs 1.9G 17M 1.9G 1%/runtmpfs 1.9G 0 1.9G 0%/sys/fs/cgroup/dev/mapp Er/centos-home 23G 92M 23G 1%/home/dev/sda5 497M 213M 284M 43%/BOOTTMPFS 37 3M 28K 373M 1%/run/user/0/dev/sda3 976M 2.6M 907M 1%/run/media/root/myfile

View the space required for backup/DEV/SDA3 [[email protected] tartest]# dump-s/dev/sda353248

For backup, back up to/root/boot.dump file,/run/media/root/myfile can also be written/dev/sda3[[email protected] tartest]# dump-0u-f/root/ Boot.dump/run/media/root/myfile Dump:date of this level 0 Dump:thu June 15:42:53 Dump:dumping/dev/sda3 (/run /media/root/myfile) To/root/boot.dump DUMP:Label:MyFile dump:writing Kilobyte Records dump:mapping (Pass I) [Re Gular files] dump:mapping (Pass II) [directories] dump:estimated blocks. Dump:volume 1 started with block 1 At:thu June 15:42:53 dump:dumping (Pass III) [directories] Dump:dumping (P [Regular Files] dump:closing/root/boot.dump Dump:volume 1 completed at:thu June 15:42:53 E 1 blocks (0.04MB) dump:40 blocks (0.04MB) on 1 volume (s) dump:finished in less than a second dump:date of this Level 0 Dump:thu June 15:42:53 dump:date This dump Completed:thu June, 15:42:53 Dump:average rate:0 kb/s Dump:dump is done
View backup files [[email protected] tartest]# ls-dl/run/media/root/myfile/root/boot.dump-rw-r--r--. 1 root root 40960 June 15:42/root/boot.dumpdrwx------. 5 root root 4096 June 15:38/run/media/root/myfile//view update history [[email protected] tartest]# Cat/etc/dumpdates/dev/sda3 0 Th U June 30 15:42:53 2016 +0800

See if any file systems have been backed up
Last dump (s) done (dump ' > ' file systems):
/dev/sda3 (/run/media/root/myfile) Last Dump:level 0, Date Thu June 30 15:42:53 2016

To back up a non-file system, a single directory method:

/run/media/root/myfile/folder1 a directory to a backup
[[email protected] tartest]# dump-0j-f/root/fw.dump/run/media/root/myfile/folder1 dump:date of this level 0 dum P:thu June 15:59:17 Dump:dumping/dev/sda3 (/run/media/root/myfile (dir/folder1)) To/root/fw.dump Dump:label : MyFile dump:writing Kilobyte records dump:compressing output at compression level 2 (bzlib) dump:mapping (Pass I) [Regular files] dump:mapping (Pass II) [directories] dump:estimated blocks. Dump:volume 1 started with block 1 At:thu June 15:59:17 dump:dumping (Pass III) [directories] Dump:dumping (P [Regular Files] dump:closing/root/fw.dump Dump:volume 1 completed at:thu June 15:59:17 dump:40 bloc KS (0.04MB) on 1 volume (s) dump:finished in less than a second dump:date of this level 0 Dump:thu June 30 15:59:17 201 6 Dump:date This DUMP completed:thu June 15:59:17 dump:average transfer rate:0 kb/s dump:wrote 40kB Uncomp ressed, 11kB compressed, 3.637:1 Dump:dump is Done[[email protected] tartest]#
Restore

Post-Backup recovery

Restore-t [-F DumpFile] [-h] To view the dump file

Restore-c [-F dumpfile] [-D mount Point] used to compare dump files with actual files

Restore-i [-F DumpFile] Enter interactive mode

Restore-r [-F dumpfile] Restoring the entire file system

-H: View the Inode and label information for the file system for the full backup data


Use Restore to view the contents of the backup data after dump

[Email protected] tartest]# restore-t-f/root/boot.dumpdump   date:thu June 15:42:53 2016Dumped from:the Epochlev El 0 Dump Of/run/media/root/myfile on localhost.localdomain:/dev/sda3label:myfile         2    .    /lost+found.    /untitled folder      8193    ./untitled folder 2.    /untitled folder 2 /untitled Folder[[email protected] tartest]#

Compare differences and restore the entire system

Remove a folder from the original filesystem [[email protected]/]# rm-rf/run/media/root/myfile/folder1//View differences between file system and backup files [[email protected]/]# Restore-c-f/root/boot.dumpdump   date:thu June 15:42:53 2016Dumped from:the epochlevel 0 Dump of/run/media/root/ MyFile on localhost.localdomain:/dev/sda3label:myfilefilesys =/run/media/root/myfilerestore:unable to Stat./ Untitled folder:no such file or directorysome files were modified!  

Restore the file system: Create a new file system first

[Email protected]/]# fdisk/dev/sdawelcome to fdisk (Util-linux 2.23.2). Changes'll remain in memory only, until the decide to write them. Be careful before using the write Command.command (M for help): P.
.
. Device Boot Start End Blocks Id system/dev/sda1 * 2048 206847 102400 7 hpfs/nt Fs/exfat/dev/sda2 206848 403138559 201465856 7 Hpfs/ntfs/exfat/dev/sda3 403138560 405235711 1 048576 linux/dev/sda4 473042944 625141759 76049408 5 extended/dev/sda5 473044992 474068991 512000 linux/dev/sda6 474071040 625141759 75535360 8e Linux lvmcommand (M for help): Dpartition num ber (1-6, default 6): 2Partition 2 is Deletedcommand (M-help): P
.
.
.
Device Boot Start End Blocks Id system/dev/sda1 * 2048 206847 102400 7 hpfs/nt Fs/exfat/dev/sda3 403138560 405235711 1048576 linux/dev/sda4 473042944 625141759 76049408 5 extended/dev/sda5 473044992 474068991 512000 linux/dev/sda6 474071040 625141759 75535360 8e Linux Lvmcommand (M for help): Npartition Type:p Primary (2 primary, 1 extended, 1 free) l logical (Numbere D from 5) Select (default p): Pselected partition 2First sector (206848-625142447, default 206848): Using Default Value 206 848Last sector, +sectors or +size{k,m,g} (206848-403138559, default 403138559): +2014mpartition 2 of type Linux and of Siz E 2 GiB is set.
.
.
Device Boot Start End Blocks Id system/dev/sda1 * 2048 206847 102400 7 HPFS /ntfs/exfat/dev/sda2 206848 4331519 2062336 linux/dev/sda3 403138560 405235711 1048576 LINUX/DEV/SDA4 473042944 625141759 76049408 5 extended/dev/sda5 473044992 474068991 5120 Linux/dev/sda6 474071040 625141759 75535360 8e Linux lvmcommand (M for help): Wthe partition Table has been altered! [[email protected]/]# partprobe[[email protected]/]# mkfs-t ext3/dev/sda2mke2fs 1.42.9 (28-Dec-2013) Filesystem label=os type:linuxblock size=4096 (log=2) Fragment size=4096 (log=2) stride=0 blocks, Stripe width=0 blocks129 024 Inodes, 515584 blocks25779 blocks (5.00%) reserved for the Super Userfirst data block=0maximum filesystem blocks=52848 230416 block groups32768 blocks per group, 32768 fragments per group8064 inodes per groupsuperblock backups stored on bloc ks:32768, 98304, 163840, 229376, 294912Allocating group Tables:done Writing inode Tables:done Creating Journal (8192 blocks): donewriting superblocks and filesystem accounting Information:done [[EMA Il protected]/]# mount/dev/sda2/mnt

CD to a new file system mount point

CD to a new file system mount point (important)
[Email protected]/]# cd/mnt

Restore only part of the file's interactive mode

View Backup Files
[Email protected] mnt]# restore-t-f/root/boot.dumpdump date:thu June 15:42:53 2016Dumped from:the epochlevel 0 D UMP Of/run/media/root/myfile on Localhost.localdomain:/dev/sda3label:myfile 2. /lost+found./untitled folder 8193./untitled folder 2./untitled folder 2/untitl Ed Folder

Enter the restore interactive mode, where all operations are within the backup file [[email protected] mnt]# restore-i-f/root/boot.dump
Enter help view assistance for restore > Helpavailable commands are:ls [arg]-list directory CD Arg-change directory pwd-p Rint current directory Add [arg]-add ' arg ' to list of files to is extracted delete [arg]-delete ' arg ' from list of files to be extracted extract-extract requested files Setmodes-set modes of requested directories quit-i mmediately Exit Program What-list dump header information Verbose-toggle verbose flag (useful with ' ls ') pr Ompt-toggle the prompt display Help or '? '-Print this listif no ' arg ' was supplied, the current directory is used
View backup file list restore > ls.:untitled folder/untitled Folder 2/lost+found/
Go to Folders Untitled folder 2restore > CD ' Untitled folder 2 '
View but previous directory name restore > pwd/untitled Folder 2

View the list of files in the current directory restore > ls ' Untitled folder './untitled folder 2/untitled folder:
Add the Untitled folder directory to the Decompression list restore > Add ' Untitled folder '

To view the current directory, there will be an * number in front of the file to be unzipped restore > ls./untitled Folder 2:*untitled folder/
Unzip restore > Extractyou has not read any volumes yet. Unless you know which volume your file (s) is on your should startwith the last volume and work towards the first. Specify next Volume # (None if no more volumes): 1set Owner/mode for '. '? [yn] yrestore > Q
View extracted files [[email protected] mnt]# ls ' Untitled Folder 2 ' Untitled folder[[email protected] mnt]#

Reprinted from:

9th. File and file system compression and packaging

Linux Learning Notes-compression and packaging of files and file systems (reproduced)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.