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
MSSQL_FETCH_FIELD(3)													      MSSQL_FETCH_FIELD(3)

mssql_fetch_field - Get field information

SYNOPSIS
object mssql_fetch_field (resource $result, [int $field_offset = -1]) DESCRIPTION
mssql_fetch_field(3) can be used in order to obtain information about fields in a certain query result. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). o $field_offset - The numerical field offset. If the field offset is not specified, the next field that was not yet retrieved by this function is retrieved. The $field_offset starts at 0. RETURN VALUES
Returns an object containing field information. The properties of the object are: o name - column name. if the column is a result of a function, this property is set to computed#N, where #N is a serial number. o column_source - the table from which the column was taken o max_length - maximum length of the column o numeric - 1 if the column is numeric o type - the column type. EXAMPLES
Example #1 mssql_fetch_field(3) example <?php // Connect to MSSQL and select the database mssql_connect('MANGOSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php'); // Send a select query to MSSQL $query = mssql_query('SELECT * FROM [php].[dbo].[persons]'); // Construct table echo '<h3>Table structure for 'persons'</h3>'; echo '<table border="1">'; // Table header echo '<thead>'; echo '<tr>'; echo '<td>Field name</td>'; echo '<td>Data type</td>'; echo '<td>Max length</td>'; echo '</tr>'; echo '</thead>'; // Dump all fields echo '<tbody>'; for ($i = 0; $i < mssql_num_fields($query); ++$i) { // Fetch the field information $field = mssql_fetch_field($query, $i); // Print the row echo '<tr>'; echo '<td>' . $field->name . '</td>'; echo '<td>' . strtoupper($field->type) . '</td>'; echo '<td>' . $field->max_length . '</td>'; echo '</tr>'; } echo '</tbody>'; echo '</table>'; // Free the query result mssql_free_result($query); ?> SEE ALSO
mssql_field_seek(3). PHP Documentation Group MSSQL_FETCH_FIELD(3)
All times are GMT -4. The time now is 04:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy