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
ALTER 
DATABASE(7) SQL Commands ALTER DATABASE(7) NAME
ALTER DATABASE - change a database SYNOPSIS
ALTER DATABASE name SET variable { TO | = } { value | DEFAULT } ALTER DATABASE name RESET variable DESCRIPTION
ALTER DATABASE is used to change the session default of a run-time configuration variable for a PostgreSQL database. Whenever a new session is subsequently started in that database, the specified value becomes the session default value. The database-specific default overrides whatever setting is present in postgresql.conf or has been received from the postmaster. Only a superuser or the database owner can change the session defaults for a database. PARAMETERS name The name of the database whose session defaults are to be altered. variable value Set the session default for this database of the specified configuration variable to the given value. If value is DEFAULT or, equiv- alently, RESET is used, the database-specific variable setting is removed and the system-wide default setting will be inherited in new sessions. Use RESET ALL to clear all settings. See SET [set(7)] and the Administrator's Guide for more information about allowed variable names and values. DIAGNOSTICS
ALTER DATABASE Message returned if the alteration was successful. ERROR: database "dbname" does not exist Error message returned if the specified database is not known to the system. NOTES
Using ALTER USER [alter_user(7)], it is also possible to tie a session default to a specific user rather than a database. User-specific settings override database-specific ones if there is a conflict. EXAMPLES
To disable index scans by default in the database test: ALTER DATABASE test SET enable_indexscan TO off; COMPATIBILITY
The ALTER DATABASE statement is a PostgreSQL extension. SEE ALSO
ALTER USER [alter_user(7)], CREATE DATABASE [create_database(l)], DROP DATABASE [drop_database(l)], SET [set(l)] SQL - Language Statements 2002-11-22 ALTER DATABASE(7)
All times are GMT -4. The time now is 09:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy