1.编写备份脚本
通过操作系统的命令来实现的备份机制:cp、scp
1.1查询所有的文件所在位置(数据文件,控制文件,参数文件,重做日志文件,密码文件)
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;
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341