2012-08-14 98 views
1

我學習PostgreSQL的(9.0.1),特別是pg_rman(1.1.2)這些天...pg_rman恢復

我所做的是.....

  1. 創建兩個表t1,t2;
  2. pg_rman安裝。
  3. pg_rman初始化-B $ RBACKUP_PATH
  4. pg_rman驗證-B $ RBACKUP_PATH
  5. 降表T1,T2;
  6. pg_ctl停止-m快速
  7. pg_rman恢復-B $ RBACKUP_PATH

everyting工作正常,但... 當我啓動PostgreSQL服務器進程....某種FO消息是有這樣的:

cp: cannot stat `/postDATA/ARCHIVE_LOG/00000007000000000000000E': No such file or directory 

無論如何,如果一切運作良好,我在充分備份必須是有之前創建的T1,T2表,對嗎?如果是這樣,我的腳本是波紋管...

localhost.localdomain:[/postDATA/RBACKUP]psql -d user1db -U user1 
psql (9.0.1) 
Type "help" for help. 

user1db=> create table t1(col1 char(1)); 
CREATE TABLE 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 
user1db=> insert into t1 values('1'); 
INSERT 0 1 

user1db=> create table t2(col1 char(1)); 
CREATE TABLE 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> insert into t2 values('1'); 
INSERT 0 1 
user1db=> \q 

localhost.localdomain:[/home/postgres]ll 
total 17592 
-rwxrwxr-x 1 postgres postgres 67103 Aug 10 16:24 pg_rman-1.1.2.tar.gz 
drwxrwxr-x 6 postgres postgres  4096 Aug 13 17:04 postgresql-9.0.1 
-rwxrwxrwx 1 postgres postgres 17898437 Aug 6 10:10 postgresql-9.0.1.tar.gz 

localhost.localdomain:[/home/postgres]tar -xvzf pg_rman-1.1.2.tar.gz 
pg_rman/ 
pg_rman/delete.c 
pg_rman/pg_rman.c 
pg_rman/pgut/ 
pg_rman/pgut/pgut.h 
pg_rman/pgut/pgut-port.h 
pg_rman/pgut/pgut-port.c 
pg_rman/pgut/pgut.c 
pg_rman/pgsql_src/ 
pg_rman/pgsql_src/COPYRIGHT.pgsql_src 
pg_rman/pgsql_src/pg_crc.c 
pg_rman/pgsql_src/pg_ctl.c 
pg_rman/data/ 
pg_rman/data/sample_backup/ 
pg_rman/data/sample_backup/20090601/ 
pg_rman/data/sample_backup/20090601/170553/ 
pg_rman/data/sample_backup/20090601/170553/file_arclog.txt 
pg_rman/data/sample_backup/20090601/170553/backup.ini 
pg_rman/data/sample_backup/20090601/170553/srvlog/ 
pg_rman/data/sample_backup/20090601/170553/arclog/ 
pg_rman/data/sample_backup/20090601/170553/database/ 
pg_rman/data/sample_backup/20090601/170553/database/PG_VERSION 
pg_rman/data/sample_backup/20090601/170553/file_database.txt 
pg_rman/data/sample_backup/backup/ 
pg_rman/data/sample_backup/pg_rman.ini 
pg_rman/data/sample_backup/20090531/ 
pg_rman/data/sample_backup/20090531/170553/ 
pg_rman/data/sample_backup/20090531/170553/file_arclog.txt 
pg_rman/data/sample_backup/20090531/170553/backup.ini 
pg_rman/data/sample_backup/20090531/170553/srvlog/ 
pg_rman/data/sample_backup/20090531/170553/arclog/ 
pg_rman/data/sample_backup/20090531/170553/database/ 
pg_rman/data/sample_backup/20090531/170553/database/PG_VERSION 
pg_rman/data/sample_backup/20090531/170553/file_database.txt 
pg_rman/data/sample_backup/timeline_history/ 
pg_rman/data/sample_backup/20090602/ 
pg_rman/data/sample_backup/20090602/170553/ 
pg_rman/data/sample_backup/20090602/170553/backup.ini 
pg_rman/data/sample_backup/20090602/170553/srvlog/ 
pg_rman/data/sample_backup/20090602/170553/arclog/ 
pg_rman/data/sample_backup/20090602/170553/database/ 
pg_rman/data/sample_backup/20090603/ 
pg_rman/data/sample_backup/20090603/170553/ 
pg_rman/data/sample_backup/20090603/170553/file_arclog.txt 
pg_rman/data/sample_backup/20090603/170553/backup.ini 
pg_rman/data/sample_backup/20090603/170553/srvlog/ 
pg_rman/data/sample_backup/20090603/170553/arclog/ 
pg_rman/data/sample_backup/20090603/170553/database/ 
pg_rman/data/sample_backup/20090603/170553/file_srvlog.txt 
pg_rman/data/sample_backup/20090603/170553/file_database.txt 
pg_rman/show.c 
pg_rman/data.c 
pg_rman/init.c 
pg_rman/backup.c 
pg_rman/dir.c 
pg_rman/xlog.c 
pg_rman/parray.h 
pg_rman/COPYRIGHT 
pg_rman/pg_rman.h 
pg_rman/sql/ 
pg_rman/sql/option.sql 
pg_rman/sql/option.sh 
pg_rman/sql/backup.sql 
pg_rman/sql/init.sql 
pg_rman/sql/backup_restore.sh 
pg_rman/sql/show_validate.sql 
pg_rman/sql/backup_restore.sql 
pg_rman/Makefile 
pg_rman/parray.c 
pg_rman/restore.c 
pg_rman/catalog.c 
pg_rman/util.c 
pg_rman/validate.c 
pg_rman/expected/ 
pg_rman/expected/option.out 
pg_rman/expected/backup_restore.out 
pg_rman/expected/show_validate.out 
pg_rman/expected/init.out 

localhost.localdomain:[/home/postgres]cd pg_rman 

localhost.localdomain:[/home/postgres/pg_rman]make USE_PGXS=1 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o backup.o backup.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o catalog.o catalog.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o data.o data.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o delete.o delete.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o dir.o dir.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o init.o init.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o parray.o parray.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pg_rman.o pg_rman.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o restore.o restore.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o show.o show.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o util.o util.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o validate.o validate.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o xlog.o xlog.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pgsql_src/pg_ctl.o pgsql_src/pg_ctl.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pgsql_src/pg_crc.o pgsql_src/pg_crc.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pgut/pgut.o pgut/pgut.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pgut/pgut-port.o pgut/pgut-port.c 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv backup.o catalog.o data.o delete.o dir.o init.o parray.o pg_rman.o restore.o show.o util.o validate.o xlog.o pgsql_src/pg_ctl.o pgsql_src/pg_crc.o pgut/pgut.o pgut/pgut-port.o -L/usr/local/pgsql/lib -lpgport -L/usr/local/pgsql/lib -lpq -L/usr/local/pgsql/lib -L/usr/lib -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags -lpgport -lxml2 -lpam -lz -lreadline -ltermcap -lcrypt -ldl -lm -o pg_rman 

localhost.localdomain:[/home/postgres/pg_rman]make USE_PGXS=1 install 
/bin/mkdir -p '/usr/local/pgsql/bin' 
/bin/sh /usr/local/pgsql/lib/pgxs/src/makefiles/../../config/install-sh -c pg_rman '/usr/local/pgsql/bin 

localhost.localdomain:[/home/postgres/pg_rman]egrep -i "wal_level|archive_mode|archive_command" $PGDATA/postgresql.conf 
wal_level = archive   # minimal, archive, or hot_standby 
archive_mode = on  # allows archiving to be done 
archive_command = 'cp -i %p /postDATA/ARCHIVE_LOG/%f'  # command to use to archive a logfile segment 

localhost.localdomain:[/home/postgres/pg_rman]pg_rman init -B /postDATA/RBACKUP 
INFO: ARCLOG_PATH is set to '/postDATA/ARCHIVE_LOG' 
INFO: SRVLOG_PATH is set to '/postDATA/DATA/pg_log' 

localhost.localdomain:[/home/postgres/pg_rman]cd /postDATA/RBACKUP 

localhost.localdomain:[/postDATA/RBACKUP]ll 
total 24 
drwx------ 4 postgres postgres 4096 Aug 14 09:43 backup 
-rw-rw-r-- 1 postgres postgres 73 Aug 14 09:43 pg_rman.ini 
drwx------ 2 postgres postgres 4096 Aug 14 09:43 timeline_history 
localhost.localdomain:[/postDATA/RBACKUP]vi pg_rman.ini 
ARCLOG_PATH='/postDATA/ARCHIVE_LOG' 
SRVLOG_PATH='/postDATA/DATA/pg_log' 
~                                                         
~                                                         
~                                                         
~   
"pg_rman.ini" 3L, 73C 
localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP show 
============================================================================ 
Start    Time Total Data  WAL  Log Backup Status 
============================================================================ 

localhost.localdomain:[/postDATA/RBACKUP]pg_rman backup -B /postDATA/RBACKUP -b f 
INFO: database backup start 
NOTICE: pg_stop_backup complete, all required WAL segments have been archived 

localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP show 
============================================================================ 
Start    Time Total Data  WAL  Log Backup Status 
============================================================================ 
2012-08-14 09:46:37 4m 26MB ---- 318MB ---- 344MB DONE 

localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP validate 
INFO: validate: 2012-08-14 09:46:37 

localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP show 
============================================================================ 
Start    Time Total Data  WAL  Log Backup Status 
============================================================================ 
2012-08-14 09:46:37 4m 26MB ---- 318MB ---- 344MB OK 

localhost.localdomain:[/postDATA/RBACKUP]psql -d user1db -U user1 
psql (9.0.1) 
Type "help" for help. 

user1db=> \d 
     List of relations 
Schema | Name | Type | Owner 
--------+------+-------+------- 
public | t1 | table | user1 
public | t2 | table | user1 
user1db=> drop table t1; 
DROP TABLE 
user1db=> drop table t2; 
DROP TABLE 
user1db=> \d 
No relations found. 
user1db=> \q 

localhost.localdomain:[/postDATA/RBACKUP]pg_ctl stop -m fast 
LOG: received fast shutdown request 
LOG: aborting any active transactions 
waiting for server to shut down....LOG: autovacuum launcher shutting down 
LOG: shutting down 
LOG: database system is shut down 
done 
server stopped 

localhost.localdomain:[/postDATA/RBACKUP]pg_rman restore -B /postDATA/RBACKUP 
INFO: validate: 2012-08-14 09:46:37 
INFO: restore complete. Recovery starts automatically when the PostgreSQL server is started. 

localhost.localdomain:[/postDATA/RBACKUP]pg_ctl start 
server starting 
localhost.localdomain:[/postDATA/RBACKUP]LOG: database system was interrupted; last known up at 2012-08-14 09:46:57 KST 
LOG: restored log file "00000007.history" from archive 
LOG: restored log file "00000007.history" from archive 
LOG: starting archive recovery 
LOG: restored log file "00000007000000000000000C" from archive 
LOG: redo starts at 0/C000070 
LOG: consistent recovery state reached at 0/D000000 
LOG: restored log file "00000007000000000000000D" from archive 
cp: cannot stat `/postDATA/ARCHIVE_LOG/00000007000000000000000E': No such file or directory 
LOG: record with zero length at 0/E000070 
LOG: redo done at 0/E000020 
LOG: last completed transaction was at log time 2012-08-14 09:59:05.321848+09 
cp: cannot stat `/postDATA/ARCHIVE_LOG/00000008.history': No such file or directory 
LOG: selected new timeline ID: 8 
LOG: restored log file "00000007.history" from archive 
LOG: archive recovery complete 
LOG: autovacuum launcher started 
LOG: database system is ready to accept connections 

localhost.localdomain:[/postDATA/RBACKUP]psql -d user1db -U user1 
psql (9.0.1) 
Type "help" for help. 

user1db=> \d 
No relations found. 

我怎樣才能通過備份得到我的表(t1,t2)?

+0

我遇到了完全相同的問題。你能指導我如何解決這個問題嗎? – Suniel 2016-11-14 11:29:57

回答

1

這裏的問題是您完全恢復備份。這意味着你實際上在表被刪除之後恢復到了這個點。

你可以看到,從線:

INFO: validate: 2012-08-14 09:46:37 

LOG: last completed transaction was at log time 2012-08-14 09:59:05.321848+09 

這可能是由於這樣的事實,你還是留在目錄中的歸檔日誌。 您需要做的是在執行數據庫恢復/啓動之前刪除/postDATA/ARCHIVE_LOG/中的所有內容(這裏我假設pg_rman將還原所需的所有歸檔日誌歸檔到備份目錄中),或者您需要修改recovery.conf文件並添加一個時間戳,直到您想要恢復的時間點(應該是放置之前的時間),然後添加參數recovery_target_time

pg_rman應該支持自動添加,如果指定,但我不確定如果按預期工作。