使用tar归档备份并排除某些文件或目录

最近工作中遇到这样一个需求,需要定期备份主机上的脚本文件,但是因为脚本文件分布在各个目录下,有的目录如日志文件并不需要备份,那么就需要排序部分目录或者指定的文件了,方法如下,可供参考(系统环境AIX):

1.将需要排除的目录或者文件每个一行以列表的形式编辑到某个文件中:
[css_int@wgyx1]$cat /int_file/lubinsu/excludeList.txt
lubinsu/backup
lubinsu/etl_data
lubinsu/logs
lubinsu/soft

2.使用-X参数排除目录 -cvf 表示创建归档文件,v归档过程中列出文件 f使用文档名
[css_int@wgyx1]$tar -cvf /int_file/lubinsu/backup/backup_scripts.test.tar -X /int_file/lubinsu/excludeList.txt lubinsu/
a lubinsu/
a lubinsu/cba
a lubinsu/css
a lubinsu/css/p_run_procedure_css.sh 1 blocks
a lubinsu/etl_data (excluded)
a lubinsu/soft (excluded)
a lubinsu/ftp
a lubinsu/logs (excluded)
a lubinsu/ods
a lubinsu/ods/p_run_procedure_ods1.sh 2 blocks
a lubinsu/ods/p_run_procedure_ods2.sh 2 blocks
a lubinsu/p_run_procedure_css.sh 5 blocks
a lubinsu/p_run_procedure_css_yz.sh 5 blocks
a lubinsu/p_run_procedure_ods1.sh 5 blocks
a lubinsu/p_run_procedure_ods2.sh 5 blocks
a lubinsu/retrieval
a lubinsu/backup (excluded)
a lubinsu/scripts
a lubinsu/scripts/p_monitor_init.sh 1 blocks
a lubinsu/scripts/etl_dispatch
a lubinsu/scripts/etl_dispatch/main_dispatch.sh 2 blocks
a lubinsu/scripts/etl_dispatch/css_etl
a lubinsu/scripts/etl_dispatch/css_etl/etl_proc.sh~ 6 blocks
a lubinsu/scripts/etl_dispatch/css_etl/getYesterday.sh 2 blocks
a lubinsu/scripts/etl_dispatch/css_etl/etl_log
a lubinsu/scripts/etl_dispatch/css_etl/db_constr.txt 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/get_info_from_db.sh~ 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/get_ftp_files.sh 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/etl_dispatch.sh~ 22 blocks
a lubinsu/scripts/etl_dispatch/css_etl/clearspace.sh 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/etl_proc.log 22613 blocks
a lubinsu/scripts/etl_dispatch/css_etl/get_info_from_db.sh 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/etl_dispatch.sh 22 blocks
a lubinsu/scripts/etl_dispatch/css_etl/getLastMonth.sh 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/etl_proc.sh 6 blocks
a lubinsu/scripts/etl_dispatch/css_etl/spoolBatch.sh~ 2 blocks
a lubinsu/scripts/etl_dispatch/css_etl/spoolBatch.sh 2 blocks
a lubinsu/scripts/etl_dispatch/css_etl/tmp.fileds~ 2 blocks
a lubinsu/scripts/etl_dispatch/css_etl/parseXML.sh 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/tmp.fileds 2 blocks
a lubinsu/scripts/etl_dispatch/css_etl/spoolSQL 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/.tmp 0 blocks
a lubinsu/scripts/etl_dispatch/css_etl/etl_dispatch_original.sh 18 blocks
a lubinsu/scripts/etl_dispatch/css_etl/spoolTail 1 blocks
a lubinsu/scripts/etl_dispatch/css_etl/spoolBatch.sh_bak 2 blocks
a lubinsu/scripts/etl_dispatch/css_etl/spoolSQL_55313886.sql 2 blocks
a lubinsu/scripts/etl_dispatch/shell_proc_daemon.sh 2 blocks
a lubinsu/scripts/get_date.sh 1 blocks
a lubinsu/scripts/get_itibil_acct_item_owe.sh 10 blocks
a lubinsu/scripts/syn_acct_item_owe_month.sh 4 blocks
a lubinsu/scripts/syn_acct_item_owe_all.sh 2 blocks
a lubinsu/scripts/get_itibil_acct_item_owe_enhance.sh 11 blocks
a lubinsu/scripts/backup.sh 3 blocks
a lubinsu/scripts/syn_acct_item_owe_all_auto.sh 3 blocks
a lubinsu/scripts/passwd.txt 1 blocks
a lubinsu/scripts/call_proc.sh 1 blocks
a lubinsu/scripts/getYesterday.sh 2 blocks
a lubinsu/scripts/syn_acct_item_owe_day.sh 4 blocks
a lubinsu/scripts/syn_acct_item_owe_day_auto_bak.sh 5 blocks
a lubinsu/scripts/syn_acct_item_owe_month_2.sh 4 blocks
a lubinsu/scripts/read_db_test.sh 1 blocks
a lubinsu/scripts/logic_backup.sh 1 blocks
a lubinsu/scripts/backup.sh~ 3 blocks
a lubinsu/scripts/get_last_month.sh 1 blocks
a lubinsu/scripts/get_files_from_ftp.sh 3 blocks
a lubinsu/scripts/source_profile 3 blocks
a lubinsu/scripts/syn_acct_item_owe_day_auto_tmp.sh~ 5 blocks
a lubinsu/scripts/get_itibil_acct_item_owe_enhance_1.sh~ 11 blocks
a lubinsu/scripts/syn_acct_item_owe_day_auto.sh 5 blocks
a lubinsu/scripts/get_itibil_acct_item_owe_enhance_1.sh 11 blocks
a lubinsu/scripts/killProcess.sh~ 1 blocks
a lubinsu/scripts/killProcess.sh 1 blocks
a lubinsu/scripts/syn_acct_item_owe_day_auto_single.sh 2 blocks
a lubinsu/scripts/syn_acct_item_owe_day_auto_tmp.sh 2 blocks
a lubinsu/jdk
a lubinsu/exportFile.sh~ 3 blocks
a lubinsu/exportFile.sh 1 blocks
a lubinsu/backup-scripts.tar.gz 33595 blocks
a lubinsu/excludeList.txt~ 1 blocks
a lubinsu/excludeList.txt 1 blocks

