1. 程式人生 > >pg_rman 實現對postgresql資料庫的備份,恢復與管理

pg_rman 實現對postgresql資料庫的備份,恢復與管理

--下載軟體
https://github.com/ossc-db/pg_rman

--安裝
 unzip pg_rman-master.zip 
 
--下載安裝postgresql93-libs
http://yum.postgresql.org/9.3/redhat/rhel-6.4-x86_64/ 

[[email protected] tools]# rpm -ivh postgresql93-libs-9.3.10-1PGDG.rhel6.x86_64.rpm 
warning: postgresql93-libs-9.3.10-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                ########################################### [100%]
   1:postgresql93-libs      ########################################### [100%]

--下載pg_rman,注意與其對應的資料庫版本   
 https://github.com/ossc-db/pg_rman/releases  
[
[email protected]
tools]# rpm -ivh pg_rman-1.3.1-1.pg93.rhel6.x86_64.rpm Preparing... ########################################### [100%] 1:pg_rman ########################################### [100%] --注意預設pg_rman安裝在 /usr/pgsql-9.3 目錄下 --注意pg_rman需要一個備份目錄 export BACKUP_PATH=/tmp/pg_rman --初始化備份目錄 mkdir pg_rman pg_rman init -B /tmp/pg_rman --檢視備份集 pg_rman show --刪除備份 pg_rman delete 2015-11-19 15:10:34 --pg_rman 支援增量備份和壓縮備份 --pg_rman必須要有一個全量的備份做增量 pg_rman backup --backup-mode=full --progress --基於全庫備份的增量備份 pg_rman backup -b incremental -P -Z --pg_rman 的備份必須都是經過驗證過的,否則不能進行恢復和增量備份 Backups without validation cannot be used for restore and incremental backup --執行完備份要執行一次validate,因為備份後的狀態是done,還不能進行恢復 pg_rman validate $ pg_rman show detail ========================================================== StartTime Mode Duration Size TLI Status ========================================================== 2015-07-30 13:36:38 FULL 0m 15MB 15 DONE The status of the backup we have just taken is DONE. This is because we does not do validate yet. So, do validate command next. $ pg_rman validate INFO: validate: "2015-07-30 13:36:38" backup, archive log files and server log files by CRC INFO: backup "2015-07-30 13:36:38" is valid $ pg_rman show ========================================================== StartTime Mode Duration Size TLI Status ========================================================== 2015-07-30 13:36:38 FULL 0m 15MB 15 OK --hard-copy,注意這個引數,其預設對歸檔檔案建立的是軟連線 The archive WAL are copied to archive WAL storage area. If not specified, pg_rman makes symbolic link to archive WAL where are in the backup catalog directory. --刪除指定時間點之前的資料 pg_rman delete '2015-12-28 14:40:00' --注意pg_rman至少要儲存一個完整的備份及其增量 WARNING: cannot delete backup with start time "2015-12-28 14:29:22" DETAIL: This is the incremental backup necessary for successful recovery. WARNING: cannot delete backup with start time "2015-12-28 14:26:42" DETAIL: This is the latest full backup necessary for successful recovery. --如果實在想刪除可以指定 -f 引數 pg_rman delete -f '2015-12-28 14:39:51' -- pg_rman 的delete只是刪除其檔案,但對於purge操作是刪除備份目錄中的備份資訊 Though delete command removes actual data from file system, there remains some catalog information of deleted backups. In order to remove this, execute purge command -- pg_rman 可用於初始化一個standby 資料庫 pg_rman backup --pgdata=/home/postgres/pgdata_sby --backup-mode=full --host=master --standby-host=localhost --standby-port=5432 --pg_rman 的增量備份是基於檔案系統的update time時間線 When taking an incremental backup, pg_rman check the timeline ID of the target database whether it is the same with the one of the full backup in backup list. But, pg_rman does not check whether the data itself is same with the full backup in backup list. So, you can take an incremental backup over the full backup against the database which has the same timeline ID but has different data --對於pg_rman,如果備份的資料庫全部丟失,包括 pg_xlog目錄內的檔案,其只能恢復到備份時的時間點 --模擬資料丟失 mv data data_bak --使用pg_rman進行恢復,注意如果歸檔目錄不存在,則需要手動建立一個歸檔目錄 pg_rman restore --恢復完成之後,由於xlog丟失,啟動資料庫失敗,錯誤如下 2015-12-27 19:08:35.848 PST,,,6422,,5680a7b3.1916,2,,2015-12-27 19:08:35 PST,,0,LOG,00000,"invalid primary checkpoint record",,,,,,,,"ReadCheckpointRecord, xlog.c:6411","" 2015-12-27 19:08:35.848 PST,,,6422,,5680a7b3.1916,3,,2015-12-27 19:08:35 PST,,0,LOG,00000,"invalid secondary checkpoint record",,,,,,,,"ReadCheckpointRecord, xlog.c:6415","" 2015-12-27 19:08:35.848 PST,,,6422,,5680a7b3.1916,4,,2015-12-27 19:08:35 PST,,0,PANIC,XX000,"could not locate a valid checkpoint record",,,,,,,,"StartupXLOG, xlog.c:5121","" --此時只能重置xlog,並取消恢復模式 pg_resetxlog -f /usr/local/postgresql/9.3.4/data mv recovery.conf recovery.done --對於pg_rman,如果備份的資料庫全部丟失,但xlog日誌存在,此時可以恢復到資料庫崩潰的時間點 rm -rf data/pg_xlog/ --拷貝原有的xlog到恢復的資料庫目錄中 cp -r data_bak/pg_xlog/ data --刪除archive_status檔案目錄的檔案 rm -rf data/pg_xlog/archive_status/* --註釋掉recovery.conf的恢復點 #recovery_target_timeline = '2' --啟動資料庫 pg_ctl start

