需要备份的schema列表
$ cat /usr/local/pgsql/dba/exp/need_backup_schema.txt
$ cat need_backup_schema.txt pipeline_na_16q3_v4 pipeline_na_16q4_v8 pipeline_na_16q4_v8_ap_delta pipeline_na_16q4_v8_dup_ids_fix pipeline_na_17q1_v9_admin_rel pipeline_na_17q1_v9_rel pipeline_na_17q2_v10_rel pipeline_na_17q2_v9_rel_usa_fixes pipeline_na_17q3_17q1_v11_rel pipeline_na_17q3_v11_base_rel pipeline_na_17q3_v11_delta_rel pipeline_na_17q3_v11_rel pipeline_na_17q4_v11_base_rel pipeline_na_17q4_v11_rel uber_anz_geocoder_16q4_v1 uber_anz_geocoder_16q4_v14 uber_anz_geocoder_16q4_v15 uber_anz_geocoder_17q1_v15 uber_eu_geocoder_16q3_v14 uber_eu_geocoder_17q1_v14 uber_na_geocoder_16q1_v13 uber_na_geocoder_16q1_v13_patch uber_na_geocoder_16q3_v14 uber_na_geocoder_16q4_v14 uber_na_geocoder_16q4_v15 uber_na_geocoder_17q1_v14 uber_na_geocoder_17q1_v14_mex uber_na_geocoder_17q2_v15 uber_na_geocoder_17q3_v16 uber_na_geocoder_17q4_v16 uber_sea_geocoder_17q1_v1 uber_sea_geocoder_17q1_v3 uber_sea_geocoder_17q2_v1 uber_sea_geocoder_17q2_v2
循环备份的脚本
#! /bin/sh -x database="TnGeo-Here-Data" current_day=`date '+%Y%m%d'` backup_dir="/usr/local/pgsql/dba/exp" mail_list="******" for schema in `cat need_backup_schema.txt`; do /usr/local/pgsql/bin/pg_dump --verbose --schema=${schema} ${database} | gzip > ${backup_dir}/${database}_${schema}_${current_day}.sql.gz if [ $? -ne 0 ]; then mail -s "${schema} backup failed" ${mail_list} < /dev/null exit 1 fi done exit 0
备份完成后生成的备份名
$ ls -ltrh total 208G -rw-r--r-- 1 postgres appuser 22G Dec 13 06:15 TnGeo-Here-Data_pipeline_na_16q3_v4_20191213.sql.gz -rw-r--r-- 1 postgres appuser 13G Dec 13 07:07 TnGeo-Here-Data_pipeline_na_16q4_v8_20191213.sql.gz -rw-r--r-- 1 postgres appuser 473 Dec 13 07:07 TnGeo-Here-Data_pipeline_na_16q4_v8_ap_delta_20191213.sql.gz -rw-r--r-- 1 postgres appuser 2.6M Dec 13 07:07 TnGeo-Here-Data_pipeline_na_16q4_v8_dup_ids_fix_20191213.sql.gz -rw-r--r-- 1 postgres appuser 473 Dec 13 07:07 TnGeo-Here-Data_pipeline_na_17q1_v9_admin_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 12G Dec 13 07:56 TnGeo-Here-Data_pipeline_na_17q1_v9_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 18G Dec 13 09:11 TnGeo-Here-Data_pipeline_na_17q2_v10_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 11G Dec 13 09:52 TnGeo-Here-Data_pipeline_na_17q2_v9_rel_usa_fixes_20191213.sql.gz -rw-r--r-- 1 postgres appuser 3.2G Dec 13 10:06 TnGeo-Here-Data_pipeline_na_17q3_17q1_v11_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 13G Dec 13 11:10 TnGeo-Here-Data_pipeline_na_17q3_v11_base_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 6.3G Dec 13 11:59 TnGeo-Here-Data_pipeline_na_17q3_v11_delta_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 5.9K Dec 13 11:59 TnGeo-Here-Data_pipeline_na_17q3_v11_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 13G Dec 13 13:08 TnGeo-Here-Data_pipeline_na_17q4_v11_base_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 4.0K Dec 13 13:08 TnGeo-Here-Data_pipeline_na_17q4_v11_rel_20191213.sql.gz -rw-r--r-- 1 postgres appuser 756M Dec 13 13:10 TnGeo-Here-Data_uber_anz_geocoder_16q4_v1_20191213.sql.gz -rw-r--r-- 1 postgres appuser 755M Dec 13 13:13 TnGeo-Here-Data_uber_anz_geocoder_16q4_v14_20191213.sql.gz -rw-r--r-- 1 postgres appuser 756M Dec 13 13:16 TnGeo-Here-Data_uber_anz_geocoder_16q4_v15_20191213.sql.gz -rw-r--r-- 1 postgres appuser 762M Dec 13 13:18 TnGeo-Here-Data_uber_anz_geocoder_17q1_v15_20191213.sql.gz -rw-r--r-- 1 postgres appuser 14G Dec 13 14:19 TnGeo-Here-Data_uber_eu_geocoder_16q3_v14_20191213.sql.gz -rw-r--r-- 1 postgres appuser 14G Dec 13 15:19 TnGeo-Here-Data_uber_eu_geocoder_17q1_v14_20191213.sql.gz -rw-r--r-- 1 postgres appuser 8.1G Dec 13 15:59 TnGeo-Here-Data_uber_na_geocoder_16q1_v13_20191213.sql.gz -rw-r--r-- 1 postgres appuser 98M Dec 13 16:00 TnGeo-Here-Data_uber_na_geocoder_16q1_v13_patch_20191213.sql.gz -rw-r--r-- 1 postgres appuser 9.1G Dec 13 16:36 TnGeo-Here-Data_uber_na_geocoder_16q3_v14_20191213.sql.gz -rw-r--r-- 1 postgres appuser 9.2G Dec 13 17:11 TnGeo-Here-Data_uber_na_geocoder_16q4_v14_20191213.sql.gz -rw-r--r-- 1 postgres appuser 2.3K Dec 13 17:11 TnGeo-Here-Data_uber_na_geocoder_16q4_v15_20191213.sql.gz -rw-r--r-- 1 postgres appuser 9.2G Dec 13 17:47 TnGeo-Here-Data_uber_na_geocoder_17q1_v14_20191213.sql.gz -rw-r--r-- 1 postgres appuser 3.8K Dec 13 17:47 TnGeo-Here-Data_uber_na_geocoder_17q1_v14_mex_20191213.sql.gz -rw-r--r-- 1 postgres appuser 11G Dec 13 18:32 TnGeo-Here-Data_uber_na_geocoder_17q2_v15_20191213.sql.gz -rw-r--r-- 1 postgres appuser 12G Dec 13 19:30 TnGeo-Here-Data_uber_na_geocoder_17q3_v16_20191213.sql.gz -rw-r--r-- 1 postgres appuser 11G Dec 13 20:14 TnGeo-Here-Data_uber_na_geocoder_17q4_v16_20191213.sql.gz -rw-r--r-- 1 postgres appuser 139M Dec 13 20:16 TnGeo-Here-Data_uber_sea_geocoder_17q1_v1_20191213.sql.gz -rw-r--r-- 1 postgres appuser 324M Dec 13 20:18 TnGeo-Here-Data_uber_sea_geocoder_17q1_v3_20191213.sql.gz -rw-r--r-- 1 postgres appuser 320M Dec 13 20:19 TnGeo-Here-Data_uber_sea_geocoder_17q2_v1_20191213.sql.gz -rw-r--r-- 1 postgres appuser 449M Dec 13 20:22 TnGeo-Here-Data_uber_sea_geocoder_17q2_v2_20191213.sql.gz