Remark ----------------------------------------------------------------------------------
Remark filename: user_online_backup_linux.sql
Remark description: User management online backup for linux (Linux下用户管理的在线备份)
Remark ----------------------------------------------------------------------------------
Prompt ****** Connect to database as sysdba
Remark connect / as sysdba;
Prompt sys/****** as sysdba;
connect sys/****** as sysdba;
archive log list;
Remark Set SQL*Plus variables to manipulate output
set termout on
set trimspool on
set echo off
set feedback off
set heading off
set verify off
set pagesize 0
set linesize 200
set serveroutput on
Remark set environment variable
Remark ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
Remark ORACLE_HOME==$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME
Remark ORACLE_SID=ORATEST; export ORACLE_SID
Remark Set SQL*Plus variables used in this script
define dbdir = '/u01/app/oracle/oradata/ORATEST'
define archivedir = '&dbdir/archive'
define backupdir = '/u01/app/oracle/oradata/ORATEST/backup/online'
define archivebackupdir = '&backupdir/archive'
define cpfile = '&backupdir/backup_filelist.sql'
-- archive log
alter system archive log current;
Prompt
Prompt ****** Spooling cp commands to &cpfile
Remark Create a command file with file backup commands
spool &cpfile;
declare
cursor cur_ts is
select *
from dba_tablespaces
where status <> 'READ ONLY'
and contents <> 'TEMPORARY';
cursor cur_df(ts_name varchar2) is
select *
from dba_data_files
where tablespace_name = ts_name;
begin
for vcur_ts in cur_ts loop
dbms_output.put_line('alter tablespace '||vcur_ts.tablespace_name||' begin backup;');
for vcur_df in cur_df(vcur_ts.tablespace_name) loop
dbms_output.put_line('host cp -p '''||vcur_df.file_name||''' &backupdir/');
end loop;
dbms_output.put_line('alter tablespace '||vcur_ts.tablespace_name||' end backup;');
end loop;
dbms_output.put_line('alter database backup controlfile to trace as ''&backupdir/controlfile.trace'';');
dbms_output.put_line('alter database backup controlfile to ''&backupdir/controlfile.binary'';');
dbms_output.put_line('create pfile=''&backupdir/spfile_backup.ora'';');
end;
/
spool off;
set feedback on
Prompt
Prompt ****** Copy file to &backupdir
Remark Run the copy file commands from the operating system
@&cpfile;
-- archive log
alter system archive log current;
Prompt
Prompt ****** Copy archive log file to &archivebackupdir
host cp -p &archivedir/* &archivebackupdir/;
Prompt
Prompt ****** Backup Complete
exit;