阿里云rds数据库恢复(阿里云rds备份恢复)

admin 114 2023-03-16

阿里云服务器优惠多,折扣错,惊喜多,请咨询:www.wqiis.com

本文目录一览:

如何使用脚本自动备份阿里云rds数据库

1、在ECS上使用mysqldump进行逻辑备份,再中转到本地服务器。使用ECS中转是为了避免将RDS暴露到公网上。

2、在RDS控制台上的“备份恢复”中找到“数据备份”,七天内的全量备份是带有下载地址的。点击后会产生一个24小时有效的下载地址。下载回去后按照文档说明进行恢复。

如何将阿里云RDS PgSQL恢复到本地主机中

1. 时间很好理解,其实就是触及这个时间后的XLOG中的第一个事务结束位置作为停止点。

2. 字符串,这个是需要通过pg_create_restore_point函数来创建的一个还原点,需要超级用户调用这个函数。

3. XID也很好理解,就是恢复到指定事务的结束位置。

既然我们已经知道了数据库可以恢复到指定的这几个位置,我们怎么来结合呢?

例如我们在做一笔比较重要的操作前,可以创建一个还原点(但是需要超级用户),不适合阿里云RDS。

postgres=# select pg_create_restore_point('digoal');

pg_create_restore_point

-------------------------

1D6/FB17EC08

(1 row)

阿里云为了防止一些用户的误操作,只开放了普通用户给用户使用,所以有一些东西都无法操作,例如创建检查点,切换XLOG,创建还原点都无法操作。

postgres= checkpoint;

ERROR: must be superuser to do CHECKPOINT

postgres= select pg_switch_xlog();

ERROR: must be superuser to switch transaction log files

postgres= select pg_create_restore_point('ab');

ERROR: must be superuser to create a restore point

时间其实是一个比较模糊的概念,所以也不建议使用,除非是我们没有其他信息,才使用时间。

XID是一个很不错的信息,我们在阿里云就用它了。

首先要创建一个记录还原点XID的表。记录XID,时间,以及描述信息。(来代替pg_create_restore_point系统函数的功能)

postgres= create table restore_point(id serial primary key, xid int8, crt_time timestamp default now(), point text);

CREATE TABLE

创建一个函数,代替pg_create_restore_point的功能,插入还原点。

postgres= create or replace function create_restore_point(i_point text) returns void as $$

declare

begin

insert into restore_point(xid,point) values (txid_current(),i_point);

end;

$$ language plpgsql strict;

CREATE FUNCTION

插入一个还原点

postgres= select create_restore_point('digoal');

create_restore_point

----------------------

(1 row)

查询这个表的信息:

postgres= select * from restore_point;

id | xid | crt_time | point

----+--------+----------------------------+--------

1 | 561426 | 2015-06-19 09:18:57.525475 | digoal

(1 row)

postgres= select * from restore_point where point='digoal';

id | xid | crt_time | point

----+--------+----------------------------+--------

1 | 561426 | 2015-06-19 09:18:57.525475 | digoal

(1 row)

接下来要模拟一下还原:

postgres= create table test(id int,info text);

CREATE TABLE

postgres= insert into test select generate_series(1,1000),md5(random()::text);

INSERT 0 1000

记录当前哈希值。用于恢复后的比对。

postgres= select sum(hashtext(t.*::text)) from test t;

sum

--------------

-69739904784

(1 row)

接下来我要做一笔删除操作,在删除前,我先创建一条还原点信息。

postgres= select create_restore_point('before delete test');

create_restore_point

----------------------

(1 row)

postgres= delete from test;

DELETE 1000

postgres= select * from restore_point where point='before delete test';

id | xid | crt_time | point

----+--------+----------------------------+--------------------

2 | 561574 | 2015-06-19 09:45:28.030295 | before delete test

(1 row)

我只需要恢复到561574 即可。接下来就是模拟恢复了。

但是这个文件可能还没有归档,而pg_switch_xlog()函数又不能用,我们只能主动产生一些XLOG,让RDS触发归档。

postgres= select pg_xlogfile_name(pg_current_xlog_location());

pg_xlogfile_name

--------------------------

000000010000000200000041

(1 row)

postgres= insert into test select generate_series(1,100000);

INSERT 0 100000

postgres= insert into test select generate_series(1,100000);

INSERT 0 100000

postgres= select pg_xlogfile_name(pg_current_xlog_location());

pg_xlogfile_name

--------------------------

000000010000000200000042

(1 row)

已经切换。接下来我们需要下载阿里云RDS的备份和归档到本地。

并且在本地需要安装一个postgresql, 并且与阿里云RDS的编译配置参数一致(例如数据块的大小),最好使用的模块也一致,但是这里没有用到其他模块,所以无所谓。

给阿里云RDS一个建议,最好提供用户一个软件打包,方便用户恢复,降低恢复门槛。

编译项可以使用pg_config命令查看,但是RDS我们没有办法这么查看。通过pg_settings来看吧。

postgres= select name,setting,unit from pg_settings where category='Preset Options';

name | setting | unit

-----------------------+---------+------

block_size | 8192 |

data_checksums | on |

integer_datetimes | on |

max_function_args | 100 |

max_identifier_length | 63 |

max_index_keys | 32 |

segment_size | 131072 | 8kB

server_version | 9.4.1 |

server_version_num | 90401 |

wal_block_size | 8192 |

wal_segment_size | 2048 | 8kB

(11 rows)

postgres= select version();

version

--------------------------------------------------------------------------------------------------------------

PostgreSQL 9.4.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 64-bit

(1 row)

本地编译安装PostgreSQL 9.4.1,编译参数与RDS一致。阿里云RDS这几个参数都是默认的。

--with-blocksize=BLOCKSIZE

set table block size in kB [8]

--with-segsize=SEGSIZE set table segment size in GB [1]

--with-wal-blocksize=BLOCKSIZE

set WAL block size in kB [8]

--with-wal-segsize=SEGSIZE

set WAL segment size in MB [16]

如何将阿里云的数据库备份RDS文件在本地恢复

打开腾讯手机管家-更多-微云网盘

进入微云界面后我们会发现微云界面有三种不同的功能选项,分别是网盘相册和传输三种功能。 进入到微云网盘中用Q登陆,我们能上传我们的资料等,下次可以在别处用Q登陆微云根据不同需求进行不同的选择和使用,能很好的保护我们的资料

阿里云rds物理备份后,怎么本地恢复

你用的是RDS还是ECS啊,如果是ECS上的数据库可以用 mysqldump备份出来,或者是phpmyadmin备份出来也很简单,mysqldump的导出方式是 mysqldump -u 用户名 -p 数据库名 导出的文件名 ,导出一个表就是 mysqldump -u 用户名 -p 数据库名 表名

上一篇:注册阿里云企业邮箱(阿里云企业邮箱配置)
下一篇:华为云桌面代理(华为云桌面系统搭建)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~