SlideShare a Scribd company logo
1 of 10
Download to read offline
backup & restore
Postgresql 9.4
postgresql 9.4 のバックアップ計画
▸ バックアップ 【 backup 】
コンピュータの記憶装置に保存されたデータを別の装置や記憶媒体へ複製
して別に保管するもので、機器の故障や破損、人為ミス、不正行為などに
よってデータの消失や改変などが起こった場合に、複製した時点のデータ
に復旧させることができる。 
  
▸ リストア 【 restore 】
ハードディスクなどの記憶装置が破損するなどしてデータが失われた際に、
以前に取っておいたデータの複製を書き戻すなどして復元することをリスト
アという。     
                   引用:IT用語辞典 e-Words
http://e-words.jp/
postgresql 9.4 のバックアップ計画
Backup手法の検討
▸ コールドバックアップ
データベースを一旦止めて物理的または論理的なバックアップを取得する
→サービス停止があるので今回は❌
▸ ホットバックアップ
 データベースの停止をせずにバックアップの取得が可能→⭕️こちらを採用
⚠ バックアップ取得ポイントのみへのリカバリー
⚠ バックアップ手順が複雑→tool(pg_rman)で楽チン
+α ポイント・イン・タイム・リカバリ(PITR)
バックアップポイント後の更新をリアルタイムでアーカイブしていき、サービス停
止直前 までのリカバリを実現する。→ ⭕basebackupと組み合わせて採用
postgresql 9.4 のバックアップ計画
まとめ
basebackupによる定期的なホットバックアップ
+PITRによるリアルタイムバックアップ
pg_rmanによる定期ホットバックアップ(冗長)
!障害発生!定期backup Restore
WAL
定期backup Restore!障害発生!
この2段構えで!
basebackup + PITRによるbackup
setup
・make a replication user
#attributes
default['postgresql']['custom']['replication']['username'] = 'postgres_backup'
default['postgresql']['custom']['replication']['password'] = 'backup_passwd'
#recipes
echo “CREATE ROLE #{repl_user} WITH REPLICATION LOGIN ENCRYPTED PASSWORD ‘ ¥
#{repl_pass}’;”" | psql -p #{node[‘postgresql’][‘config’][‘port']}
・enable archive mode
# attributes
# postgresql configure
default['postgresql']['config']['archive_mode'] = ‘on
default['postgresql']['config']['archive_command'] = 'if [ ! -d #{wal_dir} ]; th
en mkdir #{wal_dir}; fi; test ! -f #{wal_dir}/%f && gzip < %p > #{wal_dir}/%f’
basebackup + PITRによるbackup
backup & restore
・basebackup
postgres $ pg_basebackup
・restore
・stop postgresql service
root # service postgresql stop
・put backup data & recovery.conf
postgres # cd $pg_data
postgres # tar xfvz yyyymmdd_basebackup.tar.gz
# postgresdata_dir/recovery.conf
gzip < <%= node['postgresql']['custom']['archive_directory'] %>%f >%p
・start postgresql service
root # service postgresql start
・クラウド環境では別ストレージを保存先にすることで冗長性確保が可能
basebackup + PITRによるbackup
directory structure
DB server
Storage A Storage B
DB data Backup data
cloud infra cloud infra cloud infra cloud infra cloud infra
pg_rmanによるbackup
setup
・github sourceからmake
https://github.com/ossc-db/pg_rman
・setup path
# .bash_profile/profile.pg_rman
export PATH=$PATH:#{node['pg_rman']['bin_path']}
export BACKUP_PATH=#{node[‘pg_rman']['backup']}
・pg_rman init
postgres $ pg_rman init -B #{node[‘pg_rman']['backup']} -A #{node['pg_rman']['arclog']} ¥
-D #{node[‘postgresql']['config']['data_directory']}
・edit pg_rman.ini
# templates->pg_rmandir/pg_rman.ini
ARCLOG_PATH=<%= node['pg_rman']['arclog'] %>
SRVLOG_PATH=<%= node['pg_rman']['backup'] %>/pg_log
PGDATA=<%= node['postgresql']['config']['data_directory'] %>
COMPRESS_DATA = <%= node['pg_rman']['config']['compress'] %>
KEEP_ARCLOG_FILES = <%= node['pg_rman']['config']['keep_arclog_files'] %>
KEEP_ARCLOG_DAYS = <%= node['pg_rman']['config']['keep_arclog_days'] %>
KEEP_DATA_GENERATIONS = <%= node['pg_rman']['config']['keep_data_generations'] %>
KEEP_DATA_DAYS = <%= node['pg_rman']['config']['keep_data_days'] %>
KEEP_SRVLOG_FILES = <%= node['pg_rman']['config']['keep_srvlog_files'] %>
KEEP_SRVLOG_DAYS = <%= node['pg_rman']['config']['keep_srvlog_days'] %>
pg_rmanによるbackup
full backup & integral backup & restore
・full backup
postgres $ pg_rman backup -b full
・incremental backup
postgres $ pg_rman backup -b incremental
・restore database
postgres $ pg_rman restore
# When you’ll set a target time
# pg_rman restore --recovery-target-time '2016-01-06 15:12:00'
backupスケジュール
▸ cronによる以下定時backup
pg_rman
毎週日曜日 2:45にfull backup
日曜日以外の毎日 2:45にincremental backup
pg_basebackup
毎週水曜日 3:45にbasebackup
▸ archive modeにて随時walを記録