3.使用tvf来检查归档文件中的文件列表,不需要的文件已经排除在外了:
[css_int@wgyx1]$tar tvf backup_scripts.test.tar 
drwxr-x--- 207 1 0 Jun 07 11:38:02 2014 lubinsu/
drwxr-x--- 207 1 0 Oct 06 20:51:35 2013 lubinsu/cba/
drwxr-x--- 207 1 0 Apr 10 15:25:23 2014 lubinsu/css/
-rwxrwxrwx 207 1 505 Apr 10 15:26:24 2014 lubinsu/css/p_run_procedure_css.sh
drwxr-x--- 207 1 0 Mar 05 20:39:27 2014 lubinsu/ftp/
drwxr-x--- 207 1 0 Oct 06 20:57:54 2013 lubinsu/ods/
-rw-r----- 207 1 546 Apr 10 15:30:58 2014 lubinsu/ods/p_run_procedure_ods1.sh
-rw-r----- 207 1 546 Apr 10 15:31:46 2014 lubinsu/ods/p_run_procedure_ods2.sh
-rwxrwxrwx 207 1 2323 Oct 27 17:23:32 2013 lubinsu/p_run_procedure_css.sh
-rw-r----- 207 1 2357 Oct 06 20:57:55 2013 lubinsu/p_run_procedure_css_yz.sh
-rw-r----- 207 1 2358 Oct 06 20:57:56 2013 lubinsu/p_run_procedure_ods1.sh
-rw-r----- 207 1 2358 Oct 06 20:57:56 2013 lubinsu/p_run_procedure_ods2.sh
drwxr-x--- 207 1 0 Nov 21 09:50:07 2013 lubinsu/retrieval/
drwxr-xr-x 207 1 0 Jun 07 10:59:42 2014 lubinsu/scripts/
-rwxrwxrwx 207 1 129 Oct 06 21:05:17 2013 lubinsu/scripts/p_monitor_init.sh
drwxr-xr-x 207 1 0 Apr 10 14:49:45 2014 lubinsu/scripts/etl_dispatch/
-rwxr-xr-x 207 1 517 Mar 29 14:51:09 2014 lubinsu/scripts/etl_dispatch/main_dispatch.sh
drwxr-xr-x 207 1 0 Jun 07 10:22:41 2014 lubinsu/scripts/etl_dispatch/css_etl/
-rwxr-xr-x 207 1 2606 May 13 20:04:16 2014 lubinsu/scripts/etl_dispatch/css_etl/etl_proc.sh~
-rwxr-xr-x 207 1 707 Apr 01 20:14:32 2014 lubinsu/scripts/etl_dispatch/css_etl/getYesterday.sh
drwxr-xr-x 207 1 0 Mar 29 09:29:52 2014 lubinsu/scripts/etl_dispatch/css_etl/etl_log/
-rw-r--r-- 207 1 58 Mar 29 10:31:20 2014 lubinsu/scripts/etl_dispatch/css_etl/db_constr.txt
-rwxr-xr-x 207 1 231 Jun 07 10:17:20 2014 lubinsu/scripts/etl_dispatch/css_etl/get_info_from_db.sh~
-rwxr-xr-x 207 1 217 Mar 29 14:25:15 2014 lubinsu/scripts/etl_dispatch/css_etl/get_ftp_files.sh
-rwxr-xr-x 207 1 10883 May 16 18:32:24 2014 lubinsu/scripts/etl_dispatch/css_etl/etl_dispatch.sh~
-rwxr-xr-x 207 1 159 Mar 29 14:43:11 2014 lubinsu/scripts/etl_dispatch/css_etl/clearspace.sh
-rw-r--r-- 207 1 11577731 Jun 07 11:38:03 2014 lubinsu/scripts/etl_dispatch/css_etl/etl_proc.log
-rwxr-xr-x 207 1 230 Jun 07 10:23:48 2014 lubinsu/scripts/etl_dispatch/css_etl/get_info_from_db.sh
-rwxr-xr-x 207 1 10876 May 16 18:46:14 2014 lubinsu/scripts/etl_dispatch/css_etl/etl_dispatch.sh
-rwxrwxrwx 207 1 299 Apr 16 09:55:30 2014 lubinsu/scripts/etl_dispatch/css_etl/getLastMonth.sh
-rwxr-xr-x 207 1 2602 May 13 20:08:59 2014 lubinsu/scripts/etl_dispatch/css_etl/etl_proc.sh
-rwxr--r-- 207 1 794 May 30 16:57:45 2014 lubinsu/scripts/etl_dispatch/css_etl/spoolBatch.sh~
-rwxr--r-- 207 1 793 May 30 17:53:18 2014 lubinsu/scripts/etl_dispatch/css_etl/spoolBatch.sh
-rw-r--r-- 207 1 549 May 29 19:39:26 2014 lubinsu/scripts/etl_dispatch/css_etl/tmp.fileds~
-rwxrwxrwx 207 1 172 Apr 24 21:15:35 2014 lubinsu/scripts/etl_dispatch/css_etl/parseXML.sh
-rw-r--r-- 207 1 576 May 29 20:15:42 2014 lubinsu/scripts/etl_dispatch/css_etl/tmp.fileds
-rw-r--r-- 207 1 232 May 29 20:16:21 2014 lubinsu/scripts/etl_dispatch/css_etl/spoolSQL
-rw-r--r-- 207 1 0 Apr 23 21:44:45 2014 lubinsu/scripts/etl_dispatch/css_etl/.tmp
-rwxr-xr-x 207 1 9178 Apr 27 11:35:12 2014 lubinsu/scripts/etl_dispatch/css_etl/etl_dispatch_original.sh
-rw-r--r-- 207 1 17 May 29 20:16:47 2014 lubinsu/scripts/etl_dispatch/css_etl/spoolTail
-rw-r--r-- 207 1 733 May 30 08:56:12 2014 lubinsu/scripts/etl_dispatch/css_etl/spoolBatch.sh_bak
-rw-r--r-- 207 1 831 May 29 20:22:28 2014 lubinsu/scripts/etl_dispatch/css_etl/spoolSQL_55313886.sql
-rwxr-xr-x 207 1 792 Apr 09 17:44:30 2014 lubinsu/scripts/etl_dispatch/shell_proc_daemon.sh
-rwxrwxrwx 207 1 495 Nov 08 18:16:36 2013 lubinsu/scripts/get_date.sh
-rwxrwxrwx 207 1 4829 Apr 10 15:02:31 2014 lubinsu/scripts/get_itibil_acct_item_owe.sh
-rwxrwxrwx 207 1 2034 Jan 31 18:02:06 2014 lubinsu/scripts/syn_acct_item_owe_month.sh
-rwxrwxrwx 207 1 549 Nov 26 13:22:59 2013 lubinsu/scripts/syn_acct_item_owe_all.sh
-rwxr-xr-x 207 1 5135 Apr 10 15:21:00 2014 lubinsu/scripts/get_itibil_acct_item_owe_enhance.sh
-rwxrwxrwx 207 1 1070 May 30 18:11:28 2014 lubinsu/scripts/backup.sh
-rwxrwxrwx 207 1 1118 Nov 26 13:25:29 2013 lubinsu/scripts/syn_acct_item_owe_all_auto.sh
-rw-r--r-- 207 1 392 Apr 10 13:21:13 2014 lubinsu/scripts/passwd.txt
-rwxr-xr-x 207 1 400 Apr 10 14:49:11 2014 lubinsu/scripts/call_proc.sh
-rwxr-xr-x 207 1 707 Apr 01 20:15:25 2014 lubinsu/scripts/getYesterday.sh
-rwxr-xr-x 207 1 1604 Nov 08 18:26:50 2013 lubinsu/scripts/syn_acct_item_owe_day.sh
-rwxr-xr-x 207 1 2524 Jan 31 21:20:31 2014 lubinsu/scripts/syn_acct_item_owe_day_auto_bak.sh
-rwxr-xr-x 207 1 1819 Jan 02 15:46:53 2014 lubinsu/scripts/syn_acct_item_owe_month_2.sh
-rwxrwxrwx 207 1 216 Jan 08 18:04:39 2014 lubinsu/scripts/read_db_test.sh
-rwxr-xr-x 207 1 228 Jan 25 16:58:26 2014 lubinsu/scripts/logic_backup.sh
-rwxrwxrwx 207 1 1069 May 29 15:33:19 2014 lubinsu/scripts/backup.sh~
-rwxrwxrwx 207 1 298 Jan 25 16:22:18 2014 lubinsu/scripts/get_last_month.sh
-rwxrwxrwx 207 1 1436 Mar 01 23:01:52 2014 lubinsu/scripts/get_files_from_ftp.sh
-rwxrwxrwx 207 1 1029 Mar 26 16:19:19 2014 lubinsu/scripts/source_profile
-rwxr-xr-x 207 1 2523 Jun 02 21:55:32 2014 lubinsu/scripts/syn_acct_item_owe_day_auto_tmp.sh~
-rwxr-xr-x 207 1 5135 Apr 25 11:46:20 2014 lubinsu/scripts/get_itibil_acct_item_owe_enhance_1.sh~
-rwxr-xr-x 207 1 2524 Jan 31 21:11:45 2014 lubinsu/scripts/syn_acct_item_owe_day_auto.sh
-rwxr-xr-x 207 1 5137 Apr 25 12:54:38 2014 lubinsu/scripts/get_itibil_acct_item_owe_enhance_1.sh
-rwxrwxrwx 207 1 56 Jun 06 15:50:26 2014 lubinsu/scripts/killProcess.sh~
-rwxrwxrwx 207 1 21 Jun 06 15:54:47 2014 lubinsu/scripts/killProcess.sh
-rwxr-xr-x 207 1 567 May 02 08:50:21 2014 lubinsu/scripts/syn_acct_item_owe_day_auto_single.sh
-rwxr-xr-x 207 1 883 Jun 02 21:59:33 2014 lubinsu/scripts/syn_acct_item_owe_day_auto_tmp.sh
drwxr-xr-x 207 1 0 Feb 18 15:39:49 2014 lubinsu/jdk/
-rwxrwxrwx 207 1 1055 May 15 13:25:17 2014 lubinsu/exportFile.sh~
-rwxrwxrwx 207 1 363 May 15 16:33:54 2014 lubinsu/exportFile.sh
-rw-r--r-- 207 1 17200346 May 19 23:03:12 2014 lubinsu/backup-scripts.tar.gz
-rw-r--r-- 207 1 98 Jun 07 11:34:28 2014 lubinsu/excludeList.txt~
-rw-r--r-- 207 1 58 Jun 07 11:38:02 2014 lubinsu/excludeList.txt


你可能感兴趣的:(linux,shell,AIX)