Monday, February 12, 2024

EXPDP & IMPDP Automation Shell Script ?

kayyum@AbdulKayyum:~$ cat *.sh
#!/bin/bash

select com in expdp impdp
do
        case ${com} in
                "expdp")
                        command="expdp "
                        select opt in userpassword directory dumpfile schemas tables logfile exclude include show_command Quite
                        do
                                case ${opt} in
                                        "userpassword")
                                                read -p "Enter user/password: " userpassword
                                                command+="${userpassword} "
                                                ;;
                                        "directory")
                                                read -p "Enter directory: " directory
                                                command+="directory=${directory} "
                                                ;;
                                        "dumpfile")
                                                read -p "Enter dumpfile: " dumpfile
                                                command+="dumpfile=${dumpfile} "
                                                ;;
                                        "schemas")
                                                read -p "number of schemas: " n
                                                schem=""
                                                for i in $(seq 1 $n)
                                                do
                                                        read -p "Enter schemaname: " schm
                                                        if test ${i} -lt  ${n}
                                                        then
                                                                #read -p "Enter schemaname: " schm
                                                                schem+="${schm}, "
                                                        fi
                                                        if test ${i} -eq ${n}
                                                        then
                                                                schem+="${schm}"
                                                        fi
                                                done
                                                command+="schemas=${schem} "
                                                ;;
                                        "tables")
                                                read -p "number of tables: " n
                                                tabl=""
                                                for i in $(seq 1 $n)
                                                do
                                                        read -p "Enter tablename: " tbl
                                                        if test ${i} -lt ${n}
                                                        then
                                                        #       read -p "Enter tablename: " tbl
                                                                tabl+="${tbl},"
                                                        fi
                                                        if test ${i} -eq ${n}
                                                        then
                                                                tabl+="${tbl}"
                                                        fi
                                                done
                                                command+="tables=${tabl} "
                                                ;;
                                        "exclude")
                                                command+="exclude=STATISTICS "
                                                echo "exclude=STATISTICS added !"
                                                ;;
                                        "include")
                                                read -p "Enter number of tables for include: " n
                                                schemtbl=""
                                                for i in $(seq 1 $n)
                                                do
                                                      read -p "Enter schema.table: " schematable
                                                        if test ${i} -lt ${n}
                                                        then
                                                        #read -p "Enter schema.table: " schematable
                                                                schemtbl+="'${schematable}',"
                                                        fi
                                                        if test ${i} -eq ${n}
                                                        then
                                                                schemtbl+="'${schematable}'"
                                                        fi
                                                done
                                                command+='include=table:"in('${schemtbl}')"'
                                                ;;
                                        "logfile")
                                                read -p "Enter logfile: " logfile
                                                command+="logfile=${logfile} "
                                                ;;
                                        "show_command")
                                                echo ${command}
                                                ;;
                                        "Quite")
                                                break
                                                ;;
                                esac
                        done;;
                "impdp")
                        command="impdp "
                        select opt in userpassword directory dumpfile schemas tables logfile exclude include show_command remap_objects Quite
                        do
                                case ${opt} in
                                        "userpassword")
                                                read -p "Enter user/password: " userpassword
                                                command+="${userpassword} "
                                                ;;
                                        "directory")
                                                read -p "Enter directory: " directory
                                                command+="directory=${directory} "
                                                ;;
                                        "dumpfile")
                                                read -p "Enter dumpfile: " dumpfile
                                                command+="dumpfile=${dumpfile} "
                                                ;;
                                        "schemas")
                                                read -p "number of schemas: " n
                                                schem=""
                                                for i in $(seq 1 $n)
                                                do
                                                        read -p "Enter schemaname: " schm
                                                        if test ${i} -lt ${n}
                                                        then
                                                        #       read -p "Enter schemaname: " schm
                                                                schem+="${schm},"
                                                        fi
                                                        if test ${i} -eq ${n}
                                                        then
                                                                schem+="${schm}"
                                                        fi
                                                done
                                                command+="schemas=${schem} "
                                                ;;
                                        "tables")
                                                read -p "number of tables: " n
                                                tabl=""
                                                for i in $(seq 1 $n)
                                                do
                                                        read -p "Enter tablename: " tbl
                                                        if test ${i} -lt ${n}
                                                        then
                                                        #       read -p "Enter tablename: " tbl
                                                                tabl+="${tbl},"
                                                        fi
                                                        if test ${i} -eq ${n}
                                                        then
                                                                tabl+="${tbl}"
                                                        fi
                                                done
                                                command+="tables=${tabl} "
                                                ;;
                                        "logfile")
                                                read -p "Enter logfile: " logfile
                                                command+="logfile=${logfile} "
                                                ;;
                                        "exclude")
                                                command+="exclude=STATISTICS "
                                                echo "exclude=STATISTICS added !"
                                                ;;
                                        "include")
                                                read -p "Enter number of tables for include: " n
                                                schemtbl=""
                                                for i in $(seq 1 $n)
                                                do
                                                        read -p "Enter schema.table: " schematable
                                                        if test ${i} -lt ${n}
                                                        then
                                                        #read -p "Enter schema.table: " schematable
                                                                schemtbl+="'${schematable}',"
                                                        fi
                                                        if test ${i} -eq ${n}
                                                        then
                                                                schemtbl+="'${schematable}'"
                                                        fi
                                                done
                                                command+='include=table:"in('${schemtbl}')"'
                                                ;;
                                         "remap_objects")
                                             select option in remap_schema remap_table remap_tablespace remap_datafile remap_directory remap_partition main_menu
     do 
        case ${option} in
                "remap_schema")
                        content=" remap_schema="
                        read -p "Enter source_schema: " source_schema
                        read -p "Enter target_schema: " target_schema
                        content+="${source_schema}:${target_schema} "
                        echo "${content} "
                        command+="${content} "
                        ;;
                "remap_table")
                        content="remap_table="
                        read -p "Enter source_schema.source_table: " source1
                        read -p "Enter target_schema.target_table: " target
                        content+="${source1}:${target} "
                        echo "${content} "
                        command+="${content} "
                        ;;
                "remap_tablespace")
                        content="remap_tablespace="
                        read -p "Enter source_tablespace: " source_tablespace
                        read -p "Enter target_tablespace: " target_tablespace
                        content+="${source_tablespace}:${target_tablespace} "
                        echo "${content} "
                        command+="${content} "
                        ;;
                "remap_datafile")
                        content="remap_datafile="
                        read -p "Enter source_datafile: " source_datafile
                        read -p "Enter target_datafile: " target_datafile
                        content+="${source_datafile}:${target_datafile} "
                        echo  "${content} "
                        command+="${content} "
                        ;;
                "remap_directory")
                        content="remap_directory="
                        read -p "Enter source_directory: " source_directory
                        read -p "Enter target_directory: " target_directory
                        content+="${source_directory}:${target_directory} "
                        echo "${content} "
                        command+="${content} "
                        ;;
                "remap_partition")
                        content="remap_partition="
                        read -p "Enter source_schema.source_table.source_partition: " source1
                        read -p "Enter target_schema.target_table.target_partition: " target
                        content+="${source1}:${target} "
                        echo "${content} "
                        command+="${content} "
                        ;;
                                                        "main_menu")
break
;;
        esac
done
;;
                                               
                                        "show_command")
                                                echo ${command}
                                                ;;
"Quite")
                                                break
                                                ;;
                                esac
                        done;;
        esac
done

No comments:

Post a Comment

Enable OpenSSH on Windows 11

Step 1: Install OpenSSH Server You can do this via PowerShell (run as Administrator ): Check if it's already available: Get-WindowsCapab...