您的位置:首页 > 数据库 > Oracle

简单的oracle备份与恢复

2013-05-13 10:35 477 查看
一个简单的oracle备份的脚本
#!/bin/sh
#define variable......
backup_date=`date +%Y%m%d`
backup_dest=/home/oracle/backup/data
backup_log=/home/oracle/backup/log

#starting exp backup.....
exp myp001/1234567 file=$backup_dest/myp001_data_$backup_date.dmp log=$backup_log/myp001_data_$backup_date.log

find $backup_dest -type f -mtime +5 -exec rm {} \;
find $backup_log -type f -mtime +5 -exec rm {} \;

——————————————————————————
把这个脚本 加在定时计划任务中,比如每天晚上11点来执行此脚本
注意要切换到 root 命令下来执行
su -
crontab -e
0 23 * * * su - oracle -c "/home/oracle/backup/exp.sh" >/dev/null 2>&1
这样就会在/home/oracle/backup/data 生成.dmp的备份文件
恢复这些 .dmp的文件
恢复时先要情况数据库,或者重新创建一个用户
用imp 命令来恢复
[oracle@localhost ~]$ imp myp001/1234567
Import: Release 11.2.0.1.0 - Production on Thu Jul 15 05:54:32 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Import data only (yes/no): no > yes
Import file: expdat.dmp > huasu_data_20130511.dmp
Enter insert buffer size (minimum is 8192) 30720>

Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no >

Ignore create error due to object existence (yes/no): no >

Import grants (yes/no): yes >

Import table data (yes/no): yes >

Import entire export file (yes/no): no > yes
.................................................
............................
...................................
Import terminated successfully with warnings.
[oracle@localhost ~]$
这样就恢复成功了,也可以把.dmp的文件在另一台数据库上 来进行恢复
---------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle备份与恢复