备份的作用
数据库备份还原的作用是防止误操作,天灾,设备故障,软件故障导致的数据丢失,保障数据的安全可用
备份的方法
冷备 (关闭数据库,dmap服务是打开,dmrman工具做备份)
数据库实例在关闭的情况下进行备份
启动dmap服务:
[dmdba@localhost ~]$/etc/rc.d/init.d/DmAPService status
如果启动的时候,提示管道文件已经存在.
删除管道文件,重新启动($DM_HOME/bin)
DM_PIPE_DMAP_LSNR_*
关闭数据库服务:
[dmdba@localhost bin]$/etc/rc.d/init.d/DmServiceDMSERVER stop
切换到$DM_HOME/bin调用dmrman工具:
[dmdba@localhost bin]$cd /dm7/bin
[dmdba@localhostbin]$ ./dmrman
RMAN> backup database '/dm7/data/DAMENG/dm.ini' backupset '/dm7/backup/20200207'
冷备还原:
RMAN> restore database'/dm7/data/DAMENG/dm.ini' from backupset '/dm7/backup/20200207'
冷备恢复:
RMAN> recover database'/dm7/data/DAMENG/dm.ini' from backupset '/dm7/backup/20200207'
启动数据库:
[dmdba@localhost20200207]$ /etc/rc.d/init.d/DmServiceDMSERVER start
热备(数据库是打开,数据库要打开归档,dmap服务要打开)
数据库实例在开启的情况下进行备份
达梦数据库打开归档:
查看数据库的归档状态:
SQL> selectarch_mode from v$database;
1.数据库到配置模式:
SQL> alterdatabase mount;
2.配置数据库的归档文件:
SQL> alterdatabase add archivelog 'dest=/dm7/arch,type=local,file_size=64,space_limit=0';
3.打开归档:
SQL> alterdatabase archivelog;
4.打开数据库:
SQL> alterdatabase open;
Dmap服务:
[dmdba@localhostDAMENG]$ /etc/rc.d/init.d/DmAPService status
数据库的状态:
[dmdba@localhostDAMENG]$ /etc/rc.d/init.d/DmServiceDMSERVER status
热备份:可以备份数据库,备份表空间,备份表,备份归档
备份数据库:(如果要还原整个数据库,要利用dmrman)
SQL> backupdatabase backupset '/dm7/backup/full_bak';
备份表空间:(不能单独备份system,roll)
SQL> backuptablespace dmhr backupset '/dm7/backup/dmhr_bak';
备份表:(只能还原到备份的时刻)
SQL> backuptable dmhr.city backupset '/dm7/backup/city_bak';
备份归档:
SQL> backuparchivelog backupset '/dm7/backup/arch_bak';
还原表空间:
1. 利用整个数据库的备份
SQL> alter tablespace dmhroffline;
SQL> restore tablespace dmhrfrom backupset '/dm7/backup/full_bak/';
SQL> alter tablespace dmhronline;
2. 表空间的备份
SQL>alter tablespace dmhr offline;
SQL> restore tablespace dmhrfrom backupset '/dm7/backup/dmhr_bak/';
SQL> alter tablespace dmhronline;
还原表和归档直接还原
可以做增量备份:(前提要有一次完全备份)
SQL> backup database backupset '/dm7/data/DAMENG/bak/full';
SQL> backupdatabaseincrement with backupdir '/dm7/data/DAMENG/bak/full/'backupset '/dm7/data/DAMENG/bak/incr';
逻辑备份(SQL语句)(dexp dimp)
适合做数据合并,适合历史数据的归档,要求数据是打开
获取帮助:[dmdba@localhost~]$ dexp help
备份数据库:
[dmdba@localhost~]$ dexp sysdba/SYSDBA file=/dm7/backup/full.dmpfull=y
备份表:
[dmdba@localhost~]$ dexp sysdba/SYSDBA file=/dm7/backup/emp_dept.dmptables=dmhr.employee,dmhr.department
备份模式:
[dmdba@localhost~]$ dexp sysdba/SYSDBA file=/dm7/backup/dmhr.dmp schemas=dmhr
备份用户:
[dmdba@localhost~]$ dexp sysdba/SYSDBA file=/dm7/backup/dmhr1.dmp owner=dmhr
还原:(dimp)
获取帮助:[dmdba@localhost~]$ dimp help
SQL> drop userdmhr cascade;
SQL> createuser dmhr identified by "dameng123" default tablespace dmhr;
SQL> grantresource to dmhr;
[dmdba@localhost~]$ dimp sysdba/SYSDBA file=/dm7/backup/dmhr1.dmp owner=dmhr