update some content
This commit is contained in:
@@ -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=1634607506" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/style.css?v=1635401692" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1634607506" rel="stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1635401692" 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">
|
||||
|
||||
@@ -307,7 +307,7 @@ if (!doNotTrack) {
|
||||
<p>這兩天在測試pgbackrest ,簡單筆記一下測試狀況</p>
|
||||
<h4 id="install">install</h4>
|
||||
<p>在ubuntu 18.04 安裝pgbackrest 很簡單,內建在apt裡面,所以可以直接用</p>
|
||||
<pre tabindex="0"><code>sudo apt install pgbackrest
|
||||
<pre><code>sudo apt install pgbackrest
|
||||
</code></pre><p>進行安裝</p>
|
||||
<h4 id="config">config</h4>
|
||||
<p>pgbackrest 的設定檔在 /etc/pgbackrest/pgbackrest.conf
|
||||
@@ -317,7 +317,7 @@ if (!doNotTrack) {
|
||||
要特別注意,要不就是每次都指定config路徑,要不就是把那個錯誤的設定檔幹掉</p>
|
||||
<h4 id="config-內容">config 內容</h4>
|
||||
<p>內容其實很簡單</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc039:~$ cat /etc/pgbackrest/pgbackrest.conf
|
||||
<pre><code>postgres@hqdc039:~$ cat /etc/pgbackrest/pgbackrest.conf
|
||||
[demo]
|
||||
pg1-path=/database/11/main
|
||||
|
||||
@@ -361,7 +361,7 @@ process-max=4
|
||||
當然要新增其他進階的,就要自己研究了,內容有夠長
|
||||
<a href="https://pgbackrest.org/configuration.html">https://pgbackrest.org/configuration.html</a></p>
|
||||
<p>在postgresql 中,要新增一些設定,主要是 archive_command</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc039:~$ grep -A 100 "for pgbackrest" /etc/postgresql/11/main/postgresql.conf
|
||||
<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'
|
||||
archive_mode = on
|
||||
@@ -375,7 +375,7 @@ postgres@hqdc039:~$
|
||||
<p><strong>max_wal_senders</strong>
|
||||
簡單說就是定義在抄寫wal 的時候,可以同時抄給幾台
|
||||
這是postgresql 的說明</p>
|
||||
<pre tabindex="0"><code>the maximum number of simultaneously running WAL sender processes
|
||||
<pre><code>the maximum number of simultaneously running WAL sender processes
|
||||
</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>
|
||||
@@ -391,14 +391,14 @@ postgres@hqdc039:~$
|
||||
這次環境很簡單,所以就只有設定一個
|
||||
依照上面的pgbackrest.conf 內容設定好了,需要先建立這個stanza
|
||||
指令:</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc039:~$ pgbackrest --stanza=demo stanza-create --log-level-console=detail
|
||||
<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>
|
||||
<h4 id="backup">backup</h4>
|
||||
<p>備份指令也很簡單,要注意的是,如果不帶參數,pgbackrest 會自行決定要用incremental或者是 full backup</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc039:~$ pgbackrest --stanza=demo --log-level-console=detail backup
|
||||
<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
|
||||
2019-09-04 16:41:18.607 P00 INFO: execute non-exclusive pg_start_backup() with label "pgBackRest backup started at 2019-09-04 16:41:17": backup begins after the next regular checkpoint completes
|
||||
@@ -425,7 +425,7 @@ WARN: a timeline switch has occurred since the last backup, enabling delta check
|
||||
2019-09-04 16:41:25.215 P00 INFO: expire command end: completed successfully (21ms)
|
||||
postgres@hqdc039:~$
|
||||
</code></pre><p>執行後,可以檢查一下</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc039:~$ pgbackrest --stanza=demo --log-level-console=info info
|
||||
<pre><code>postgres@hqdc039:~$ pgbackrest --stanza=demo --log-level-console=info info
|
||||
stanza: demo
|
||||
status: ok
|
||||
cipher: aes-256-cbc
|
||||
@@ -454,12 +454,12 @@ postgres@hqdc039:~$
|
||||
<a href="https://github.com/pgbackrest/pgbackrest/issues/800">https://github.com/pgbackrest/pgbackrest/issues/800</a>
|
||||
才找到正確的用法</p>
|
||||
<p>先把DB整個砍掉</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc034:/zp/database$ time dropdb demo
|
||||
<pre><code>postgres@hqdc034:/zp/database$ time dropdb demo
|
||||
</code></pre><p>然後停止postgresql 服務</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc034:/zp/database$ pg_ctlcluster 10 main stop
|
||||
<pre><code>postgres@hqdc034:/zp/database$ pg_ctlcluster 10 main stop
|
||||
sudo systemctl stop postgresql@10-main
|
||||
</code></pre><p>接著就可以來下指令還原了</p>
|
||||
<pre tabindex="0"><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
|
||||
<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
|
||||
2019-09-05 11:15:57.947 P00 INFO: remove invalid files/paths/links from /zp/database/10/main
|
||||
@@ -473,15 +473,15 @@ user 0m6.896s
|
||||
sys 0m0.832s
|
||||
</code></pre><p>在DB目錄中,會產生一個recovery.conf,這是用來給 postgresql 看的檔案,裡面會紀錄怎麼還原、以及還原的類型、時間點,這邊指定要恢復到 <em><strong>2019-09-05 11:00:00.268248+08</strong></em>
|
||||
這個時間格式要看資料庫的設定,可以藉由以下指令得到</p>
|
||||
<pre tabindex="0"><code>postgres@hqdc034:/zp/database$ psql -Atc "select current_timestamp"
|
||||
<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>
|
||||
<pre tabindex="0"><code>postgres@hqdc034:/zp/database$ cat /zp/database/10/main/recovery.conf
|
||||
<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>
|
||||
<pre tabindex="0"><code>postgres@hqdc034:/zp/database$ pg_ctlcluster 10 main start
|
||||
<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
|
||||
postgres@hqdc034:/zp/database$ psql
|
||||
@@ -790,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=1634607506"></script>
|
||||
<script src="https://h.cowbay.org/js/production.min.js?v=1635401692"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user