冷备份
一、备份
1.编写备份脚本
通过操作系统的命令来实现的备份机制:cp、scp
1.1查询所有的文件所在位置(数据文件,控制文件,参数文件,重做日志文件,归档日志文件,初始化参数文件,密码文件)
查看参数文件位置show parameter spfile;
SYS@orcl11g>
select
name
from
v$datafile
2
union
3
select
name
from
v$controlfile
4
union
5
select
member
from
v$logfile;
1.2创建备份的路径
SYS@orcl11g> host mkdir /u01/app/backup
1.3通过
select
语句构建拷贝脚本
SYS@orcl11g>
set
trim
on
截取掉不必要的空格
SYS@orcl11g>
set
trims
on
每个行的空格
SYS@orcl11g>
set
heading
off
去掉标题
SYS@orcl11g>
set
echo
off
去掉反馈
SYS@orcl11g>
set
feedback
off
去掉回显
SYS@orcl11g>
set
term
off
关闭终端信息
SYS@orcl11g> spool /home/oracle/cp.sql
SYS@orcl11g>
select
'cp '
||
name
||
' /u01/app/backup'
from
v$datafile
union
select
'cp '
||
name
||
' /u01/app/backup'
from
v$controlfile
union
select
'cp '
||member||
' /u01/app/backup'
from
v$logfile
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SYS@orcl11g>
select
'cp '
||
name
||
' /u01/app/backup/'
from
v$datafile;
--只备份数据文件
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cp /u01/app/oracle/fast_recovery_area/orcl11g/control02.ctl /home/backup
cp /u01/app/oracle/oradata/orcl11g/control01.ctl /home/backup
cp /u01/app/oracle/oradata/orcl11g/example01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/redo01.log /home/backup
cp /u01/app/oracle/oradata/orcl11g/redo02.log /home/backup
cp /u01/app/oracle/oradata/orcl11g/redo03.log /home/backup
cp /u01/app/oracle/oradata/orcl11g/sysaux01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/system01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/undotbs01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/users01.dbf /home/backup
[oracle@db253 ~]$ spool
off
[oracle@db253 ~]$ vi cp.sql
[oracle@db253 ~]$ cat cp.sql
cp /u01/app/oracle/fast_recovery_area/orcl11g/control02.ctl /home/backup
cp /u01/app/oracle/oradata/orcl11g/control01.ctl /home/backup
cp /u01/app/oracle/oradata/orcl11g/example01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/redo01.log /home/backup
cp /u01/app/oracle/oradata/orcl11g/redo02.log /home/backup
cp /u01/app/oracle/oradata/orcl11g/redo03.log /home/backup
cp /u01/app/oracle/oradata/orcl11g/sysaux01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/system01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/undotbs01.dbf /home/backup
cp /u01/app/oracle/oradata/orcl11g/users01.dbf /home/backup
[oracle@db253 ~]$ chmod +x cp.sql
awk构建命令:
ls -lSr /test | awk
'{print "mv " $NF" /tmp/test/t"NR".conf"}'
| bash
2.停止数据库
sql> shutdown immediate;
3.拷贝数据文件
[oracle@db253 ~]$ /home/oracle/cp.sql
--执行脚本
4.开启数据库
sql> startup;
二、恢复(操作系统重新安装后恢复数据)
1.正常安装oracle软件,只需要安装软件,可以不用建实例。软件安装好以后,开始准备恢复
2.数据覆盖过去,包括pwd文件,放在原来的目录,如果目录有所改变,则需要另外建立控制文件,修改pfile
3.建立服务:使用oradism命令建立一个服务 oradism -new -sid 服务名
4.建立监听:net configuration assintant来建立监听
5.打开数据库
set oracle_sid=服务名
sqlplus / as sysdba
startup
热备份(使用归档模式来进行备份)
1、查看数据库归档状态
2、数据库备份
2.1、查询要备份表空间对应的数据文件信息
select file_name from dba_data_files where table_space_name='表空间名字';
2.2、将表空间设为备份模式
ALTER TABLESPACE USERS BEGIN BACKUP;
2.3、查看处于备份模式的数据文件
select * from v$backup;
2.4、备份表空间的数据文件
host copy
2.5、将表空间设置为正常模式
ALTER TABLESPACE USERS END BACKUP;
####查看数据库是否开启归档模式
详见https://www.2cto.com/database/201307/226243.html