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 us with the filter function,
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