Linuxtarexclude parameter usage

Source: Internet
Author: User
Tags gz file

Recently, when using Cold Standby tar for Oracle database migration, You need to filter out the files exported by datapump under the current database file, otherwise, a large tar file will be generated and the network transmission time will be consumed. In fact, the tar command provides a filtering function, but many people do not know it because the filtering function is usually used less. This article describes how to filter unwanted files or folders under the tar command.

1. Demo Environment

# The BBB, CCC, and BNR subdirectories exist in the current tree directory. Now, you need to filter out the dump file of gz, that is, you do not need to package [oracle @ linux1 ~]. $ Tree AAAAAA | -- BBB | '-- SYTST_temp.dbf | -- BNR | -- dump | -- emp.dmp.gz | -- tb.dmp.gz |' -- xx.dmp.gz | '-- full | -- CCC | '-- tempSYTST. dbf | -- SYTST. sh' -- initSYTST. ora5 directories, 7 files

2. demonstrate how to filter

# Method 1: Filter Using the exclude parameter and use the wildcard [oracle @ linux1 ~] $ Tar-czvf A1.tar.gz -- exclude '*. gz '. /AAA. /AAA /. /AAA/CCC /. /AAA/CCC/tempSYTST. dbf. /AAA/BBB /. /AAA/BBB/SYTST_temp.dbf. /AAA/SYTST. sh. /AAA/initSYTST. ora. /AAA/BNR /. /AAA/BNR/full /. /AAA/BNR/dump/# view the content in the package. There is no gz file [oracle @ linux1 ~] $ Tar-tvf A1.tar.gz drwxr-xr-x oracle/oinstall 0 14:10:43. /AAA/drwxr-xr-x oracle/oinstall 0 14:12:18. /AAA/CCC/-rwxr-xr-x oracle/oinstall 209723392 14:12:19. /AAA/CCC/tempSYTST. dbfdrwxr-xr-x oracle/oinstall 0 14:11:56. /AAA/BBB/-rwxr-xr-x oracle/oinstall 104865792 14:11:56. /AAA/BBB/SYTST_temp.dbf-rwxr-xr-x oracle/oinstall 1281 0: 43. /AAA/SYTST. sh-rwxr-xr-x oracle/oinstall 2949 14:10:31. /AAA/initSYTST. oradrwxr-xr-x oracle/oinstall 0 14:11:12. /AAA/BNR/drwxr-xr-x oracle/oinstall 0 14:11:12. /AAA/BNR/full/drwxr-xr-x oracle/oinstall 0 14:11:04. /AAA/BNR/dump/# method 2. Use multiple exclude parameters to filter [oracle @ linux1 ~] $ Tar-czvf A2.tar.gz -- exclude = 'tempsytst. dbf' -- exclude = SYTST_temp.dbf. /AAA. /AAA /. /AAA/CCC /. /AAA/BBB /. /AAA/SYTST. sh. /AAA/initSYTST. ora. /AAA/BNR /. /AAA/BNR/full /. /AAA/BNR/dump /. /AAA/BNR/dump/xx.dmp.gz. /AAA/BNR/dump/tb.dmp.gz. /AAA/BNR/dump/emp.dmp.gz # method 3: add the file to be filtered to the file by using the exclude parameter, and then read from the file [oracle @ linux1 ~] $ Echo "*. dbf"> exclude.txt [oracle @ linux1 ~] $ Echo "*. gz"> exclude.txt [oracle @ linux1 ~] $ More exclude.txt *. dbf *. gz [oracle @ linux1 ~] $ Tar-czvf A3.tar.gz --exclude-from=exclude.txt. /AAA. /AAA /. /AAA/CCC /. /AAA/BBB /. /AAA/SYTST. sh. /AAA/initSYTST. ora. /AAA/BNR /. /AAA/BNR/full /. /AAA/BNR/dump/# Method 4. With the exclude parameter, you can directly filter all files in the specified folder by adding wildcards to the directory [oracle @ linux1 ~] $ Tar-czvf A4.tar.gz -- exclude =. /AAA/BNR/dump /*. /AAA. /AAA /. /AAA/CCC /. /AAA/CCC/tempSYTST. dbf. /AAA/BBB /. /AAA/BBB/SYTST_temp.dbf. /AAA/SYTST. sh. /AAA/initSYTST. ora. /AAA/BNR /. /AAA/BNR/full /. /AAA/BNR/dump/# Method 5. Use the exclude parameter to directly filter [oracle @ linux1 ~] Directories $ Tar-czvf A4.tar.gz -- exclude =. /AAA/BNR. /AAA. /AAA /. /AAA/CCC /. /AAA/CCC/tempSYTST. dbf. /AAA/BBB /. /AAA/BBB/SYTST_temp.dbf. /AAA/SYTST. sh. /AAA/initSYTST. ora

3. Get help information

# Use help to obtain help information [oracle @ linux1 ~] $ Tar -- helpUsage: tar [OPTION...] [FILE]... GNU 'tar 'saves program files together into a single tape or disk archive, and canrestore individual files from the archive. examples: tar-cf archive.tar foo bar # Create archive.tar from files foo and bar. tar-tvf archive.tar # List all files in archive.tar verbosely. tar-xf archive.tar # Extract all files from archive.tar ........... omitted ........... # use man or Info for help information [oracle @ linux1 ~] $ Man tar

More references

For more information about Oracle RAC, see

For more information about the basics and concepts of Oracle network configuration, see:

For more information about user-managed backup and recovery, see

For information on RMAN backup recovery and management, see

For the ORACLE architecture, see

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.