PostgreSQL使用PG_RMAN进行在线热备份和恢复操作演示
进行一次全备:
-bash-4.1$ /usr/pgsql-9.4/bin/pg_rman backup --backup-mode=full
INFO: database backup start
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
进行一次增备:
-bash-4.1$ /usr/pgsql-9.4/bin/pg_rman backup --backup-mode=incremental
INFO: database backup start
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
查看备份信息:
-bash-4.1$ /usr/pgsql-9.4/bin/pg_rman show timeline
============================================================
Start Mode Current TLI Parent TLI Status
============================================================
2015-02-27 17:46:12 INCR 1 0 DONE
2015-02-27 17:45:01 FULL 1 0 DONE
2015-02-26 00:22:13 INCR 1 0 OK
2015-02-26 00:19:10 FULL 1 0 OK
-bash-4.1$ /usr/pgsql-9.4/bin/pg_rman show
============================================================================
Start Time Total Data WAL Log Backup Status
============================================================================
2015-02-27 17:46:12 0m ---- 290kB 83MB ---- 84MB DONE
2015-02-27 17:45:01 0m 28MB ---- 50MB ---- 76MB DONE
2015-02-26 00:22:13 0m ---- 16kB 67MB 0B 67MB OK
2015-02-26 00:19:10 0m 28MB ---- 117MB 3704B 143MB OK
查看数据库内的测试数据情况:
-bash-4.1$ psql music
psql (9.4.1)
Type "help" for help.
music=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
music | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
music=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | test | table | postgres
(1 row)
删除表格:
music=# drop table test;
DROP TABLE
music=# \d
No relations found. ---测试数据已删除
music=# \q
-bash-4.1$ /usr/pgsql-9.4/bin/pg_rman validate
-bash-4.1$ /usr/pgsql-9.4/bin/pg_ctl stop -m fast
waiting for server to shut down.... done
server stopped
基于时间点恢复数据库:
-bash-4.1$ /usr/pgsql-9.4/bin/pg_rman restore -B /pgbackup --recovery-target-time 2015-02-27
INFO: validate: 2015-02-26 00:19:10 backup and archive log files by SIZE
INFO: validate: 2015-02-26 00:22:13 backup and archive log files by SIZE
INFO: validate: 2015-02-26 00:22:13 server log files by SIZE
INFO: restore complete. Recovery starts automatically when the PostgreSQL server is started.
启动数据库后查看数据是否已恢复:
-bash-4.1$ psql music
psql (9.4.1)
Type "help" for help.
music=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | test | table | postgres
(1 row)
music=# select * from test;
id
----
1
2
3
(3 rows)
OK,数据已恢复!~~~
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。