Syntax: #tar [Options] File and directory
Pack: pack the file into one file.
Compress: pack the file into one file.
Pack and compress.
tar command function options:
Options | Features |
---|---|
-c | Create a compressed file/package file |
-x | Unzip a compressed file/package file |
-t | Check the contents of the bag |
-with | Whether to use gzip compression |
-j | Whether to use bzip2 compression |
-v | Show files during compression |
-f | Use file, followed by file name |
-p | The original file attributes remain unchanged |
-P | Can use absolute path to compress |
-T file name | Specify the list of backup files |
-N file name | Only newer than the set date (yyyy/mm/dd) will be packaged into the newly created file |
-M | Sub-volume processing |
-C file name | Specify the directory |
- - exclude FILE | Do not pack the specified FILE |
-g,–listed-incremental F | Create a new GNU format backup |
-G,–incremental | Create a backup in the old GNU format |
For more parameters, see: Tar (Linux system command) Baidu Encyclopedia
tar -cvf ??? Pack + build + display process + file
tar -zcvf use gzip compression + build + display + file
tar -jcvf use bzip2 compression. . .
tar -ztvf View what is in the file tar -zxvf
decompression
Which way to compress and which way to decompress. (-Z or -j)
压缩: tar -zcvf 或 -jcvf 目标文件 原文件
解压: tar -zxvf 或 -jxvf 原文件
Conventionally, the parameter z corresponds to the file name ".tar.gz" or ".tgz" and the
parameter j corresponds to the file name ".tar.bz2". To
unzip, cd to the corresponding directory and unzip to the current location.
tar -zcvpf backs up the files in /etc/ and retains permissions (owner array and permissions)
tar -N '2020/1/1" -zcvf test.tar.gz /home
The asking price under /home that is newer than the date is packaged into test.tar.gz
tar --exclude /home/testuser -zcvf test.tar.gz /home/* /etc
backs up /home, /etc, but does not back up /home/testuser
Full backup, incremental backup
Full backup is directly packaged and compressed. The name of the backup file contains the date. Such as:
testbak_full_`date +%Y%m%d`.tar.gz
Incremental backup: (the name of the backup file contains the date and time) (if the mirror file exists, the backup will be incremental, otherwise it will become a full backup)
tar -g 镜像文件名 -czpPf 备份文件(如: testbak_incremental_`date +%Y%m%d-%H%M`.tar.gz ) 待备份的目录和文件
The capital P is to specify the absolute path, if it is not needed, do not add it.