-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·35 lines (29 loc) · 1.06 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#backup data directory if directoy exist
#checks if /mysql_data folder exists
if [ -d "./mysql_data" ]
then
#creates backup directory
echo "Directory ./mysql_data exists. Creating backup..."
if [[ ! -e "./backup" ]]; then
mkdir "./backup"
fi
date_dir_path=$(date +'%Y/%m/%d')
time=$(date +%H-%M-%S)
#prepares backup directory in Year/Month/Date/time/
#-p parameter creates directories if any of them are not found
mkdir -p ./backup/$date_dir_path/$time/
echo "Moved ./mysql_data to ./backup/$date_dir_path/$time"
mv -f ./mysql_data ./backup/$date_dir_path/$time/
else
echo "Directory ./mysql_data does not exists. Nothing to backup..."
fi
echo "attempt to stop any mysql container..."
docker stop mysql
echo "execute docker-compose build..."
docker build --tag mysql_docker:v0.1 .
docker run -it -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --rm --name mysql mysql_docker:v0.1
echo "copying database file to host..."
docker cp mysql:/var/lib/mysql/ ./mysql_data/
echo "stopping container..."
docker stop mysql
echo "finished!"