Donnerstag, 2. Juni 2016

Oracle Database Daily Backup and delete older then 5 days


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
#exec >/tmp/export.log
#exec 2>&1

# Set Environment
. ~oracle/oracle_env_arculhbt
DIR=/oradata/arculhbt/dpdump/daily_backup
DD=DATAPUMPDIR

sqlplus / as sysdba <<EOF
  set echo on
  create or replace directory $DD as '$DIR';
  exit
EOF

DUMP=arculhbt_$(date +%Y-%m-%d)_full.dmp
LOG=arculhbt_$(date +%Y-%m-%d)_full_exp.log

if [ -f $DIR/$DUMP ];then
  echo Dump already exist! => "Abort!"
  exit 1
  # rm $DIR/$DUMP
fi

if [ -f $DIR/$LOG ];then
  rm $DIR/$LOG
fi

P=`dd if=/dev/urandom bs=512 count=1 2>/dev/null | tr -dc "a-zA-Z0-9-_\.\+\$\?" | fold -w 15 | head -1`
echo "alter user system identified by \"$P\";" | sqlplus -S "/ as sysdba"

expdp system/"$P" full=yes DIRECTORY=$DD DUMPFILE=$DUMP logfile=$LOG METRICS=YES
#  STATUS=120


sqlplus / as sysdba <<EOF
set echo on
drop directory $DD;
exit
EOF

echo
echo "-----[ DONE ]-----"

echo "Create Zip-File and delete dump-file"
zip -rm /oradata/arculhbt/dpdump/daily_backup/arculhbt_$(date +%Y-%m-%d)_full.zip /oradata/arculhbt/dpdump/daily_backup/arculhbt_$(date +%Y-%m-%d)_full.dmp /oradata/arculhbt/dpdump/daily_backup/arculhbt_$(date +%Y-%m-%d)_full_exp.log

echo "Delete Backups older then 5 days"
find /oradata/arculhbt/dpdump/daily_backup -iname "*.zip" -mtime +5 -delete

Keine Kommentare:

Kommentar veröffentlichen