postgresql同样支持在线备份,该备份方式与oracle中用户热备的方式相同,手动拷贝数据文库文件与归档日志。可以根据测试过程将备份直接写成script,通过定制,完成数据库的自动备份。
postgresql的恢复支持基于时间戳与事务ID,可以通过时间戳或事务ID的方式,完成数据库的不完全恢复或者因错误操作的故障恢复。
该测试目的:postgresql的在线备份;通过在线备份完成恢复。
1,开启归档
[postgre@daduxiong~]$more/usr/local/pgsql/data/postgresql.conf|greparchive_ archive_mode=on#allowsarchivingtobedone archive_command='cp-i%p/archive/%f>/dev/null' |
[root@daduxiong~]#servicepostgresqlstop StoppingPostgresql:serverstopped ok [root@daduxiong~]#servicepostgresqlstart StartingPostgresql:ok |
[postgre@daduxiongarchive]$psqlpostgres-c"selectpg_start_backup('hot_backup');" pg_start_backup ----------------- 0/7000020 (1row) |
[postgre@daduxiongarchive]$tar--exclude$PGDATA/pg_xlog-cvjpf/archive/pgbackup.tar.bz2$PGDATA |
[postgre@daduxiongarchive]$psqlpostgres-c"selectpg_stop_backup();"pg_stop_backup----------------0/70133A0(1row) |
[postgre@daduxiongarchive]$psqlpostgres Welcometopsql8.3.10,thePostgresqlinteractiveterminal. Type:\copyrightfordistributionterms \hforhelpwithsqlcommands \?forhelpwithpsqlcommands \gorterminatewithsemicolontoexecutequery \qtoquit postgres=#createtableabc(idinteger); CREATETABLE postgres=#insertintoabcvalues(1); INSERT01 postgres=#\q |
[root@daduxiongpgsql]#servicepostgresqlstop StoppingPostgresql:serverstopped ok [postgre@daduxiongarchive]$cp$PGDATA/pg_xlog/*00*/archive/ |
[root@daduxiongpgsql]#rm-rfdata |
[postgre@daduxiongpgsql]$tar-xvf/archive/pgbackup.tar.bz2 ....省略 /usr/local/pgsql/data/global/2843 /usr/local/pgsql/data/postmaster.opts /usr/local/pgsql/data/pg_twophase/ /usr/local/pgsql/data/postmaster.pid /usr/local/pgsql/data/backup_label /usr/local/pgsql/data/PG_VERSION |
[root@daduxiongpgsql]#mv/archive/usr/local/pgsql/data/usr/local/pgsql [root@daduxiongdata]#mkdirpg_xlog [root@daduxiongdata]#chmod0700pg_xlog/ [root@daduxiongdata]#chownpostgre:postgrepg_xlog/ [root@daduxiongdata]#cdpg_xlog/ [root@daduxiongpg_xlog]#mkdirarchive_status [root@daduxiongpg_xlog]#chmod0700archive_status/ [root@daduxiongpg_xlog]#chownpostgre:postgrearchive_status/ [root@daduxiongpg_xlog]#mv/archive/*00*/usr/local/pgsql/data/pg_xlog [root@daduxiongpg_xlog]#cd.. [root@daduxiongdata]#ls backup_labelpg_clogpg_multixactpg_twophasepostgresql.conf basepg_hba.confpg_subtransPG_VERSIONpostmaster.opts globalpg_ident.confpg_tblspcpg_xlogpostmaster.pid |
[root@daduxiongdata]#touchrecovery.conf [root@daduxiongdata]#echo"restore_command='cp-i/archive/%f%p'">>recovery.conf [root@daduxiongdata]#chownpostgre:postgrerecovery.conf [root@daduxiongdata]#chmod0750recovery.conf |
[root@daduxiongdata]#servicepostgresqlstart StartingPostgresql:ok ---省略日志部分内容 LOG:selectednewtimelineID:3 LOG:restoredlogfile"00000002.history"fromarchive LOG:archiverecoverycomplete LOG:autovacuumlauncherstarted LOG:databasesystemisreadytoacceptconnections |