-- 1. クラスターの作成
aws redshift create-cluster \
--db-name test \
--cluster-identifier redshift01 \
--cluster-type single-node \
--node-type dc2.large \
--master-username test \
--master-user-password 'password' \
--no-allow-version-upgrade \
--no-publicly-accessible \
--automated-snapshot-retention-period 0
aws redshift describe-clusters
aws redshift describe-clusters --cluster-identifier redshift01
psql -h redshift01.xxxxxxxxxxxx.ap-northeast-1.redshift.amazonaws.com -p 5439 -d test -U test
drop table tab1;
create table tab1(col1 int);
insert into tab1 values(1);
select * from tab1;
-- 2. スナップショットの作成
aws redshift create-cluster-snapshot \
--cluster-identifier redshift01 \
--snapshot-identifier snap01
aws redshift describe-cluster-snapshots
-- 3. 使用ストレージサイズに関する情報を取得
aws redshift describe-storage
-- 4. スナップショットからのクラスターの復元
aws redshift restore-from-cluster-snapshot \
--cluster-identifier redshift02 \
--snapshot-identifier snap01 \
--no-allow-version-upgrade \
--no-publicly-accessible \
--automated-snapshot-retention-period 0 \
--node-type dc2.large \
--number-of-nodes 1
psql -h redshift02.xxxxxxxxxxxx.ap-northeast-1.redshift.amazonaws.com -p 5439 -d test -U test
-- 5. スナップショットからのテーブルの復元
aws redshift restore-table-from-cluster-snapshot \
--cluster-identifier redshift01 \
--snapshot-identifier snap01 \
--source-database-name test \
--source-schema-name public \
--source-table-name tab1 \
--target-database-name test \
--target-schema-name public \
--new-table-name tab2
psql -h redshift01.xxxxxxxxxxxx.ap-northeast-1.redshift.amazonaws.com -p 5439 -d test -U test
-- 6. クリーンアップ
-- クラスターの削除
aws redshift delete-cluster \
--cluster-identifier redshift01 \
--skip-final-cluster-snapshot
aws redshift delete-cluster \
--cluster-identifier redshift02 \
--skip-final-cluster-snapshot
-- スナップショットの削除
aws redshift delete-cluster-snapshot --snapshot-identifier snap01