More Related Content

Recently uploaded

2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
ssuserbefd24
 

Recently uploaded (12)

5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
 
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
 
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
 
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
 
Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )
 
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
 
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
 
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
 
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
 
20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf
 
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
 
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Postgresqlのbackup実装

  • 2. postgresql 9.4 のバックアップ計画 ▸ バックアップ 【 backup 】 コンピュータの記憶装置に保存されたデータを別の装置や記憶媒体へ複製 して別に保管するもので、機器の故障や破損、人為ミス、不正行為などに よってデータの消失や改変などが起こった場合に、複製した時点のデータ に復旧させることができる。     ▸ リストア 【 restore 】 ハードディスクなどの記憶装置が破損するなどしてデータが失われた際に、 以前に取っておいたデータの複製を書き戻すなどして復元することをリスト アという。                         引用:IT用語辞典 e-Words http://e-words.jp/
  • 3. postgresql 9.4 のバックアップ計画 Backup手法の検討 ▸ コールドバックアップ データベースを一旦止めて物理的または論理的なバックアップを取得する →サービス停止があるので今回は❌ ▸ ホットバックアップ  データベースの停止をせずにバックアップの取得が可能→⭕️こちらを採用 ⚠ バックアップ取得ポイントのみへのリカバリー ⚠ バックアップ手順が複雑→tool(pg_rman)で楽チン +α ポイント・イン・タイム・リカバリ(PITR) バックアップポイント後の更新をリアルタイムでアーカイブしていき、サービス停 止直前 までのリカバリを実現する。→ ⭕basebackupと組み合わせて採用
  • 5. basebackup + PITRによるbackup setup ・make a replication user #attributes default['postgresql']['custom']['replication']['username'] = 'postgres_backup' default['postgresql']['custom']['replication']['password'] = 'backup_passwd' #recipes echo “CREATE ROLE #{repl_user} WITH REPLICATION LOGIN ENCRYPTED PASSWORD ‘ ¥ #{repl_pass}’;”" | psql -p #{node[‘postgresql’][‘config’][‘port']} ・enable archive mode # attributes # postgresql configure default['postgresql']['config']['archive_mode'] = ‘on default['postgresql']['config']['archive_command'] = 'if [ ! -d #{wal_dir} ]; th en mkdir #{wal_dir}; fi; test ! -f #{wal_dir}/%f && gzip < %p > #{wal_dir}/%f’
  • 6. basebackup + PITRによるbackup backup & restore ・basebackup postgres $ pg_basebackup ・restore ・stop postgresql service root # service postgresql stop ・put backup data & recovery.conf postgres # cd $pg_data postgres # tar xfvz yyyymmdd_basebackup.tar.gz # postgresdata_dir/recovery.conf gzip < <%= node['postgresql']['custom']['archive_directory'] %>%f >%p ・start postgresql service root # service postgresql start
  • 7. ・クラウド環境では別ストレージを保存先にすることで冗長性確保が可能 basebackup + PITRによるbackup directory structure DB server Storage A Storage B DB data Backup data cloud infra cloud infra cloud infra cloud infra cloud infra
  • 8. pg_rmanによるbackup setup ・github sourceからmake https://github.com/ossc-db/pg_rman ・setup path # .bash_profile/profile.pg_rman export PATH=$PATH:#{node['pg_rman']['bin_path']} export BACKUP_PATH=#{node[‘pg_rman']['backup']} ・pg_rman init postgres $ pg_rman init -B #{node[‘pg_rman']['backup']} -A #{node['pg_rman']['arclog']} ¥ -D #{node[‘postgresql']['config']['data_directory']} ・edit pg_rman.ini # templates->pg_rmandir/pg_rman.ini ARCLOG_PATH=<%= node['pg_rman']['arclog'] %> SRVLOG_PATH=<%= node['pg_rman']['backup'] %>/pg_log PGDATA=<%= node['postgresql']['config']['data_directory'] %> COMPRESS_DATA = <%= node['pg_rman']['config']['compress'] %> KEEP_ARCLOG_FILES = <%= node['pg_rman']['config']['keep_arclog_files'] %> KEEP_ARCLOG_DAYS = <%= node['pg_rman']['config']['keep_arclog_days'] %> KEEP_DATA_GENERATIONS = <%= node['pg_rman']['config']['keep_data_generations'] %> KEEP_DATA_DAYS = <%= node['pg_rman']['config']['keep_data_days'] %> KEEP_SRVLOG_FILES = <%= node['pg_rman']['config']['keep_srvlog_files'] %> KEEP_SRVLOG_DAYS = <%= node['pg_rman']['config']['keep_srvlog_days'] %>
  • 9. pg_rmanによるbackup full backup & integral backup & restore ・full backup postgres $ pg_rman backup -b full ・incremental backup postgres $ pg_rman backup -b incremental ・restore database postgres $ pg_rman restore # When you’ll set a target time # pg_rman restore --recovery-target-time '2016-01-06 15:12:00'
  • 10. backupスケジュール ▸ cronによる以下定時backup pg_rman 毎週日曜日 2:45にfull backup 日曜日以外の毎日 2:45にincremental backup pg_basebackup 毎週水曜日 3:45にbasebackup ▸ archive modeにて随時walを記録