1 #!/opt/tcl8.3.0/bin/tclsh8.3
3 # .-------------.------------------------------------------------------.
4 # | module | dbbackup.tcl |
5 # `-------------^------------------------------------------------------'
7 # .--------------------------------------------------------------------.
9 # |--------------------------------------------------------------------|
10 # | 07/25/96 (TMH) eliminated the need for a library file. |
11 # | 02/10/97 (TMH) converted to tcl7.6, oratcl 2.4. |
12 # | 12/02/98 (TMH) eliminate all pipes to /bin/sh for final release |
13 # `--------------------------------------------------------------------'
15 # .--------------------------------------------------------------------.
16 # | Copyright (c) 1998, Purdue University |
17 # | All rights reserved. |
18 # `--------------------------------------------------------------------'
20 # .--------------------------------------------------------------------.
21 # | Redistribution and use in source and binary forms are permitted |
24 # | (1) source distributions retain this entire copyright notice and |
26 # | (2) distributions including binaries display the following |
27 # | acknowledgement: |
29 # | "This product includes software developed by Purdue University." |
30 # | in the documentation or other materials provided with the |
31 # | distribution and in all advertising materials mentioning features |
32 # | or use of this software. |
34 # | The name of the University may not be used to endorse or promote |
35 # | products derived from this software without specific prior written |
38 # | THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
39 # | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
40 # | WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR |
42 # `--------------------------------------------------------------------'
44 package require -exact Oratcl 2.7
47 set df_dest /opt/oracle/backup
48 set cf_dest [file join $df_dest "ctl$env(ORACLE_SID).ctl"]
54 # .--------------------------------------------------------------------.
56 # `--------------------------------------------------------------------'
58 return [clock format [clock seconds] -format {%c}]
62 # .-------------.------------------------------------------------------.
63 # | procedure | ora_Connect |
64 # | date | (09/02/94) |
65 # `-------------^------------------------------------------------------'
71 set retcode [catch {set lda [oralogon ${uidpswd}]}]
73 set cur [oraopen $lda]
79 # .-------------.------------------------------------------------------.
80 # | procedure | ora_Disconnect |
81 # | author | Todd M. Helfter |
82 # | date | (09/02/94) |
83 # `-------------^------------------------------------------------------'
84 proc ora_Disconnect {} {
86 return [catch {oralogoff $lda }]
90 # .-------------.------------------------------------------------------.
91 # | procedure | print_log |
92 # `-------------^------------------------------------------------------'
98 set sql {select min(sequence#), max(sequence#) from v$log}
99 if {[catch {orasql $cur $sql}] == 0} {
100 orafetch $cur "set log_min @1; set log_max @2"
102 puts stdout [format "\nOldest online log sequence\t%s" $log_min]
103 puts stdout [format "Current log sequence\t\t%s\n" $log_max]
108 # .-------------.------------------------------------------------------.
109 # | procedure | ora_SQL |
110 # `-------------^------------------------------------------------------'
111 proc ora_SQL {sql_str} {
114 set dbret [catch {orasql $cur $sql_str}]
116 puts stdout $oramsg(errortxt)
127 # .--------------------------------------------------------------------.
129 # `--------------------------------------------------------------------'
131 global cur ts_list df_list oramsg uidpswd
134 if {[ora_Connect] == 0} {
135 set sql0 "SELECT tablespace_name FROM sys.dba_tablespaces"
136 if {[catch {orasql $cur $sql0}] == 0} {
137 orafetch $cur {lappend ts_list @0}
140 puts stdout $oramsg(errortxt)
145 foreach ts_name $ts_list {
146 set df_list($ts_name) {}
147 set sql1 "SELECT file_name FROM sys.dba_data_files \
148 where tablespace_name = '$ts_name'"
149 if {[catch {orasql $cur $sql1}] == 0} {
150 orafetch $cur {lappend df_list($ts_name) @0}
152 puts stdout $oramsg(errortxt)
160 # .--------------------------------------------------------------------.
162 # `--------------------------------------------------------------------'
164 global ts_list df_list
166 foreach ts_name $ts_list {
167 puts stdout "ts_name : $ts_name"
169 foreach df_name $df_list($ts_name) {
170 puts stdout " df_name : $df_name"
177 # .--------------------------------------------------------------------.
179 # `--------------------------------------------------------------------'
181 global ts_list df_list df_dest cf_dest
185 foreach ts_name $ts_list {
187 puts stdout "[sysdate] | begin online backup for : $ts_name"
189 ora_SQL "alter tablespace $ts_name begin backup"
191 foreach df_name $df_list($ts_name) {
192 puts stdout "[sysdate] | copying $df_name to $df_dest."
194 file copy -force -- $df_name $df_dest
196 puts stdout "[sysdate] | end online backup for : $ts_name"
198 ora_SQL "alter tablespace $ts_name end backup"
200 puts stdout "[sysdate] | switching logfile."
202 ora_SQL {alter system switch logfile}
206 puts stdout "[sysdate] | copying control file to $cf_dest."
208 ora_SQL "alter database backup controlfile to '$cf_dest' reuse"
212 # .-------------.------------------------------------------------------.
213 # | procedure | main |
214 # | purpose | scan database and report results to parent window |
215 # | author | Todd M. Helfter |
216 # | date | (10/13/94) |
217 # `-------------^------------------------------------------------------'
219 global cur uidpswd oramsg ts_list df_list