1. Common compression instructions in Linux systems
Common compressed file formats in Linux systems:
- Files compressed by the .z compress program;
- .zip file compressed by zip program;
- file compressed by .gz gzip program;
- .bz2 file compressed by bzip2 program;
- .xz xz program Compressed files;
- Data packaged by the .tar tar program, and not compressed;
- Data packaged by the .tar.gz tar program, and compressed by gzip;
- Data packaged by .tar.bz2 tar program and compressed by bzip2;
- Data packaged by .tar.xz tar program and compressed by xz;
1, gzip command:
Common options:
- -c: Output the compressed data to the screen, through the data Traffic redirection to deal with;
- -d: decompression parameters;
- -t: can be used to check the consistency of a compressed file ~ see if the file has errors;< /li>
- -v: can display information such as the compression ratio of the original file/compressed file;
- -#: # means a number, representing the compression level, -1 is the fastest, but compression The worst ratio, -9 is the slowest, but the compression ratio is the best, and the default is -6.
For example:
(1) Compression:
[[email protected] ~]# cp /etc/passwd /mnt #Copy the file out
[[emailprotected] ~]# gzip -v /mnt/passwd #Compress it
/mnt/passwd: 61.1% - replaced with /mnt/passwd.gz
[[email protected] ~]# ll /etc/passwd /mnt/passwd* #Compare the size of this file before and after compression
- rw-r--r--. 1 root root 2311 July 14 19:02 /etc/passwd
-rw-r--r--. 1 root root 923 August 20 22:34 /mnt/ passwd.gz
(2) View the contents of the compressed file:
[[emailprotected] ~]# zcat /mnt/passwd.gz pre>(3) Decompress the compressed file:
[[emailprotected] ~]# gzip -d /mnt/passwd.gz
[ [email protected] ~]# ls /mnt
passwd2, bzip command:
Common options:
- -c: output the data generated during the compression process to the screen;
- -d: decompress the parameters;
- -k: keep the original file without deleting the original File;
- -z: Compressed parameters (default value, you don’t need to add it).
- -v: can display information such as the compression ratio of the original file/compressed file;
- -#: # means a number, representing the compression level, -1 is the fastest, but The compression ratio is the worst, -9 is the slowest, but the compression ratio is the best, and the default is -6.
For example:
(1)Compression[[emailprotected ] ~]# bzip2 -v /mnt/passwd #Compression
[[emailprotected] ~]# ls /mnt #View the compressed file
passwd.bz2(2) View the contents of the compressed file:
[[email protected] ~]# bzcat /mnt/passwd.bz2 #Output the file information on the screen(3)Unzip
[[emailprotected] ~]# bzip2 -d /mnt/passwd.bz2 #Unzip
[[emailprotected] ~]# ls /mnt #View
passwd3, xz command:
Common options:
- -d: unzip Parameters;
- -t: Test the integrity of the compressed file to see if there are any errors;
- -l: List the relevant information of the compressed file;
- -k: keep the original file without deleting;
- -c: mean outputting data from the screen;
- -#: # means a number, representing the compression level,- 1 is the fastest, but the compression ratio is the worst, -9 is the slowest, but the compression ratio is the best, and the default is -6.
Illustration:
(1) Compression:
[[emailprotected] ~]# xz -v /mnt/passwd
[[emailprotected] ~]# ls /mnt
passwd.xz(2 ) View:
[[emailprotected] ~]# xz -l /mnt/passwd.xz #View the size of the file before and after compression
[[emailprotected] ~]# xzcat /mnt/passwd.xz #Display the file information on the screen(3) Unzip and view
[[emailprotected] ~]# xz -d /mnt/passwd.xz
[[email protected] ~]# ls /mnt
passwd4, tar archive command
Common options :
- -c: Create a package file, you can use -v to view the file name that was packaged in the process;
- -C: Specify the released file when decompressing The destination folder.
- -f: Means to use archive files, usually followed by the file name to be processed.
- -j: Call bzip2 program to compress or decompress.
- -J: Compress or decompress through the xz program.
- -p: Preserve file and directory permissions when packaging.
- -P: Keep the absolute path of files and directories when packaging.
- -t: List the files in the package.
- -v: Output detailed information about the decompression/compression process.
- -x: Unzip the package file in .tar format.
- -z: Call gzip program to compress or decompress.
Example of use:
[[emailprotected] ~]# tar jcf filename.tar.bz2 The file or directory to be compressed#Compression
[[email Protected] ~]# tar jtvf filename.tar.bz2 #View the contents of the compressed file
[[email Protected] ~]# tar jxvf filename.tar.bz2 -C Which file do you want to extract? Contents #Unzip2. Other common compression and backup tools
5. dd command (commonly used):
Common options:
5. p>
- if: input file (original file) can also be a device;
- of: output file (backed up file) can also be a device;
- bs: The size of a planned block (block), if not specified, the default is 512Bytes (bytes);
- count: How many blocks mean.
For example:
[[emailprotected] ~]# dd if=/dev/zero of=/ a/123.txt bs=10M count=5
#Copy the information in the /dev/zero file to the /a directory to create a 123.txt file, 10M at a time, 5 times, and the final size of the file It is 50M.6, cpio command (not commonly used):
Backup common options:
- -o: Copy data to file or On the device;
- -B: The default Blocks can be increased to 5120 bytes, the default is 512 bytes;
- (This has the advantage of speeding up the storage of large files ).
Options and parameters used for restoration:- -i: Copy data from a file or device to the system;
- -d: Automatically create a directory! ;
- (The data content backed up by cpio may not be in the same directory, so we must let cpio automatically create a new directory when restoring, we must use the "-d" option);
- -u: Automatically compare new files and overwrite old files;
- -t: Need to combine the "-i" option, which can be used when viewing the created file or device content.
Some shareable options and parameters:- -v: Let the file name be displayed on the screen during storage;
- -c: A newer protable Store in format.
For example:
(1) Backup
To use this command, you need to use the find command to search first, and then Only then can the output file be used by this command#Copy all files in the /boot directory using the cpio command to the /mnt directory and name it boot.cpio
[[emailprotected] ~ ]# find /boot | cpio -ocvB> /mnt/boot.cpio
[[emailprotected] ~]# ls -lh /mnt/boot.cpio
-rw-r--r-- . 1 0 root 140M August 20 23:30 /mnt/boot.cpio(2) Restore
[[emailprotected] ~]# cpio -idvc [[emailprotected] ~]# find / | cpio -ocvB> /dev/st0 #Backup
[ [email protected] ~]# cpio -idvcThree, XFS file system backup and restore
1, xfs file system backup-xfsdump Command:
Limits of the xfsdump command:
- xfsdump does not support unmounted file systems, so it can only back up mounted files;
- Xfsdump must use root permissions to operate (involving the file system relationship);
- Xfsdump can only back up the xfs file system;
- Xfsdump backup data (file or storage Media) can only be decompressed by xfsrestore;
- Xfsdump distinguishes each backup file by the UUID of the file system, so two file systems with the same UUID cannot be backed up.
Common options:
- -L: xfsdump will record the session header of each backup, here you can Fill in the brief description of this file system;
- -M: xfsdump can record the header of the storage media, here you can fill in the brief description of the media.
- -l: is the lower case of L, which is the specified level, there are 10 levels from 0 to 9, the default is 0, that is, full backup, and 1 to 9 refer to incremental backup.
- -f: A bit similar to tar, followed by the generated file, or the device file name of /dev/st0 or other general file names;
- -I: uppercase "I", lists the current backup information status from /var/lib/xfsdump/inventory.
For example:
[[emailprotected] ~]# xfsdump -l O -L boot_all -Mboot_all -f /srv/boot.dump /boot
#Record the full backup file name as /srv/boot.dump
#If you don’t add the -L and -M options to enter the interactive mode
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0)-type ^C for status and control
xfsdump: WARNING: most recent level 0 dump was interrupted, but not resuming that dump since resume (-R ) option not specified
xfsdump: level 0 dump of localhost.localdomain:/boot #Start to back up the local/boot system
xfsdump: dump date: Wed Aug 21 00:04:00 2019 #Backup Time
xfsdump: session id: 2ab52f27-54d8-4cb3-b99f-5f78601afeed #ID of this dump
xfsdump: session label: "boot_all" # Simply give a name to remember
#Start backup Program
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: 146934272 bytes
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 146605160 bytes
xfsdump: dump size (non-dir files): 146370000 bytes
xfsdump: dump complete: 1 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /srv/boot.dump OK (success)
xfsdump: Dump Status: SUCCESS
[[emailprotected] ~]# xfsdump -I # Check if there is any data backed up by xfsdump2, restore of xfs file system-xfsrestore command:
Common options are as follows:
- -I: The uppercase "i" has the same output as xfsdump! You can query the backup data, including the label name and backup time, etc.;
- -f: The backup file is followed by! In the enterprise, it is very likely that tape drives such as /dev/st0 will be connected!
- -L: The data that can be queried with "-I". Enter after this option;
- -s: You need to connect to a specific directory, and you can restore a file or directory;
- -r: If you use a file to store backup data, Then this one does not need to be used. If there are multiple files in one disk, you need to use it to achieve cumulative recovery;
- -i: Enter interactive mode (generally not required)
For example:
[[emailprotected] ~]# xfsrestore -I #View backup file data
[[emailprotected] ~]# xfsrestore -f /srv/boot.dump -L boot_all /boot# directly overwrite the backup data back———————— This is the end of this article, thanks for reading————————