PostgreSQL11 MYSQL_postgresql11 备份
逻辑备份
postgres=# select * from t;
id | name
----+------
1 | http
2 | qdds
(2 rows)
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
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
(3 rows)
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | t | table | postgres
(1 row)
pg_dump -p 5432 --inserts --column-inserts -d postgres | gzip > /u01/pgsql/backup/dump.sql.gz
逻辑恢复
[postgres@redis01 backup]$ gzip -d /u01/pgsql/backup/dump.sql.gz
[postgres@redis01 backup]$ pg_restore -p 5432 -C -d postgres /u01/pgsql/backup/dump.sql
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
[postgres@redis01 backup]$ psql -p 5432 -d postgres -f /u01/pgsql/backup/dump.sql
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
INSERT 0 1
INSERT 0 1
ALTER TABLE
一个数据库(或者部分对象)导出为脚本文本文件,用psql恢复。
一个数据库(或者部分对象)导出为归档文件,用pg_restore恢复。
导出为其他格式的文件
pg_dump -p 5432 -Fc -d postgres > /u01/pgsql/backup/dump.dmp
[postgres@redis01 backup]$ pg_restore -p 5432 -d postgres /u01/pgsql/backup/dump.dmp
物理备份 冷备
pg_ctl stop
tar -cvjpf /u01/pgsql/colddata.tar.gz data
恢复
tar -xvf colddata.tar.gz
pg_ctl start
开启归档热备
[root@redis01 pgsql]# cat hot.sh
export POSTDATA=/u01/pgsql
export POSTBACKUPDATA=/u01/pgsql/backup
export PGPASSFILE=/u01/pgsql/.pgpass
backupname=`date +"%Y%m%d%H%M%S"`
echo "$backupname"
cd $POSTDATA
echo "$PWD"
psql -h 192.168.20.201 -d postgres -U postgres -c "select pg_start_backup('hot_backup$backupname');"
tar -cvjpf $POSTBACKUPDATA/hot$backupname.tar.gz data
psql -h 192.168.20.201 -d postgres -U postgres -c "select pg_stop_backup();select pg_switch_wal();"
备份完毕以后前面的归档日志可以删除
-rw-r----- 1 postgres postgres 16777216 Oct 12 10:14 pg_00000001000000000000000E
-rwxr-x--- 1 postgres postgres 16777216 Oct 12 10:26 pg_00000001000000000000000F
-rw-r----- 1 postgres postgres 16777216 Oct 12 11:12 pg_000000010000000000000010
-rwxr-x--- 1 postgres postgres 16777216 Oct 12 11:14 pg_000000010000000000000011
-rw-r----- 1 postgres postgres 16777216 Oct 12 11:15 pg_000000010000000000000012
-rw-r----- 1 postgres postgres 16777216 Oct 12 11:39 pg_000000010000000000000013
-rw-r----- 1 postgres postgres 16777216 Oct 12 11:39 pg_000000010000000000000014
-rw-r----- 1 postgres postgres 346 Oct 12 11:39 pg_000000010000000000000014.00000060.backup
[postgres@redis01 archive]$ cat pg_000000010000000000000014.00000060.backup
START WAL LOCATION: 0/14000060 (file 000000010000000000000014)
STOP WAL LOCATION: 0/14000130 (file 000000010000000000000014)
CHECKPOINT LOCATION: 0/14000098
BACKUP METHOD: pg_start_backup
BACKUP FROM: master
START TIME: 2019-10-12 11:39:42 CST
LABEL: hot_backup20191012113942
START TIMELINE: 1
STOP TIME: 2019-10-12 11:39:45 CST
STOP TIMELINE: 1
生成大量数据
postgres=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
0/15029668
(1 row)
postgres=# insert into t select * ,'海天' as "1" FROM generate_series(1001,10000);
INSERT 0 9000
postgres=# select pg_switch_wal();
pg_switch_wal
---------------
0/1515CCA0
(1 row)
postgres=# select count(1) from t;
count
-------
10000
(1 row)
postgres=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
0/16000140
(1 row)
查看归档日志
-rw-r----- 1 postgres postgres 346 Oct 12 11:39 pg_000000010000000000000014.00000060.backup
-rwxr-x--- 1 postgres postgres 16777216 Oct 12 14:23 pg_000000010000000000000015
drop表以后使用上次的热备+归档进行恢复
postgres=# drop table t;
DROP TABLE
pg_ctl stop
基于 Point-in-Time Recovery (PITR)恢复
tar -xf hot20191012113942.tar.gz -C ../
[postgres@redis01 pgsql]$ cd share
[postgres@redis01 share]$ ls
conversion_create.sql information_schema.sql pg_service.conf.sample postgresql.conf.sample recovery.conf.sample system_views.sql tsearch_data
errcodes.txt pg_hba.conf.sample postgres.bki postgres.shdescription snowball_create.sql timezone
extension pg_ident.conf.sample postgres.description psqlrc.sample sql_features.txt timezonesets
[postgres@redis01 share]$ cp recovery.conf.sample ../data/
mv recovery.conf.sample recovery.conf
[postgres@redis01 data]$ tail -3 recovery.conf
restore_command = 'cp /u01/pgsql/archive/pg_%f %p' #pg_wal里没有的日志从归档目录处拷贝
recovery_target_lsn = '0/16000140' #恢复到指定的lsn
recovery_target_inclusive = true #这个时间点上的commit是否要包括进去.true就是包括
另外结合如下参数进行数据库的恢复:
recovery_target_time (timestamp)
recovery_target_xid (string)
recovery_target_inclusive (boolean)
recovery_target_timeline (string)
恢复的具体日志
[postgres@redis01 log]$ cat postgresql-2019-10-12_150259.log
2019-10-12 15:02:59.624 CST [8319] LOG: database system was interrupted while in recovery at log time 2019-10-12 11:39:42 CST
2019-10-12 15:02:59.624 CST [8319] HINT: If this has occurred more than once some data might be corrupted and you might need to choose an earlier recovery target.
2019-10-12 15:02:59.865 CST [8320] FATAL: the database system is starting up
2019-10-12 15:02:59.872 CST [8321] FATAL: the database system is starting up
2019-10-12 15:02:59.906 CST [8322] FATAL: the database system is starting up
2019-10-12 15:02:59.914 CST [8323] FATAL: the database system is starting up
2019-10-12 15:02:59.947 CST [8324] FATAL: the database system is starting up
2019-10-12 15:03:00.018 CST [8325] FATAL: the database system is starting up
2019-10-12 15:03:00.028 CST [8326] FATAL: the database system is starting up
2019-10-12 15:03:00.062 CST [8327] FATAL: the database system is starting up
2019-10-12 15:03:00.070 CST [8328] FATAL: the database system is starting up
2019-10-12 15:03:00.121 CST [8329] FATAL: the database system is starting up
2019-10-12 15:03:00.128 CST [8330] FATAL: the database system is starting up
2019-10-12 15:03:00.164 CST [8331] FATAL: the database system is starting up
2019-10-12 15:03:00.169 CST [8332] FATAL: the database system is starting up
2019-10-12 15:03:00.207 CST [8333] FATAL: the database system is starting up
2019-10-12 15:03:00.214 CST [8334] FATAL: the database system is starting up
2019-10-12 15:03:00.247 CST [8335] FATAL: the database system is starting up
2019-10-12 15:03:00.283 CST [8336] FATAL: the database system is starting up
2019-10-12 15:03:00.290 CST [8337] FATAL: the database system is starting up
2019-10-12 15:03:00.325 CST [8338] FATAL: the database system is starting up
2019-10-12 15:03:00.336 CST [8339] FATAL: the database system is starting up
2019-10-12 15:03:00.358 CST [8340] FATAL: the database system is starting up
2019-10-12 15:03:00.378 CST [8341] FATAL: the database system is starting up
2019-10-12 15:03:00.397 CST [8342] FATAL: the database system is starting up
2019-10-12 15:03:00.423 CST [8343] FATAL: the database system is starting up
2019-10-12 15:03:00.433 CST [8344] FATAL: the database system is starting up
2019-10-12 15:03:00.466 CST [8345] FATAL: the database system is starting up
2019-10-12 15:03:00.473 CST [8346] FATAL: the database system is starting up
2019-10-12 15:03:00.507 CST [8347] FATAL: the database system is starting up
2019-10-12 15:03:00.523 CST [8348] FATAL: the database system is starting up
2019-10-12 15:03:00.545 CST [8349] FATAL: the database system is starting up
2019-10-12 15:03:00.564 CST [8350] FATAL: the database system is starting up
2019-10-12 15:03:00.592 CST [8351] FATAL: the database system is starting up
2019-10-12 15:03:00.622 CST [8352] FATAL: the database system is starting up
2019-10-12 15:03:00.633 CST [8353] FATAL: the database system is starting up
2019-10-12 15:03:00.657 CST [8354] FATAL: the database system is starting up
2019-10-12 15:03:00.674 CST [8355] FATAL: the database system is starting up
2019-10-12 15:03:00.699 CST [8356] FATAL: the database system is starting up
2019-10-12 15:03:00.718 CST [8357] FATAL: the database system is starting up
2019-10-12 15:03:00.735 CST [8358] FATAL: the database system is starting up
2019-10-12 15:03:00.766 CST [8359] FATAL: the database system is starting up
2019-10-12 15:03:00.778 CST [8360] FATAL: the database system is starting up
2019-10-12 15:03:00.814 CST [8361] FATAL: the database system is starting up
2019-10-12 15:03:00.821 CST [8362] FATAL: the database system is starting up
2019-10-12 15:03:00.860 CST [8363] FATAL: the database system is starting up
2019-10-12 15:03:00.866 CST [8364] FATAL: the database system is starting up
2019-10-12 15:03:00.908 CST [8365] FATAL: the database system is starting up
2019-10-12 15:03:00.914 CST [8366] FATAL: the database system is starting up
2019-10-12 15:03:00.962 CST [8367] FATAL: the database system is starting up
2019-10-12 15:03:00.968 CST [8368] FATAL: the database system is starting up
2019-10-12 15:03:01.008 CST [8369] FATAL: the database system is starting up
2019-10-12 15:03:01.014 CST [8370] FATAL: the database system is starting up
2019-10-12 15:03:01.042 CST [8319] LOG: starting point-in-time recovery to WAL location (LSN) "0/16000140"
2019-10-12 15:03:01.051 CST [8372] FATAL: the database system is starting up
2019-10-12 15:03:01.057 CST [8373] FATAL: the database system is starting up
2019-10-12 15:03:01.058 CST [8319] LOG: restored log file "000000010000000000000014" from archive
2019-10-12 15:03:01.107 CST [8374] FATAL: the database system is starting up
2019-10-12 15:03:01.112 CST [8375] FATAL: the database system is starting up
2019-10-12 15:03:01.145 CST [8376] FATAL: the database system is starting up
2019-10-12 15:03:01.152 CST [8377] FATAL: the database system is starting up
2019-10-12 15:03:01.182 CST [8378] FATAL: the database system is starting up
2019-10-12 15:03:01.188 CST [8379] FATAL: the database system is starting up
2019-10-12 15:03:01.221 CST [8380] FATAL: the database system is starting up
2019-10-12 15:03:01.226 CST [8381] FATAL: the database system is starting up
2019-10-12 15:03:01.267 CST [8382] FATAL: the database system is starting up
2019-10-12 15:03:01.273 CST [8383] FATAL: the database system is starting up
2019-10-12 15:03:01.300 CST [8319] LOG: redo starts at 0/14000060
2019-10-12 15:03:01.311 CST [8386] FATAL: the database system is starting up
2019-10-12 15:03:01.317 CST [8387] FATAL: the database system is starting up
2019-10-12 15:03:01.351 CST [8388] FATAL: the database system is starting up
2019-10-12 15:03:01.357 CST [8389] FATAL: the database system is starting up
2019-10-12 15:03:01.359 CST [8319] LOG: consistent recovery state reached at 0/14000130
2019-10-12 15:03:01.359 CST [8317] LOG: database system is ready to accept read only connections
2019-10-12 15:03:01.377 CST [8319] LOG: restored log file "000000010000000000000015" from archive
2019-10-12 15:03:01.642 CST [8319] LOG: restored log file "000000010000000000000016" from archive
2019-10-12 15:03:01.775 CST [8319] LOG: recovery stopping after WAL location (LSN) "0/16000140"
2019-10-12 15:03:01.775 CST [8319] LOG: recovery has paused
2019-10-12 15:03:01.775 CST [8319] HINT: Execute pg_wal_replay_resume() to continue.
PostgreSQL11 MYSQL_postgresql11 备份相关推荐
- 内存:VSS/RSS/PSS/USS区别和监控
软件开发的最后阶段就是测试,了解软件整体的cpu和mem使用情况,之前一直用ps来确定cpu使用率和rss内存,最近监控python多进程软件时,累积rss竟然超过了节点物理内存126G,原因在此处梳 ...
- postgresql学习配置主从同步和自动备份
最近刚接手一个维护项目,一个生产环境出了故障,所有数据都损毁了.数据第一啊,原先在做方案的时候厂家已经建议客户做冗余什么的,但是始终因为资金的原因没有落实,但也得想办法提高数据安全性开拔,优先保存数据 ...
- docker镜像的备份和恢复
在使用docker的时候总会出现这种情况:下载东西很慢很慢,下载完配置完以后,突然,一个地方配置出现了问题,无法恢复,需要重新装载,那么,之前的所有配置.安装.下载都没了,又是一个大活~ 该怎么办呢? ...
- mysql备份psb文件怎么打开_Navicat for MySQL 数据备份教程
原标题:Navicat for MySQL 数据备份教程 一个安全和可靠的服务器与定期运行备份有密切的关系,因为错误有可能随时发生,由攻击.硬件故障.人为错误.电力中断等都会照成数据丢失.备份功能为防 ...
- Docker 入门系列(4)- Docker 数据管理(挂载目录、挂载文件、数据卷挂载、数据卷共享、数据卷删除、数据卷容器备份和恢复)
基于底层存储实现,Docker 提供了三种适用于不同场景的文件系统挂载方式:Bind Mount.Volume 和 Tmpfs Mount. Bind Mount 能够直接将宿主操作系统中的目录和文件 ...
- oracle自动备份
oracle自动备份,支持BLOB,BINARY_DOUBLE字段 #!/bin/sh #请设置以下参数 db_array=(csop) db_user=csop db_pwd=csop #默认备份目 ...
- 客快物流大数据项目(十二):Docker的迁移与备份
目录 Docker的迁移与备份 一.容器保存为镜像 二. 镜像备份 三.镜像恢复与迁移 Docker的迁移与备份
- mongodb之备份
前言 数据库的备份非常重要 备份方式 使用Mongodb自带的运维管理工具(Ops Manager) 需要单独部署,比较麻烦和复杂 通过文件系统快照 Linux需要LVM支持 需要开启journal日 ...
- oracle数据库 export,转:Oracle数据库的备份方法——使用export作为备份
5.使用export作为备份策略 5.1 export的命令选项说明 Oracle数据库的exp工具提供tables.users.full database.tablespace四种级别的导出方式,把 ...
最新文章
- 【BZOJ-1367】sequence 可并堆+中位数
- (1110, “Column ‘arriveTime‘ specified twice“)
- linux cp源码_为Linux的cp和mv命令添加进度条
- 求解10的75次方问题
- react(89)--设置只能正整数
- Ajax基石脚本异步并发调用参数传递
- 一个内部转岗的机会,要不要尝试?
- Dart 7-Day
- 高性能的“流水线技术”网页
- android获取用户点击的坐标
- 面向对象的超级面试题,涉及封装多态继承等多方面考核,异常烧脑,90%的面试官必问题目,不会这个的,只是会搬砖的码农
- ajax实现文件表单上传,ajax文件异步实现表单上传
- java ssm网上超市购物管理系统
- 步进电机原理及参数详解
- JAVA实现微信授权登录(详解)
- 倍福--实现和西门子的profinet
- 云计算的发展趋势(一)云计算相关领域介绍
- 超级账本执行董事:区块链将削弱谷歌、亚马逊和Facebook的市场力量
- 摩羯座|摩羯座性格分析
- 微计算机应用是核心吗,北大核心哪个杂志好投
热门文章
- yolo学习之各版本网络结构
- 进程(上篇):进程与操作系统
- Environment variable ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to da tabase unique name.
- 微星小飞机没有osd显示怎么办?
- BlackBerry 9850 应用:大众点评,美食家必备哦
- linux查看系统日志命令
- 提醒事项 android,每日提醒 Pro-提醒事项、时间管理待办清单
- 谜题51:那个点是什么?
- python练习题(难度高)
- 5 大最常用 C++ 经典算法