重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3836|回复: 4

产生oracle手工方式备份的脚本

[复制链接]
发表于 2013-12-29 11:56:35 | 显示全部楼层 |阅读模式

   select 'alter tablespace ' || tablespace_name || ' begin backup;' || chr(10) || chr(13) ||
           '! cp ' || file_name || ' /home/oracle/' || substr(file_name,33)  || chr(10) || chr(13) ||
           'alter tablespace ' || tablespace_name || ' end backup;'
   from dba_data_files;

 

结果如下:

 

SQL> r

'ALTERTABLESPACE'||TABLESPACE_NAME||'BEGINBACKUP;'||CHR(10)||CHR(13)||'!CP'||FIL
--------------------------------------------------------------------------------
alter tablespace USERS begin backup;
! cp /u01/app/oracle/oradata/sztech1/users01.dbf /home/oracle/users01.dbf
alter tablespace USERS end backup;

alter tablespace UNDOTBS1 begin backup;
! cp /u01/app/oracle/oradata/sztech1/undotbs01.dbf /home/oracle/undotbs01.dbf
alter tablespace UNDOTBS1 end backup;

alter tablespace SYSAUX begin backup;
! cp /u01/app/oracle/oradata/sztech1/sysaux01.dbf /home/oracle/sysaux01.dbf
alter tablespace SYSAUX end backup;

alter tablespace SYSTEM begin backup;
! cp /u01/app/oracle/oradata/sztech1/system01.dbf /home/oracle/system01.dbf
alter tablespace SYSTEM end backup;

alter tablespace EXAMPLE begin backup;
! cp /u01/app/oracle/oradata/sztech1/example01.dbf /home/oracle/example01.dbf
alter tablespace EXAMPLE end backup;

alter tablespace TBSBC begin backup;
! cp /u01/app/oracle/oradata/sztech1/tbsbc12.dbf /home/oracle/tbsbc12.dbf
alter tablespace TBSBC end backup;


6 rows selected.

[此贴子已经被作者于2013-12-29 12:06:51编辑过]
回复

使用道具 举报

 楼主| 发表于 2013-12-29 11:57:32 | 显示全部楼层

也可以写成一个sql文件

比如 一个sql 文件test.sql:

 

[oracle@dbserver ~]$ more test.sql
set head off
set echo off
set feedback off
spool /home/oracle/prod.sql
select 'alter tablespace ' || tablespace_name || ' begin backup;' || chr(10) || chr(13) ||
       '! cp ' || file_name || ' /home/oracle/' || substr(file_name,33)  || chr(10) || chr(13) ||
       'alter tablespace ' || tablespace_name || ' end backup;'
from dba_data_files;

spool off
exit

[此贴子已经被作者于2013-12-29 12:07:14编辑过]
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-29 11:59:18 | 显示全部楼层

在执行

 

$ sqlplus / as sysdba @test.sql

 

结果如下:

 

[oracle@dbserver ~]$ ls -ltr prod.sql
total 16472
-rw-r--r-- 1 oracle oinstall     1460 Dec 29 09:35 prod.sql
[oracle@dbserver ~]$

 

查看结果:

[oracle@dbserver ~]$ more prod.sql

alter tablespace USERS begin backup;                                           
! cp /u01/app/oracle/oradata/sztech1/users01.dbf /home/oracle/users01.dbf     
alter tablespace USERS end backup;                                            
                                                                               
alter tablespace UNDOTBS1 begin backup;                                        
! cp /u01/app/oracle/oradata/sztech1/undotbs01.dbf /home/oracle/undotbs01.dbf 
alter tablespace UNDOTBS1 end backup;                                         
                                                                               
alter tablespace SYSAUX begin backup;                                          
! cp /u01/app/oracle/oradata/sztech1/sysaux01.dbf /home/oracle/sysaux01.dbf   
alter tablespace SYSAUX end backup;                                           
                                                                               
alter tablespace SYSTEM begin backup;                                          

! cp /u01/app/oracle/oradata/sztech1/system01.dbf /home/oracle/system01.dbf   
alter tablespace SYSTEM end backup;                                           
                                                                               
alter tablespace EXAMPLE begin backup;                                         
! cp /u01/app/oracle/oradata/sztech1/example01.dbf /home/oracle/example01.dbf 
alter tablespace EXAMPLE end backup;                                          
                                                                               
alter tablespace TBSBC begin backup;                                           
! cp /u01/app/oracle/oradata/sztech1/tbsbc12.dbf /home/oracle/tbsbc12.dbf     
alter tablespace TBSBC end backup;

 

 

[此贴子已经被作者于2013-12-29 12:09:40编辑过]
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-29 12:00:12 | 显示全部楼层

调用 prod.sql文件进行备份

 

 

$ sqlplus / as sysdba @prod.sql

 

即可.

回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-29 12:03:26 | 显示全部楼层

难点

对每个文件需要开启备份模式,再备份,再关闭备份.

这个通过 回车换行 chr(10) chr(13) 来完成,

另外,有列头,有多少行的提示 ,通过 set head off,set feedback off来完成.

 

 

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-4-18 15:19 , Processed in 0.107336 second(s), 21 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表