关于我们
技术分享
技术分享
备份&恢复系列之二:在linux中对oracle进行热备份的脚本!
备份&恢复系列之二:在linux中对oracle进行热备份的脚本!
2021-06-03
测试环境:
1 操作系统:Redhat Linux 5
[oracle@mzl proc]$ cat /proc/version
Linux version 2.6.18-8.el5 (brewbuilder@ls20-bc2-14.build.redhat.com) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:21 EST 2007
2 数据库版本:Oracle10g
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
3 数据库的名字:orcl
SQL> show parameter db_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string orcl
4 数据库的所有数据文件所在位置
SQL> select file#,status,enabled,name from v$datafile;
FILE# STATUS ENABLED NAME
---------- ------- ---------- ------------------------------------------
1 SYSTEM READ WRITE /u01/app/oracle/oradata/orcl/system01.dbf
2 ONLINE READ WRITE /u01/app/oracle/oradata/orcl/undotbs01.dbf
3 ONLINE READ WRITE /u01/app/oracle/oradata/orcl/sysaux01.dbf
4 ONLINE READ WRITE /u01/app/oracle/oradata/orcl/users01.dbf
5 ONLINE READ WRITE /u01/app/oracle/oradata/orcl/example01.dbf
5 控制文件的所在位置
SQL> select * from v$controlfile;
STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS
------- ------------------------------------------ --- ---------- --------------
/u01/app/oracle/oradata/orcl/control01.ctl NO 16384 430
/u01/app/oracle/oradata/orcl/control02.ctl NO 16384 430
/u01/app/oracle/oradata/orcl/control03.ctl NO 16384 430
6 重做日志文件位置
SQL> col member format a45
SQL> l
1* select * from v$logfile
SQL> /
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- --------------------------------------------- ---
3 ONLINE /u01/app/oracle/oradata/orcl/redo03.log NO
2 STALE ONLINE /u01/app/oracle/oradata/orcl/redo02.log NO
1 STALE ONLINE /u01/app/oracle/oradata/orcl/redo01.log NO
7 我在/home/mzl/BackupDatabase/目录下写个hotbak.sql脚本
[oracle@mzl proc]$ vi /home/mzl/BackupDatabase/hotbak.sql
脚本内容如下:
#rem script.:hotbak.sql
#rem creater:mengzhaoliang
#rem data:2008/2/4
#rem desc:backup all database datafile in archive
#enter database
$ORACLE_HOME/bin/sqlplus "/as sysdba" <<EOF
alter system archive log current;
#start
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/system01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/undotbs01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/users01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/sysaux01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/orcl/example01.dbf /home/mzl/BackupDatabase/;
alter tablespace system end backup;
#backup control file
#binary
alter database backup controlfile to '/home/mzl/BackupDatabase/controlbinarybackup';
#ascii
alter database backup controlfile to trace;
alter system archive log current;
<<EOF
8 在linux启动一个终端执行该hotbak.sql脚本
[oracle@mzl BackupDatabase]$ ./hotbak.sql
热备份完毕!
附上piner的说明:
说明:
1、热备份必须在数据库归档方式下才可以运行
2、以上脚本可以在数据库运行状态下备份数据库所有的数据文件(除了临时数据文件),没有必要备份联机日志。
3、归档日志至少需要一次完整备份之后的所有日志。
4、如果以上命令没有成功依次执行,那么备份也是无效的,如连接数据库不成功,那么备份则无效。
- 标签:
-
容灾备份
您可能感兴趣的新闻 换一批
热门文章
现在下载,可享30天免费试用