-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tangoslee/develop
Develop
- Loading branch information
Showing
23 changed files
with
357 additions
and
2,041 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[ -f ~/.bashrc ] && . ~/.bashrc | ||
PS1=$(printf "docker>$PS1") | ||
#PS1=$(printf "docker>$PS1") | ||
export PS1="docker>$PS1" | ||
export PATH=$HOME/bin:$PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@echo off | ||
SETLOCAL EnableDelayedExpansion | ||
|
||
if "%1" == "" ( | ||
SET CONTAINER="php" | ||
) else ( | ||
SET CONTAINER="%1" | ||
) | ||
|
||
if "%2" == "" ( | ||
docker exec -it %CONTAINER% /bin/bash --init-file ~/.bashrc_docker | ||
) else ( | ||
SET USER="--user %2" | ||
docker exec -it %USER% %CONTAINER% /bin/bash --init-file ~/.bashrc_docker | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
#!/bin/bash | ||
# https://opensource.com/article/19/9/linux-terminal-colors | ||
|
||
CONTAINER=workspace | ||
CONTAINER=php | ||
OPT="-it" | ||
|
||
[ "$1" != "" ] && CONTAINER=$1 | ||
[ "$1" != "" ] && CONTAINER="$1" | ||
[ "$2" != "" ] && OPT="$OPT --user $2" | ||
|
||
docker exec -it $CONTAINER /bin/bash --init-file ~/.bashrc_docker | ||
docker exec -it $OPT $CONTAINER /bin/bash --init-file ~/.bashrc_docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# https://dev.mysql.com/doc/refman/8.0/en/creating-accounts.html | ||
__DIR__=$(dirname $(readlink -f $0)) | ||
|
||
config=$__DIR__/../.env | ||
|
||
DBNAME="$1" | ||
|
||
[ "$DBNAME" = "" ] && { | ||
echo "usage: `basename $0` dbname" | ||
exit 1 | ||
} | ||
|
||
echo "Drop database $DBNAME" | ||
|
||
#CMD="mysql -h db.localhost -u root -p$PASS mysql" | ||
CMD="mysql -h db.localhost -u root mysql" | ||
TMP=.user.sql | ||
|
||
[ -f "$TMP" ] && rm -f "$TMP" | ||
|
||
cat<<EOL > $TMP | ||
DROP DATABASE IF EXISTS $DBNAME; | ||
EOL | ||
|
||
{ | ||
$CMD < "$TMP" | ||
} && { | ||
[ -f "$TMP" ] && rm -f "$TMP" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/sh | ||
#It is best that --tab be used only for dumping a local server. If you use it with a remote server, the --tab directory must exist on both the local and remote hosts, and the .txt files are written by the server in the remote directory (on the server host), whereas the .sql files are written by mysqldump in the local directory (on the client host). | ||
# https://dev.mysql.com/doc/refman/8.0/en/mysqldump-delimited-text.html | ||
CWD=$(dirname $(readlink -f "$0")) | ||
ENV=${CWD}/../.env | ||
|
||
[ -f "$ENV" ] && { | ||
. "$ENV" | ||
} | ||
|
||
|
||
DATABASE="$1" | ||
CMD="docker exec mysql" | ||
|
||
[ "$DATABASE" = "" ] && { | ||
cat<<EOL | ||
usage: $(basename $0) database_to_restore | ||
EOL | ||
exit 1 | ||
} | ||
|
||
SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }') | ||
[ "$SECURE_DIR" = "" ] && SECURE_DIR=/var/lib/mysql-files | ||
|
||
[ -d "${DB_DUMP_DIR}" ] && | ||
{ | ||
echo "Cleaning ${DB_DUMP_DIR} before dump" | ||
find "${DB_DUMP_DIR}" -type f -exec rm -f {} \; | ||
} && { | ||
echo "Dump Started to ${DB_DUMP_DIR}" | ||
$CMD mysqldump "$DATABASE" --tab=$SECURE_DIR --fields-terminated-by=0x1e --single-transaction --order-by-primary | ||
} && { | ||
echo "The job has been successfully done!" | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
#It is best that --tab be used only for dumping a local server. If you use it with a remote server, the --tab directory must exist on both the local and remote hosts, and the .txt files are written by the server in the remote directory (on the server host), whereas the .sql files are written by mysqldump in the local directory (on the client host). | ||
# https://dev.mysql.com/doc/refman/8.0/en/mysqldump-delimited-text.html | ||
CWD=$(dirname $(readlink -f "$0")) | ||
ENV=${CWD}/../.env | ||
|
||
[ -f "$ENV" ] && { | ||
. "$ENV" | ||
} | ||
|
||
SRC=${DB_DUMP_DIR} | ||
DATABASE="$1" | ||
CMD="docker exec mysql" | ||
|
||
[ "$DATABASE" = "" ] && { | ||
cat<<EOL | ||
usage: $(basename "$0") database_to_restore | ||
EOL | ||
exit 1 | ||
} | ||
|
||
SECURE_DIR=$($CMD mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv';" | awk '{ print $2 }') | ||
[ "$SECURE_DIR" = "" ] && SECURE_DIR=/var/lib/mysql-files | ||
|
||
echo "Start to restore database from ${SRC}" | ||
{ | ||
echo "Drop database: ${DATABASE}" | ||
$CMD mysql -e "DROP DATABASE IF EXISTS $DATABASE" | ||
} && { | ||
echo "Create database" | ||
$CMD mysql -e "CREATE DATABASE IF NOT EXISTS $DATABASE" 2> /dev/null | ||
} && { | ||
echo "Restore $DATABASE" | ||
for localTxtFile in "${SRC}"/*.txt; do | ||
localSqlFile=${localTxtFile/${SRC}/${SECURE_DIR::-1}} | ||
table=$(basename "${localTxtFile::-4}") | ||
rows=$(wc -l "${localTxtFile}" | awk '{ print $1 }') | ||
sqlFile=${localSqlFile/.txt/.sql} | ||
txtFile=${localTxtFile/${SRC}/${SECURE_DIR::-1}} | ||
|
||
#echo "Create table: $table" | ||
$CMD mysql "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;source ${sqlFile};" | ||
|
||
echo -n "Restore data: $table (${rows} rows)" | ||
startedAt=$(date +%s.%3N) | ||
$CMD mysql "${DATABASE}" --local-infile=1 -e "SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;SET AUTOCOMMIT=0;ALTER TABLE ${table} DISABLE KEYS;LOAD DATA LOCAL INFILE '${txtFile}' INTO TABLE ${table} FIELDS TERMINATED BY 0x1e LINES TERMINATED BY '\n';COMMIT;ALTER TABLE ${table} ENABLE KEYS;" | ||
endedAt=$(date +%s.%3N) | ||
time1=$(echo "scale=3; ${endedAt} - ${startedAt}" | bc) | ||
echo " $time1 sec" | ||
done | ||
|
||
$CMD mysql "${DATABASE}" -e "SET FOREIGN_KEY_CHECKS=1;SET UNIQUE_CHECKS=1;SET AUTOCOMMIT=1;" | ||
} && { | ||
echo "The job has been successfully done!" | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.