Browse Source

changes to import function in database_functions.sh

joel
Simon Bowie 2 years ago
parent
commit
5e63e68179
1 changed files with 17 additions and 9 deletions
  1. +17
    -9
      database_functions.sh

+ 17
- 9
database_functions.sh View File



Export() Export()
{ {
docker exec -it $CONTAINER mysqldump --single-transaction -u $USERNAME -p$PASSWORD $DATABASE > $EXPORT_SQL_FILENAME`date +"%Y%m%d"`.sql
docker exec -it $CONTAINER mysqldump --single-transaction -u $USERNAME -p$PASSWORD $DATABASE > $EXPORT_DIRECTORY/$EXPORT_SQL_FILENAME`date +"%Y%m%d"`.sql
} }


Import() Import()
{ {
docker exec -i $CONTAINER mysql -u $USERNAME -p$PASSWORD $DATABASE < $IMPORT_SQL_DIRECTORY/$IMPORT_SQL_FILENAME
docker cp $IMPORT_SQL_FILE $CONTAINER:/tmp/import_file
docker exec -i $CONTAINER mysql -u $USERNAME -p$PASSWORD $DATABASE < /tmp/import_file
} }


Table_export() Table_export()
# set variables # set variables
CONTAINER=mariadb CONTAINER=mariadb
DATABASE=toolkit DATABASE=toolkit
USERNAME=xxxxxxxxx
PASSWORD=xxxxxxxxx
USERNAME=xxxxxxxx
PASSWORD=xxxxxxxx
EXPORT_DIRECTORY="./db_exports"
EXPORT_SQL_FILENAME=toolkit_db_ EXPORT_SQL_FILENAME=toolkit_db_
IMPORT_SQL_DIRECTORY="/Users/ad7588/Downloads"
IMPORT_SQL_FILENAME=toolkit_db.sql
EXPORT_TXT_DIRECTORY="./db_exports"
EXPORT_TXT_FILENAME=$2`date +"%Y%m%d"` EXPORT_TXT_FILENAME=$2`date +"%Y%m%d"`


# error message for no flags # error message for no flags
Export Export
exit;; exit;;
i) # import database from file i) # import database from file
Import
exit;;
if [ -z "$2" ]
then
echo "-i requires a file as an argument"
echo
echo "Syntax: database_functions.sh -i [file]"
else
IMPORT_SQL_FILE=$2
Import
exit 1
fi;;
c) # export single table as tab-delimited txt c) # export single table as tab-delimited txt
if [ -z "$2" ] if [ -z "$2" ]
then then

Loading…
Cancel
Save