pg_rman恢复

时间:2012-08-14 01:47:00

标签: postgresql

我正在学习postgreSQL(9.0.1),尤其是pg_rman(1.1.2)......

我所做的是.....

  1. 创建两个表t1,t2;
  2. pg_rman安装。
  3. pg_rman init -B $ RBACKUP_PATH
  4. pg_rman validate -B $ RBACKUP_PATH
  5. 删除表t1,t2;
  6. pg_ctl stop -m fast
  7. pg_rman restore -B $ RBACKUP_PATH
  8. 每一件工作都很好但是...... 当我启动postgresql服务器进程时....某些消息就像:

    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)

1 个答案:

答案 0 :(得分: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应该支持在指定时自动添加,但我不确定它是否按预期工作。