使用expdp命令自动备份数据库
1、创建目录对象
因为使用expdp命令需要使用到目录对象(directory),所以首先需要创建目录对象,并赋予某个用户对目录对象的操作权限.
dbserver-> sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Sat Mar 1 00:13:16 2014 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options 00:13:16 SYS@ datacenter>create directory expdp_bak_dir as '/arcerzhangoracle/backup_datacenter'; Directory created. 00:13:46 SYS@ datacenter>grant create any directory to ARCER; Grant succeeded. 00:14:18 SYS@ datacenter>
2、编辑自动备份脚本
脚本名称:auto_bak_expdp.sh,内容如下:
#!/bin/bash export ORACLE_BASE=/arcerzhangoracle/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 export ORACLE_SID=datacenter export PATH=$ORACLE_HOME/bin:$PATH a=$(date +%Y%m%d_%H%M) echo $a /arcerzhangoracle/app/oracle/product/11.2.0/db_1/bin/expdp ARCER/ARCER owner=ARCER dumpfile=$a.dmp directory=expdp_bak_dir log=$a.log
3、使用cronttab命令,设置系统自动定时执行备份脚本
crontab -e进入编辑页面,加入如下内容,使系统每隔59分钟自动备份数据库一次.
*/59 * * * * /arcerzhangoracle/auto_bak_exp/auto_bak_expdp.sh
4、查看备份脚本内容
dbserver-> pwd /arcerzhangoracle/backup_datacenter dbserver-> ll 3584 -rw-r----- 1 oracle oinstall 3469312 3 1 00:17 20140301_0016.dmp -rw-r--r-- 1 oracle oinstall 5403 3 1 00:17 20140301_0016.log -rw-r----- 1 oracle oinstall 3469312 3 1 00:22 20140301_0022.dmp -rw-r--r-- 1 oracle oinstall 5403 3 1 00:22 20140301_0022.log -rw-r----- 1 oracle oinstall 3469312 3 1 00:24 20140301_0024.dmp -rw-r--r-- 1 oracle oinstall 5403 3 1 00:24 20140301_0024.log -rw-r----- 1 oracle oinstall 3469312 3 1 00:26 20140301_0026.dmp -rw-r--r-- 1 oracle oinstall 5403 3 1 00:26 20140301_0026.log
5、数据库自动化备份工作完成