Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Restore database improve code Post 303046011 by mustfirst on Tuesday 21st of April 2020 03:03:56 PM
Old 04-21-2020
Restore database improve code

let me know if you can suggest any improvement in my code. I think i have too many ECHO.


Code:
#! /bin/bash

DATABASE=$1
DATE=$2
MYLOGIN=/home/dbadmin/login_dev.ini
BKUP_FILE=/home/dbadmin/delete
DB_NAME=$DATABASE.sql.gz


DBEXISTS=$(mysql --defaults-extra-file=$MYLOGIN --batch --skip-column-names -e "SHOW DATABASES LIKE '"$DATABASE"';" | grep "$DATABASE" > /dev/null; echo "$?")


if [ $DBEXISTS -eq 0 ];then
    clear
	
	echo ".........................................................................."
	echo "$DATABASE already exists. Back up and drop $DATABASE before running restore_full_db.sh. Exiting..."
	echo ".........................................................................."
	echo ""
	echo ""
	
	exit
else 	

	if [ -f $BKUP_FILE/$DATE/$DB_NAME ] 
		then
		
			clear
		
			echo "$DB_NAME decompressed"
			echo ".........................................................................."
			gzip -d $BKUP_FILE/$DATE/$DB_NAME
			echo ""
			echo ""
			echo ""

			echo "$DATABASE created"
			echo ".........................................................................."
			mysql --defaults-extra-file=$MYLOGIN <<< "create database $DATABASE"
			echo ""
			echo ""
			echo ""

			echo "Data restoring in $DATABASE"
			echo ".........................................................................."
			mysql --defaults-extra-file=$MYLOGIN "$DATABASE" < "$BKUP_FILE/$DATE/$DATABASE.sql"
			echo ""
			echo ""
			echo ""
			echo "Data restored. Exit..."
			echo ""
			echo ""
			echo ""

		else
			
			echo ".........................................................................."
			echo "$DB_NAME file not found. Exiting..."
			echo ".........................................................................."
			echo ""
			echo ""
			
			exit
	fi

fi

Moderator's Comments:
Mod Comment
Code tags please.

Last edited by Peasant; 04-22-2020 at 01:17 AM..
 

4 More Discussions You Might Find Interesting

1. AIX

mksysb restore - Wrong OS level for restore

Hi all, I am still working on my mksysb restore. My latest issue is during an alt_disk_install from tape I got the following error after all the data had been restored. 0505-143 alt_disk_install: Unable to match mksysb level 5.2.0 with any available boot images. Please correct this... (0 Replies)
Discussion started by: pobman
0 Replies

2. Solaris

Restore a database on solaris..

hi All, Can anyone help me with the set of commands which are used to restore maybe a sybase database on solaris.. (1 Reply)
Discussion started by: sankasu
1 Replies

3. Programming

Improve the performance of my C++ code

Hello, Attached is my very simple C++ code to remove any substrings (DNA sequence) of each other, i.e. any redundant sequence is removed to get unique sequences. Similar to sort | uniq command except there is reverse-complementary for DNA sequence. The program runs well with small dataset, but... (11 Replies)
Discussion started by: yifangt
11 Replies

4. Shell Programming and Scripting

Improve awk code that has three separate parts

I have a very inefficient awk below that I need some help improving. Basically, there are three parts, that ideally, could be combined into one search and one output file. Thank you :). Part 1: Check if the user inputted string contains + or - in it and if it does the input is writting to a... (4 Replies)
Discussion started by: cmccabe
4 Replies
OCI_FIELD_TYPE(3)														 OCI_FIELD_TYPE(3)

oci_field_type - Returns a field's data type name

SYNOPSIS
mixed oci_field_type (resource $statement, mixed $field) DESCRIPTION
Returns a field's data type name. PARAMETERS
o $statement - A valid OCI statement identifier. o $field - Can be the field's index (1-based) or name. RETURN VALUES
Returns the field data type as a string, or FALSE on errors. EXAMPLES
Example #1 oci_field_type(3) example <?php // Create the table with: // CREATE TABLE mytab (number_col NUMBER, varchar2_col varchar2(1), // clob_col CLOB, date_col DATE); $conn = oci_connect("hr", "hrpwd", "localhost/XE"); if (!$conn) { $m = oci_error(); trigger_error(htmlentities($m['message']), E_USER_ERROR); } $stid = oci_parse($conn, "SELECT * FROM mytab"); oci_execute($stid, OCI_DESCRIBE_ONLY); // Use OCI_DESCRIBE_ONLY if not fetching rows echo "<table border="1"> "; echo "<tr>"; echo "<th>Name</th>"; echo "<th>Type</th>"; echo "<th>Length</th>"; echo "</tr> "; $ncols = oci_num_fields($stid); for ($i = 1; $i <= $ncols; $i++) { $column_name = oci_field_name($stid, $i); $column_type = oci_field_type($stid, $i); $column_size = oci_field_size($stid, $i); echo "<tr>"; echo "<td>$column_name</td>"; echo "<td>$column_type</td>"; echo "<td>$column_size</td>"; echo "</tr> "; } echo "</table> "; // Outputs: // Name Type Length // NUMBER_COL NUMBER 22 // VARCHAR2_COL VARCHAR2 1 // CLOB_COL CLOB 4000 // DATE_COL DATE 7 oci_free_statement($stid); oci_close($conn); ?> NOTES
Note In PHP versions before 5.0.0 you must use ocicolumntype(3) instead. This name still can be used, it was left as alias of oci_field_type(3) for downwards compatability. This, however, is deprecated and not recommended. SEE ALSO
oci_num_fields(3), oci_field_name(3), oci_field_size(3). PHP Documentation Group OCI_FIELD_TYPE(3)
All times are GMT -4. The time now is 05:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy