[Solved] How to take backup of a BigQuery view script using BQ?


In case you would like to backup view’s sql query code only:

bq mk \
--nouse_legacy 
--view "$(bq show --view --format=prettyjson project1:dataset1.view1 | jq --raw-output .view.query)" \
project2:dataset2.view2

I used jq json tool.

In case you would like to materialise the view into table:

bq query --nouse_legacy --destination_table=project1:dataset1.table1 "SELECT * FROM project1.dataset1.view1"

Update:

In case you would like to copy exisiting table to another just do

bq cp project1:dataset1.table1 project2:dataset2.table2

solved How to take backup of a BigQuery view script using BQ?