The Nautilus DevOps team is working on to develop a bash script to automate some tasks. As per the requirements shared with the team database related tasks needed to be automated. Below you can find more details about the same:
-
Write a bash script named
/opt/scripts/database.sh
onDatabase Server
. The mariadb database server is already installed on this server. -
Add code in the script to perform some database related operations as per conditions given below:
a. Create a new database named kodekloud_db01
. If this database already exists on the server then script should print a message Database already exists
and if the database does not exist then create the same and script should print Database kodekloud_db01 has been created
. Further, create a user named kodekloud_roy
and set its password to asdfgdsd
, also give full access to this user on newly created database (remember to use wildcard host while creating the user).
b. Now check if the database (if it was already there) already contains some data (tables)if so then script should print 'database is not empty
otherwise import the database dump /opt/db_backups/db.sql
and print imported database dump into kodekloud_db01 database.
c. Take a mysql dump which should be named as kodekloud_db01.sql
and save it under /opt/db_backups/
directory.
task getting failed even though the dump file is under /opt/db_backups. please see attached screenshot.