Search This Blog

Friday, February 21, 2014

RMAN: Restore controlfiles


Sometimes, your loose all your controlfiles, your instance is down, and you think you're in a big sh**. But here's a solution.


Check your last controlfile backup to get your DBID :
ls -l *.bck
-rw-rw---- 1 oracle oracle   10092544 Apr 15 15:49 c-159519437-20110415-06.bck

The DBID is the first number block : 159519437


Then, go to RMAN and restore your controlfile from the last backup:

rman target /

set DBID=159519437

startup nomount

set controlfile autobackup format for device type disk to '/backup/file/location/%F';

restore controlfile from autobackup;


The last action, recover and start the database

recover database;

alter database open resetlogs;

Tuesday, February 4, 2014

Linux: Generate a random password

The main script, has to be saved in a separate file, or modified as a function:
#!/bin/bash

#add special characters you want to use in the password here:
charspool=('a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p'
'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '0' '1' '2' '3' '4' '5' '6' '7'
'8' '9' '0' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O'
'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' '$' '-' '_');

len=${#charspool[*]} if [ $# -lt 1 ]; then         num=$1; else         num=$1; fi randomnumbers=$(head -c $num /dev/urandom | od -t u1 | awk '{for (i = 2; i <= NF; i++) print $i}') for c in $randomnumbers; do         echo -n ${charspool[$((c % len))]} done echo

and to call it:
lenPassword=8
# echo $(/path/to/script/gen_password.sh $lenPassword);