朋友說到一個生產(chǎn)線上表數(shù)據(jù)被大批量誤操作了,能否恢復(fù)。
千萬別跑路,只要數(shù)據(jù)數(shù)據(jù)庫,無論是MySQL,PG,Oracle等,只要日志和備份在,都可以恢復(fù)到任意故障點。
只是操作方法不同而已。
可以通過在其它機器基于故障點恢復(fù)備份數(shù)據(jù)
在其它環(huán)境中搭建一套PG環(huán)境:
編譯安裝的參數(shù)特別重要,否則不能啟動,建議分離 data和安裝軟件目錄,這是只需tar軟件包即可。
1)查看線上環(huán)境基礎(chǔ)配置:
show all;可以看到生產(chǎn)環(huán)境的blocksize和wal-segsize
2)采用線上環(huán)境版本PG軟件編譯安裝
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
./configure --prefix=/opt/postgres --with-pgport=5432 --with-python --with-libxml --with-wal-segsize=16 --with-blocksize=8
make && make install
插件安裝:
cd contrib
make && make install
3)基于時間點恢復(fù)數(shù)據(jù)庫:
停數(shù)據(jù)庫
# pg_stop
利用備份恢復(fù)
# rm -rf data
tar xvf pgdata.tar
利用 pg_waldump 找到問題的點,然后修改 recovery.conf 恢復(fù)到指定的時間點。
拷貝recovery.conf文件并修改以指定時間點恢復(fù)
# cp $PG_HOME/share/recovery.conf.sample /home/postgres/data
# vi /opt/postgres/data/recovery.conf
--新增內(nèi)容,指定恢復(fù)文件和路徑,%f,%p見上面說明
restore_command = 'cp /opt/postgres/archive/%f %p'
recovery_target_time = '2018-12-29 10:24:00+09'
恢復(fù)數(shù)據(jù)后,dump表的數(shù)據(jù)到生產(chǎn)線即可。
99)這個工作建議手工打造
尤其是確定故障點,然后手工進行恢復(fù),多方面確認,最后才能放心將數(shù)據(jù)放到生產(chǎn)線。