UIから手動で実行するのは面倒だし、API使ってプログラム書くのも面倒だしと思って簡易なshellを作成。備忘録程度に。
# ! /bin/bash
tables=`bq --project_id $1 ls $2 | perl -ane 'print $F[0] . "\n" if $.>2'`
for table in $tables
do
bq --project_id $1 extract $2.$table gs://$3/tables/$table.csv
done
$1
はproject id、$2
はdataset、$3
はbucket
削除する場合はbq --project_id $1 rm -f $2.table
を代わりに使う。
テーブルの行数を数えるときは、bq --project_id <project> show <dataset>.<table> | perl -ane 'print $F[6] . "\n" if $.==5' 1
をtabelsに代入してtotalを求める