Bash for DBAs – Part 3

This is the last part of the series, and as promised I’ll have a script to perform database export. If you wish to read the first posts, here they are: part1, part2.

The script is interactive and this is how it works:

  • The script performs full database export
  • It will ask you where to put the file and the file name
  • It will check if the file exists and if it is if you wish to overwrite it
  • There are defaults for everything
  • I tried to perform all the necessary checks so it won’t get any strange errors
  • I wrote many comments so you can understand what I did and why

Last note, I wrote this script for educational purposes. You are welcome to use it freely, but at your risk, it might contain errors or bugs.

The script:

Run examples:


$ ./run_export.sh

Welcome to the export assistant
===============================

Please enter Oracle Home to use for export [leave empty to use '/opt/oracle/product/ora12c']:
Please enter database SID [leave empty to use 'ora12']:
Please enter a username with privileges to export the database [leave empty to use '/ as sysdba']:
Please enter directory for the dump file [leave empty to use '/tmp']:
Please enter dump file name [leave empty to use 'full_export.dmp']:

Export will use the following:
------------------------------
Oracle home:              /opt/oracle/product/ora12c
Oracle SID:               ora12
Export will be done by:   sys as sysdba
Export file:              /tmp/full_export.dmp
Log file:                 /tmp/full_export.log

Is this ok? [y for yes, anything else to abort]: y

File '/tmp/full_export.dmp' already exist, overwrite? [y for yes, anything else to abort]: y

Exporting the database... Done

Export completed successfully!

$
$
$ ./run_export.sh
Welcome to the export assistant
===============================

Please enter Oracle Home to use for export [leave empty to use '/opt/oracle/product/ora12c']:
Please enter database SID [leave empty to use 'ora12']:
Please enter a username with privileges to export the database [leave empty to use '/ as sysdba']: system
Please enter system's password:
Please enter directory for the dump file [leave empty to use '/tmp']: /tmp/export
Please enter dump file name [leave empty to use 'full_export.dmp']: my_export

Export will use the following:
------------------------------
Oracle home:              /opt/oracle/product/ora12c
Oracle SID:               ora12
Export will be done by:   system
Export file:              /tmp/export/my_export.dmp
Log file:                 /tmp/export/my_export.log

Is this ok? [y for yes, anything else to abort]: y

Exporting the database... Done

Export completed successfully!

Advertisements

One thought on “Bash for DBAs – Part 3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s