add auto fetch ssl certs
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
"datePublished": "2019-09-05 11:42:28 \x2b0800 CST",
|
||||
"dateModified" : "2019-09-05 11:42:28 \x2b0800 CST",
|
||||
"url" : "https:\/\/h.cowbay.org\/post\/backup-restore-postgresql-with-pgbackrest\/",
|
||||
"wordCount" : "818",
|
||||
"wordCount" : "816",
|
||||
"image" : "https://h.cowbay.orghttps://h.cowbay.org/images/post-default-15.jpg"",
|
||||
"keywords" : [ ""postgresql"","Blog" ]
|
||||
}
|
||||
@@ -45,9 +45,9 @@
|
||||
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
||||
|
||||
<link href="https://h.cowbay.org/css/style.css?v=1626744134" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/style.css?v=1629951055" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1626744134" rel="stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1629951055" rel="stylesheet" type='text/css' media='all'>
|
||||
<link rel="shortcut icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
|
||||
<link rel="icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
|
||||
|
||||
@@ -81,10 +81,6 @@ if (!doNotTrack) {
|
||||
|
||||
<ul id="menu-secondary-items" class="menu-secondary-items">
|
||||
|
||||
<li class="menu-item menu-item-type-taxonomy menu-item-object-category">
|
||||
<a href="/categories/"></a>
|
||||
</li>
|
||||
|
||||
<li class="menu-item menu-item-type-taxonomy menu-item-object-category">
|
||||
<a href="/categories/ansible">ansible</a>
|
||||
</li>
|
||||
@@ -309,28 +305,18 @@ if (!doNotTrack) {
|
||||
<div class="entry-content">
|
||||
<article>
|
||||
<p>這兩天在測試pgbackrest ,簡單筆記一下測試狀況</p>
|
||||
|
||||
<h4 id="install">install</h4>
|
||||
|
||||
<p>在ubuntu 18.04 安裝pgbackrest 很簡單,內建在apt裡面,所以可以直接用</p>
|
||||
|
||||
<pre><code>sudo apt install pgbackrest
|
||||
</code></pre>
|
||||
|
||||
<p>進行安裝</p>
|
||||
|
||||
</code></pre><p>進行安裝</p>
|
||||
<h4 id="config">config</h4>
|
||||
|
||||
<p>pgbackrest 的設定檔在 /etc/pgbackrest/pgbackrest.conf
|
||||
如果是用apt 安裝,預設會建立一個 /etc/pgbackrest.conf
|
||||
但是這個路徑是錯誤的
|
||||
執行 pgbackrest的時候,預設還是會去讀取 /etc/pgbackrest/pgbackrest.conf
|
||||
要特別注意,要不就是每次都指定config路徑,要不就是把那個錯誤的設定檔幹掉</p>
|
||||
|
||||
<h4 id="config-內容">config 內容</h4>
|
||||
|
||||
<p>內容其實很簡單</p>
|
||||
|
||||
<pre><code>postgres@hqdc039:~$ cat /etc/pgbackrest/pgbackrest.conf
|
||||
[demo]
|
||||
pg1-path=/database/11/main
|
||||
@@ -344,47 +330,37 @@ repo1-retention-full=2
|
||||
[global:archive-push]
|
||||
compress-level=3
|
||||
process-max=4
|
||||
</code></pre>
|
||||
|
||||
<p><strong>[demo]</strong> 用來指定這個 “stanza” 的名稱
|
||||
* pg1-path 是資料庫存放的路徑</p>
|
||||
|
||||
</code></pre><p><strong>[demo]</strong> 用來指定這個 “stanza” 的名稱</p>
|
||||
<ul>
|
||||
<li>pg1-path 是資料庫存放的路徑</li>
|
||||
</ul>
|
||||
<p><strong>[global]</strong> 中的兩個cipher 用途我不清楚,不設定也沒關係</p>
|
||||
|
||||
<ul>
|
||||
<li>“repo1-path” 則是用來存放備份的路徑</li>
|
||||
<li>“repo1-retention-full” 定義要保留幾次 full backup</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>[global:archive-push]</strong> 似乎是用來定義在備份/還原時的選項
|
||||
* process-max 指定要用多少process (平行處理)</p>
|
||||
|
||||
<p><strong>[global:archive-push]</strong> 似乎是用來定義在備份/還原時的選項</p>
|
||||
<ul>
|
||||
<li>process-max 指定要用多少process (平行處理)</li>
|
||||
</ul>
|
||||
<h4 id="簡單流程">簡單流程</h4>
|
||||
|
||||
<ul>
|
||||
<li>config (pgbackrest & postgresql )</li>
|
||||
<li>建立 stanza</li>
|
||||
<li>建立備份</li>
|
||||
<li>(還原,如果有需要的話)</li>
|
||||
</ul>
|
||||
|
||||
<h4 id="其他部份">其他部份</h4>
|
||||
|
||||
<ul>
|
||||
<li>清除 stanza (刪除備份)</li>
|
||||
<li>踩到的地雷</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
|
||||
<h4 id="設定-pgbackrest-postgresql">設定 pgbackrest & postgresql</h4>
|
||||
|
||||
<hr>
|
||||
<h4 id="設定-pgbackrest--postgresql">設定 pgbackrest & postgresql</h4>
|
||||
<p>pgbackrest 基本上設定很簡單,內容就跟上面的一樣就可以跑了。
|
||||
當然要新增其他進階的,就要自己研究了,內容有夠長
|
||||
<a href="https://pgbackrest.org/configuration.html">https://pgbackrest.org/configuration.html</a></p>
|
||||
|
||||
<p>在postgresql 中,要新增一些設定,主要是 archive_command</p>
|
||||
|
||||
<pre><code>postgres@hqdc039:~$ grep -A 100 "for pgbackrest" /etc/postgresql/11/main/postgresql.conf
|
||||
#for pgbackrest
|
||||
archive_command = 'pgbackrest --stanza=demo archive-push %p'
|
||||
@@ -394,52 +370,34 @@ log_line_prefix = ''
|
||||
max_wal_senders = 3
|
||||
wal_level = replica
|
||||
postgres@hqdc039:~$
|
||||
</code></pre>
|
||||
|
||||
<p><strong>archive_command</strong>
|
||||
</code></pre><p><strong>archive_command</strong>
|
||||
這個因為要帶stanza 名稱進來,所以<strong>需要跟pgbackrest.conf 裡面定義的名稱一致</strong></p>
|
||||
|
||||
<p><strong>max_wal_senders</strong>
|
||||
簡單說就是定義在抄寫wal 的時候,可以同時抄給幾台
|
||||
這是postgresql 的說明</p>
|
||||
|
||||
<pre><code>the maximum number of simultaneously running WAL sender processes
|
||||
</code></pre>
|
||||
|
||||
<p><strong>wal_level</strong>
|
||||
</code></pre><p><strong>wal_level</strong>
|
||||
有三種等級,參考 <a href="https://blog.csdn.net/pg_hgdb/article/details/78666719">https://blog.csdn.net/pg_hgdb/article/details/78666719</a></p>
|
||||
|
||||
<ul>
|
||||
<li>minimal –不能通过基础备份和wal日志恢复数据库。</li>
|
||||
<li>replica = 9.6版本以前的archive和hot_standby –该级别支持wal归档和复制。</li>
|
||||
<li>logical –在replica级别的基础上添加了支持逻辑解码所需的信息。</li>
|
||||
</ul>
|
||||
|
||||
<p>設定完成後,重起 postgresql 就可以了</p>
|
||||
|
||||
<h4 id="建立-stanza">建立 stanza</h4>
|
||||
|
||||
<p>stanza 這名詞我是第一次聽到,直接翻譯就是 <strong>”“(詩的)節,段”</strong></p>
|
||||
|
||||
<p>stanza 這名詞我是第一次聽到,直接翻譯就是 <strong>""(詩的)節,段”</strong></p>
|
||||
<p><a href="https://dictionary.cambridge.org/zht/%E8%A9%9E%E5%85%B8/%E8%8B%B1%E8%AA%9E-%E6%BC%A2%E8%AA%9E-%E7%B9%81%E9%AB%94/stanza">https://dictionary.cambridge.org/zht/%E8%A9%9E%E5%85%B8/%E8%8B%B1%E8%AA%9E-%E6%BC%A2%E8%AA%9E-%E7%B9%81%E9%AB%94/stanza</a></p>
|
||||
|
||||
<p>在pgbackrest中,可以一次定義多個 stanza,用來備份不同的DB
|
||||
這次環境很簡單,所以就只有設定一個
|
||||
依照上面的pgbackrest.conf 內容設定好了,需要先建立這個stanza
|
||||
指令:</p>
|
||||
|
||||
<pre><code>postgres@hqdc039:~$ pgbackrest --stanza=demo stanza-create --log-level-console=detail
|
||||
2019-09-04 16:21:40.700 P00 INFO: stanza-create command begin 2.16: --log-level-console=detail --pg1-path=/database/11/main --repo1-cipher-pass=<redacted> --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --stanza=demo
|
||||
2019-09-04 16:21:41.525 P00 INFO: stanza-create command end: completed successfully (825ms)
|
||||
postgres@hqdc039:~$
|
||||
</code></pre>
|
||||
|
||||
<p>接著就可以執行備份了</p>
|
||||
|
||||
</code></pre><p>接著就可以執行備份了</p>
|
||||
<h4 id="backup">backup</h4>
|
||||
|
||||
<p>備份指令也很簡單,要注意的是,如果不帶參數,pgbackrest 會自行決定要用incremental或者是 full backup</p>
|
||||
|
||||
<pre><code>postgres@hqdc039:~$ pgbackrest --stanza=demo --log-level-console=detail backup
|
||||
2019-09-04 16:41:17.458 P00 INFO: backup command begin 2.16: --log-level-console=detail --pg1-path=/database/11/main --repo1-cipher-pass=<redacted> --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=demo
|
||||
2019-09-04 16:41:17.697 P00 INFO: last backup label = 20190904-134245F, version = 2.16
|
||||
@@ -466,10 +424,7 @@ WARN: a timeline switch has occurred since the last backup, enabling delta check
|
||||
2019-09-04 16:41:25.215 P00 DETAIL: no archive to remove, archiveId = 11-1
|
||||
2019-09-04 16:41:25.215 P00 INFO: expire command end: completed successfully (21ms)
|
||||
postgres@hqdc039:~$
|
||||
</code></pre>
|
||||
|
||||
<p>執行後,可以檢查一下</p>
|
||||
|
||||
</code></pre><p>執行後,可以檢查一下</p>
|
||||
<pre><code>postgres@hqdc039:~$ pgbackrest --stanza=demo --log-level-console=info info
|
||||
stanza: demo
|
||||
status: ok
|
||||
@@ -491,30 +446,19 @@ stanza: demo
|
||||
repository size: 547MB, repository backup size: 220.4KB
|
||||
backup reference list: 20190904-134245F
|
||||
postgres@hqdc039:~$
|
||||
</code></pre>
|
||||
|
||||
<h4 id="還原測試">還原測試</h4>
|
||||
|
||||
</code></pre><h4 id="還原測試">還原測試</h4>
|
||||
<p>pgbackrest 的還原因為透過WAL ,所以有一些觀念需要先釐清
|
||||
本來我的測試是先做好備份,然後直接砍掉 DB,接著再用restore還原
|
||||
卻發現砍掉的DB居然沒有回來..
|
||||
後來看了這一篇,然後又研究了一下 <strong>Point-in-Time Recovery</strong>
|
||||
<a href="https://github.com/pgbackrest/pgbackrest/issues/800">https://github.com/pgbackrest/pgbackrest/issues/800</a>
|
||||
才找到正確的用法</p>
|
||||
|
||||
<p>先把DB整個砍掉</p>
|
||||
|
||||
<pre><code>postgres@hqdc034:/zp/database$ time dropdb demo
|
||||
</code></pre>
|
||||
|
||||
<p>然後停止postgresql 服務</p>
|
||||
|
||||
</code></pre><p>然後停止postgresql 服務</p>
|
||||
<pre><code>postgres@hqdc034:/zp/database$ pg_ctlcluster 10 main stop
|
||||
sudo systemctl stop postgresql@10-main
|
||||
</code></pre>
|
||||
|
||||
<p>接著就可以來下指令還原了</p>
|
||||
|
||||
</code></pre><p>接著就可以來下指令還原了</p>
|
||||
<pre><code>postgres@hqdc034:/zp/database$ time pgbackrest --stanza=demo --log-level-console=info --delta --type=time "--target=2019-09-05 11:00:00.268248+08" --target-action=promote restore
|
||||
2019-09-05 11:15:57.480 P00 INFO: restore command begin 2.13: --delta --log-level-console=info --pg1-path=/zp/database/10/main --process-max=4 --repo1-path=/var/lib/pgbackrest --stanza=demo --target="2019-09-05 11:00:00.268248+08" --target-action=promote --type=time
|
||||
2019-09-05 11:15:57.624 P00 INFO: restore backup set 20190905-111109F
|
||||
@@ -527,25 +471,16 @@ postgres@hqdc039:~$
|
||||
real 0m3.328s
|
||||
user 0m6.896s
|
||||
sys 0m0.832s
|
||||
</code></pre>
|
||||
|
||||
<p>在DB目錄中,會產生一個recovery.conf,這是用來給 postgresql 看的檔案,裡面會紀錄怎麼還原、以及還原的類型、時間點,這邊指定要恢復到 <strong><em>2019-09-05 11:00:00.268248+08</em></strong>
|
||||
</code></pre><p>在DB目錄中,會產生一個recovery.conf,這是用來給 postgresql 看的檔案,裡面會紀錄怎麼還原、以及還原的類型、時間點,這邊指定要恢復到 <em><strong>2019-09-05 11:00:00.268248+08</strong></em>
|
||||
這個時間格式要看資料庫的設定,可以藉由以下指令得到</p>
|
||||
|
||||
<pre><code>postgres@hqdc034:/zp/database$ psql -Atc "select current_timestamp"
|
||||
2019-09-05 11:14:27.268248+08
|
||||
</code></pre>
|
||||
|
||||
<p>檢查一下recovery.conf</p>
|
||||
|
||||
</code></pre><p>檢查一下recovery.conf</p>
|
||||
<pre><code>postgres@hqdc034:/zp/database$ cat /zp/database/10/main/recovery.conf
|
||||
restore_command = 'pgbackrest --log-level-console=info --stanza=demo archive-get %f "%p"'
|
||||
recovery_target_time = '2019-09-05 11:00:00.268248+08'
|
||||
recovery_target_action = 'promote'
|
||||
</code></pre>
|
||||
|
||||
<p>重新啟動postgresql 然後看看被砍掉的demo DB有沒有回來</p>
|
||||
|
||||
</code></pre><p>重新啟動postgresql 然後看看被砍掉的demo DB有沒有回來</p>
|
||||
<pre><code>postgres@hqdc034:/zp/database$ pg_ctlcluster 10 main start
|
||||
Warning: the cluster will not be running as a systemd service. Consider using systemctl:
|
||||
sudo systemctl start postgresql@10-main
|
||||
@@ -567,10 +502,7 @@ postgres=# \l
|
||||
|
||||
postgres=# \q
|
||||
postgres@hqdc034:/zp/database$
|
||||
</code></pre>
|
||||
|
||||
<p>很好, demo DB 有順利的還原回來了,先暫時測試到這邊。接下來要來玩postgresql on zfs</p>
|
||||
|
||||
</code></pre><p>很好, demo DB 有順利的還原回來了,先暫時測試到這邊。接下來要來玩postgresql on zfs</p>
|
||||
<p>後續如果想更深入測試 pgbackrest,可以試試看異機備份還原。</p>
|
||||
</article>
|
||||
</div>
|
||||
@@ -846,7 +778,7 @@ title="pinterest icon"></i>
|
||||
|
||||
</ul> <div class="design-credit">
|
||||
|
||||
<p>© 2018 Göran Svensson</p>
|
||||
<p>© 2018 Göran Svensson</p>
|
||||
|
||||
<p>Nederburg Hugo Theme by <a href="https://appernetic.io">Appernetic</a>.</p>
|
||||
|
||||
@@ -858,7 +790,7 @@ title="pinterest icon"></i>
|
||||
</div>
|
||||
<script src="https://h.cowbay.org/js/jquery.min.js"></script>
|
||||
<script src="https://h.cowbay.org/js/jquerymigrate.js"></script>
|
||||
<script src="https://h.cowbay.org/js/production.min.js?v=1626744134"></script>
|
||||
<script src="https://h.cowbay.org/js/production.min.js?v=1629951055"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user