x
1
(1 row)
pg2=# q
2.在线热备
使用select pg_start_backup和select pg_stop_backup()对数据库进行热备
实验过程如下:
(1)开启归档
[pg@edb1 ~]$ vi /home/pg/pgsql/data/postgresql.conf
配置以下三个参数:
wal_level = archive
archive_mode = on
archive_command = ‘cp %p /home/pg/pgsql/backup/archived_log/%f’
(2)创建归档目录
[pg@edb1 ~]$ mkdir -p /home/pg/pgsql/backup/archived_log
(3)重启数据库,使参数生效
[pg@edb1 ~]$ pg_ctl -D /home/pg/pgsql/data stop
[pg@edb1 ~]$ pg_ctl -D /home/pg/pgsql/data start
(4)创建测试库
[pg@edb1 ~]$ createdb arch
[pg@edb1 ~]$ psql arch
psql (9.3.9)
Type “help” for help.
arch=# create table btest(x int);
CREATE TABLE
arch=# insert into btest values(1);
INSERT 0 1
(5)创建备份
arch=# select pg_start_backup(‘baseline’);
pg_start_backup
0/5000028
(1 row)
arch=# q
(6)备份数据库目录
[pg@edb1 ~]$ tar -zcvf /home/pg/pg_backup.tar.gz /home/pg/pgsql/data/
…
(7)停止备份
[pg@edb1 ~]$ psql arch
psql (9.3.9)
Type “help” for help.
arch=# select pg_stop_backup();
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
pg_stop_backup
0/50000B8
(1 row)
(8)再插入一些其他数据并切换WAL日志
arch=# insert into btest values(2);
INSERT 0 1
arch=# insert into btest values(3);
INSERT 0 1
arch=# insert into btest values(4);
INSERT 0 1
arch=# select pg_switch_xlog();
pg_switch_xlog
0/6000208
(1 row)
(9)停止数据库
[pg@edb1 ~]$ pg_ctl -D /home/pg/pgsql/data stop
LOG: received smart shutdown request
LOG: autovacuum launcher shutting down
LOG: shutting down
waiting for server to shut down…LOG: database system is shut down
done
server stopped
(10)删除目录
[pg@edb1 ~]$ rm -rf /home/pg/pgsql/data/
(11)使用tar包备份恢复目录
[pg@edb1 ~]$ tar -zxvf pg_backup.tar.gz -C /
…
(12)重置pg_xlog目录
[pg@edb1 ~]$ rm -r /home/pg/pgsql/data/pg_xlog/
[pg@edb1 ~]$ mkdir /home/pg/pgsql/data/pg_xlog/
(13)创建目录存放之前的归档
[pg@edb1 ~]$ mkdir arch
[pg@edb1 ~]$ cp /home/pg/pgsql/backup/archived_log/* arch/
(14)编辑recovery.conf文件
[pg@edb1 ~]$ vi pgsql/data/recovery.conf
restore_command = ‘cp /home/pg/arch/%f “%p”’
(15)启动数据库
[pg@edb1 ~]$ pg_ctl -D /home/pg/pgsql/data/ start
server starting
[pg@edb1 ~]$ LOG: database system was interrupted; last known up at 2015-09-21 18:27:41 CST
LOG: starting archive recovery
LOG: restored log file “000000010000000000000005” from archive
LOG: redo starts at 0/5000090
LOG: consistent recovery state reached at 0/50000B8
LOG: restored log file “000000010000000000000006” from archive
cp: cannot stat `/home/pg/arch/000000010000000000000007’: No such file or directory
LOG: redo done at 0/60001E8
LOG: last completed transaction was at log time 2015-09-21 18:30:16.033281+08
LOG: restored log file “000000010000000000000006” from archive
cp: cannot stat `/home/pg/arch/00000002.history’: No such file or directory
LOG: selected new timeline ID: 2
cp: cannot stat `/home/pg/arch/00000001.history’: No such file or directory
LOG: archive recovery complete
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
可以看到数据库恢复到了最后一个归档所在的时间点
(16)验证数据
[pg@edb1 ~]$ psql arch
psql (9.3.9)
Type “help” for help.
arch=# select * from btest;
x
1
2
3
4
(4 rows)
3.文件系统冷备份
方法就是对数据库相关文件直接进行备份,由于需要停库,对业务影响较大,所以一般不使用这种方法。
实验过程如下:
创建测试库
[pg@edb1 ~]$ createdb test1
[pg@edb1 ~]$ psql test1
psql (9.3.9)
Type “help” for help.
test1=# create table test1(x int);
CREATE TABLE
test1=# insert into test1 values(1);
INSERT 0 1
test1=# q
关库
[pg@edb1 ~]$ pg_ctl -D /home/pg/pg
pg_all.dmp pg.dmp pg.log pgsql/
[pg@edb1 ~]$ pg_ctl -D /home/pg/pgsql/data/ stop
waiting for server to shut down… done
server stopped
进行文件系统打包冷备
[pg@edb1 ~]$ tar -zcvf pgdata.tar.gz /home/pg/pgsql/data
…
删除原来的文件
[pg@edb1 ~]$ rm -rf /home/pg/pgsql/data/
使用tar包中内容进行替换
[pg@edb1 ~]$ tar -zxvf pgdata.tar.gz -C /
启动数据库查看
[pg@edb1 ~]$ pg_ctl -D /home/pg/pgsql/data/ start
server starting
[pg@edb1 ~]$ LOG: database system was shut down at 2015-09-21 18:02:27 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
[pg@edb1 ~]$
[pg@edb1 ~]$ psql test1
psql (9.3.9)
Type “help” for help.
test1=# select * from test1;
x
1
(1 row)
test1=# q
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数软件测试工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上软件测试开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
4r-1713000751547)]
[外链图片转存中…(img-r8h3a5Ui-1713000751548)]
[外链图片转存中…(img-CEnxCZuG-1713000751549)]
[外链图片转存中…(img-JmBMIHZI-1713000751549)]
[外链图片转存中…(img-gmMxkAL3-1713000751550)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上软件测试开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注软件测试)
[外链图片转存中…(img-NNFj6cg9-1713000751550)]