相關推薦

pg_rman 實現postgresql資料庫備份恢復管理

--下載軟體 https://github.com/ossc-db/pg_rman --安裝 unzip pg_rman-master.zip --下載安裝postgresql93-libs http://yum.postgresql.org/9.3/redhat

Python3.6中安裝psycopg2實現PostgreSQL資料庫的操作

        事先在網上搜索了一大圈,頭都大了,看到那麼多文章寫道在python裡安裝psycopg2的各種坑和各種麻煩,各種不成功。搜尋了一下午,索性外出放鬆。晚飯後,又繼續上psycopg2官網(http://initd.org/psycopg/docs/instal

Java 下實現mysql資料庫備份恢復

在java裡面使用 Java.lang.Runtime 執行系統系統執行環境裡面的命令,從而使用mysql自帶的備份及恢復工具達到對資料庫的備份和恢復package org.hinsteny.util; import java.io.File; import java.i

Linux下MySql資料庫備份恢復

MySQL命令列匯入資料庫: 1,將要匯入的.sql檔案移至bin檔案下,這樣的路徑比較方便 2,同上面匯出的第1步 3,進入MySQL:mysql -u 使用者名稱 -p 如我輸入的命令列:mysql -u root -p   (輸入同樣後會讓你輸入MySQL的密碼) 4

技術實現(2)之資料庫備份恢復的設計實現

APDPlat提供了web介面的資料庫備份與恢復,支援手工操作和定時排程,可下載備份檔案到本地,也可把備份檔案傳送到異地容錯,極大地簡化了資料庫的維護工作。 設計目標: 1、多資料庫支援 2、橫切關注點隔離 3、異地容錯 下面闡述具體的設計及實現: 1、為了支援多資料

oracle資料庫備份刪除恢復

1、首先備份test使用者的所有表和檢視等 exp test/[email protected]/orcl file=etms20170818_70.dmp log=0818_70.log 2、刪除test使用者的所有表和檢視等 SQL>dro

thinkphp實現MySQL資料庫實現備份功能

public function exportDatabase(){ header("Content-type:text/html;charset=utf-8"); $path = C('ROOT_MYSQL_PATH'); $model = M(); //查詢所有表 $sq

Oracle冷備份恢復時報錯解決

chang tab sha 卸載 database not sqlplus members acl ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist 進程 ID: 0

MySQL備份恢復方案mysqlbinlogmysqldump主從主主復制

庫存 讀寫 sel erro l數據庫 reat 當前 password ima DBMS數據庫管理系統的三層模型:物理層,邏輯層以及視圖層。 物理層:決定數據的存儲形式。 邏輯層:是一張有一張的表,一行行的數據記錄。 視圖層:讓用戶看起來更方便,可有可無。 存

Xtrabackup工具完成完全備份恢復

Xtrabackup工具完全備份恢復準備兩臺mariadb數據庫主機 一臺做備份,在另一臺恢復數據 一,在源主機上執行全備份 # 完全備份 innobackupex --user=root /backup/data/ # 將備份的文件拷貝到另一臺主機上 scp -r /backup/data

gitlab安裝使用備份恢復

git gitlab gitlab安裝,使用,備份,恢復 git是一個版本控制器在分布式版本控制系統裏,客戶端並不只提取最新版本的文件快照,而是把代碼倉庫完整地鏡像下來。 這麽一來,任何一處協同工作用的服務器發生故障,事後都可以用任何一個鏡像出來的本地倉庫恢復。因為每一次的提取操作,實際上都是一次對代

索引視圖導入導出備份恢復

insert 重新登錄 ctrl 註意 備份文件 數據保存 視圖 mysq 學習 一、實驗介紹 1.1 實驗內容 本節實驗中我們將學習並實踐數據庫的其他基本操作:索引、視圖,導入和導出,備份和恢復等。 這些概念對於數據庫管理員而言都非常重要,請仔細理解並完成所有實驗操作。

完整備份數據庫+差異備份恢復到另外一臺服務器

數據庫文件 完整 刷新 需要 點擊 一個 服務 選中 第一個 材料:完整備份數據庫一份、最近備份的差異備份一份 現在需要將它完整的恢復到另外一臺數據庫服務器上。 首先 左側數據庫-右鍵-還原數據庫 然後目標數據庫手動輸入一個名字。 下面源設備選擇完整數據庫文件,然後確定後會

Oracle運維基本操作倒庫、備份恢復優化。

Oracle Linux Centos 系統 運維 Oracle基本操作創建表空間CREATE TABLESPACE test //這裏我們創建的表空間名稱叫做test,名字可以自定義 LOGGING DATAFILE ‘/data/ora01/app/oracle/oradat

如何實現函式的隱藏看完就會

      當你寫了一個函式可以實現某些功能時,你要給其他人使用,卻不想讓別人看到你寫的函式的內容,這時你就可以通過對函式內容進行隱藏來達到目的,函式提供了對過程的封裝和細節的隱藏,那麼今天我們就來看看如何對函式進行隱藏:   這裡以上篇部落格寫的Sw

Oracle資料庫備份exp和expdp的區別imp和impdp的區別

oracle資料庫備份 1: 建立dmp匯出目錄  create directory 目錄名 as '目錄路徑' 2: 檢視當前建立的所有dmp匯出目錄 select * from dba_directories 3: 備份 expdp 使用者名

PostgreSQL資料庫備份還原指令碼

本文對資料庫進行的操作主要用到的是PG自帶的pg_dumpall、pg_dump、psql這幾個命令 備份還原過程: 1:備份全域性物件 2: 備份某一個數據庫 3:還原全域性物件 4:還原備份的資料庫 備份詳細過程:    

jfinal+hbase+eclipse開發web專案詳細步驟04---在web頁面實現hbase資料庫資料的增刪查改功能

首先提醒大家,本節是在步驟01、步驟02、步驟03都成功的基礎上做進一步開發。如果在之前的任何一個步驟出現問題,那麼希望你先解決好問題之後,再做本次的開發。 步驟1:建表。 1、開啟我們虛擬機器,並且啟動hadoop、hbase start-all.sh start

sql server 操作 約束和備份恢復

--約束,確保資料滿足一定規則 --not null select * from emp select * from dept --unique 唯一性, --primary key 表中只有一個主鍵,但是可以將多個列定義為一個主鍵 cr

Spring+Maven+JdbcTemplate實現mysql資料庫操作

第一步匯入需要的maven: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-conte