oracle expdp自动备份脚本
windows:
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo 1. 使用当前日期命名备份文件。 echo 2. 自动删除7天前的备份。 echo ================================================ ::以“YYYYMMDD”格式取出当前时间。 set BACKUPDATE=%date:~0,4%%date:~5,2%%date:~8,2% ::设置导出的路径 set DATADIR=F:\app\Administrator\admin\orcl\dpdump\ expdp smxy/smxy2018!@orcl directory=DATA_PUMP_DIR dumpfile=smxy%BACKUPDATE%.DUMP schemas=smxy ::删除7天前的备份。 forfiles /p %DATADIR% /s /m HBGYDX*.DUMP /d -7 /c "cmd /c del @path" exit
linux:
#!/bin/bash PATH=$PATH:$HOME/bin ORACLE_BASE=/data01/oracleDB ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 ORACLE_SID=orcl PATH=$ORACLE_HOME/bin:$PATH export ORACLE_BASE ORACLE_HOME ORACLE_SID export PATH NLS_LANG=AMERICAN_AMERICA.UTF8 export NLS_LANG #export DELTIME=`date -d "15 days ago" +%Y%m%d` export BACKUPTIME=`date +%Y%m%d%H%M%S` echo "Starting backup..." echo "Backup file path $DATA_DIR/$BAKUPTIME.dump" echo "Backuping HR system data" expdp user/user@orcl directory=DATA_PUMP_DIR_BACKUP dumpfile=user$BACKUPTIME.DUMP schemas=user #备份用户数据 echo "Delete 3 days before data files..." echo "Delete backup cycle before HR system backup data" #rm -f /data01/backup/HDSFDX_HR$DELTIME*.DUMP find /data01/backup/ -mtime +15 -name "user*.dump" -exec rm -rf {} \; #删除前15天的数据