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
INTVAL(3)								 1								 INTVAL(3)

intval - Get the integer value of a variable

SYNOPSIS
int intval (mixed $var, [int $base = 10]) DESCRIPTION
Returns the integer value of $var, using the specified $base for the conversion (the default is base 10). intval(3) should not be used on objects, as doing so will emit an E_NOTICE level error and return 1. PARAMETERS
o $var - The scalar value being converted to an integer o $base - The base for the conversion Note If $base is 0, the base used is determined by the format of $var: o if string includes a "0x" (or "0X") prefix, the base is taken as 16 (hex); otherwise, o if string starts with "0", the base is taken as 8 (octal); otherwise, o the base is taken as 10 (decimal). RETURN VALUES
The integer value of $var on success, or 0 on failure. Empty arrays return 0, non-empty arrays return 1. The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807. Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply. EXAMPLES
Example #1 intval(3) examples The following examples are based on a 32 bit system. <?php echo intval(42); // 42 echo intval(4.2); // 4 echo intval('42'); // 42 echo intval('+42'); // 42 echo intval('-42'); // -42 echo intval(042); // 34 echo intval('042'); // 42 echo intval(1e10); // 1410065408 echo intval('1e10'); // 1 echo intval(0x1A); // 26 echo intval(42000000); // 42000000 echo intval(420000000000000000000); // 0 echo intval('420000000000000000000'); // 2147483647 echo intval(42, 8); // 42 echo intval('42', 8); // 34 echo intval(array()); // 0 echo intval(array('foo', 'bar')); // 1 ?> NOTES
Note The $base parameter has no effect unless the $var parameter is a string. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Throws E_NOTICE and returns 1, when an object is | | | passed to $var. | | | | +--------+---------------------------------------------------+ SEE ALSO
boolval(3), floatval(3), strval(3), settype(3), is_numeric(3), Type juggling, BCMath Arbitrary Precision Mathematics Functions. PHP Documentation Group INTVAL(3)
All times are GMT -4. The time now is 01:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy