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

mysql_create_db - Create a MySQL database

SYNOPSIS
Warning This function was deprecated in PHP 4.3.0, and will be removed in the future, along with the entirety of the original MySQL exten- sion. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: omysqli_query(3) o PDO::query bool mysql_create_db (string $database_name, [resource $link_identifier = NULL]) DESCRIPTION
mysql_create_db(3) attempts to create a new database on the server associated with the specified link identifier. o $database_name - The name of the database being created. o $ link_identifier -The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect(3) is assumed. If no such link is found, it will try to create one as if mysql_connect(3) was called with no arguments. If no connection is found or established, an E_WARNING level error is generated. Returns TRUE on success or FALSE on failure. Example #1 mysql_create_db(3) alternative example The function mysql_create_db(3) is deprecated. It is preferable to use mysql_query(3) to issue an sql CREATE DATABASE statement instead. <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } $sql = 'CREATE DATABASE my_db'; if (mysql_query($sql, $link)) { echo "Database my_db created successfully "; } else { echo 'Error creating database: ' . mysql_error() . " "; } ?> The above example will output something similar to: Database my_db created successfully Note For backward compatibility, the following deprecated alias may be used: mysql_createdb(3) Note This function will not be available if the MySQL extension was built against a MySQL 4.x client library. mysql_query(3), mysql_select_db(3). PHP Documentation Group MYSQL_CREATE_DB(3)
All times are GMT -4. The time now is 04:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy