|
|
|
@ -1,30 +1,34 @@
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
TIMESTAMP=$(date +"%F")
|
|
|
|
|
APATH=$(pwd)
|
|
|
|
|
|
|
|
|
|
echo "==========LOGS : $TIMESTAMP==========="
|
|
|
|
|
|
|
|
|
|
if [ $APATH = "/root" ]; then
|
|
|
|
|
echo "USING IN ROOT"
|
|
|
|
|
APATH="$(pwd)/../home/dev"
|
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]];then
|
|
|
|
|
export TPATH=$(find /Users -type d -name "maettleship" 2> /dev/null | head -n 1)
|
|
|
|
|
else
|
|
|
|
|
export TPATH=$(find /home -type d -name "maettleship" 2> /dev/null | head -n 1)
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
BACKUP_DIR="$APATH/maettleship_save"
|
|
|
|
|
SRC_DIR="$APATH/maettleship"
|
|
|
|
|
echo "==========LOGS : $TIMESTAMP==========="
|
|
|
|
|
|
|
|
|
|
# GET PATH AND CREATE VARIABLE
|
|
|
|
|
echo "PATH TO DIR : $TPATH"
|
|
|
|
|
BACKUP_DIR="$TPATH/../maettleship_save"
|
|
|
|
|
SRC_DIR="$TPATH"
|
|
|
|
|
mkdir -p "$BACKUP_DIR/$TIMESTAMP"
|
|
|
|
|
source "$SRC_DIR/.env"
|
|
|
|
|
|
|
|
|
|
echo "BACKUP_DIR : $BACKUP_DIR"
|
|
|
|
|
echo "SRC_DIR : $SRC_DIR"
|
|
|
|
|
echo "ENVIRONMENT : $ACTUAL_ENV"
|
|
|
|
|
|
|
|
|
|
# GET DOCKER CONTAINER ID
|
|
|
|
|
CONTAINERID=$(docker ps | grep "mysql" | cut -d ' ' -f 1)
|
|
|
|
|
echo "CONTAINER ID : $CONTAINERID"
|
|
|
|
|
|
|
|
|
|
if [ $ACTUAL_ENV = 'dev' ]; then
|
|
|
|
|
docker exec -i maettleship_db_1 mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > "$BACKUP_DIR/$TIMESTAMP/$DB_NAME.sql"
|
|
|
|
|
docker exec -i $CONTAINERID mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > "$BACKUP_DIR/$TIMESTAMP/$DB_NAME.sql"
|
|
|
|
|
else
|
|
|
|
|
db_password_file=$(cat $SRC_DIR/secrets/db_password.txt)
|
|
|
|
|
db_name_file=$(cat $SRC_DIR/secrets/db_name.txt)
|
|
|
|
|
docker exec -i maettleship_db_1 mysqldump -u $DB_USER -p$db_password_file $db_name_file > "$BACKUP_DIR/$TIMESTAMP/$db_name_file.sql"
|
|
|
|
|
docker exec -i $CONTAINERID mysqldump -u $DB_USER -p$db_password_file $db_name_file > "$BACKUP_DIR/$TIMESTAMP/$db_name_file.sql"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "DATA SAVED ON THE $BACKUP_DIR/$TIMESTAMP/$db_name_file.sql file."
|
|
|
|
|