sqtsqt 发表于 2018-9-26 09:12:28

简单的oracle备份与恢复

  一个简单的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/1234567file=$backup_dest/myp001_data_$backup_date.dmplog=$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 命令来恢复
  $ imp myp001/1234567

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

  Connected to: Oracle Database 11g Enterprise Edition>  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>  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.
  $
  这样就恢复成功了,也可以把.dmp的文件在另一台数据库上 来进行恢复
  ---------------------------------

页: [1]
查看完整版本: 简单的oracle备份与恢复