Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在一个sh脚本上备份多个表_Bash_Postgresql_Backup_Multiple Tables - Fatal编程技术网

Bash 在一个sh脚本上备份多个表

Bash 在一个sh脚本上备份多个表,bash,postgresql,backup,multiple-tables,Bash,Postgresql,Backup,Multiple Tables,我有一个脚本,可以在一行中备份多个表,如下所示: /usr/local/pgsql/bin/pg_dump --quote-all-identifiers --username=postgres -p 5432 -t schema.table1 -t schema.table2 -t schema.table3 -t schema.table4 -h localhost mydb | gzip -1 > file.dmp.gz 我已经创建了一个新的sh脚本,以便能够按如下方式重新利用该

我有一个脚本,可以在一行中备份多个表,如下所示:

/usr/local/pgsql/bin/pg_dump  --quote-all-identifiers --username=postgres -p 5432 -t schema.table1 -t schema.table2 -t schema.table3 -t schema.table4 -h localhost mydb | gzip -1 > file.dmp.gz
我已经创建了一个新的sh脚本,以便能够按如下方式重新利用该命令:

/usr/local/pgsql/bin/pg_dump  --quote-all-identifiers --username=postgres -p 5432 -t schema.table1 -t schema.table2 -t schema.table3 -t schema.table4 -h localhost mydb | gzip -1 > file.dmp.gz
backup_table.sh

$TABLE=$1
$DESTINATION=$2

/usr/local/pgsql/bin/pg_dump  --quote-all-identifiers --username=postgres -p 5432 -t $TABLE -h localhost mydb | gzip -1 > $DESTINATION
如您所见,这只适用于1个表,我不确定如何将多个表传递给sh脚本(-t table1-t table2-t table3等)

我可以使用数组,但仍然不确定如何编写代码


谢谢

如果您愿意将
DESTINATION
作为第一个预期参数,那么类似的方法应该适用于您:

DESTINATION=$1
TABLES=`echo ${@:2}|sed "s/\s/ -t /g"`

/usr/local/pgsql/bin/pg_dump  --quote-all-identifiers --username=postgres -p 5432 -t $TABLES -h localhost mydb | gzip -1 > $DESTINATION