diff --git a/.env b/.env index 5a1a22b..16fce6a 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -ACTUAL_ENV=dev +ACTUAL_ENV=prod DB_USER=root DB_PASSWORD=password DB_NAME=battleship diff --git a/tools/db_auto_save.sh b/tools/db_auto_save.sh index 88892db..b24f27e 100755 --- a/tools/db_auto_save.sh +++ b/tools/db_auto_save.sh @@ -1,17 +1,32 @@ #!/bin/bash -source .env - TIMESTAMP=$(date +"%F") -BACKUP_DIR="../maettleship_save" +APATH=$(pwd) + +echo "==========LOGS : $TIMESTAMP===========" + +if [ $APATH = "/root" ]; then + echo "USING IN ROOT" + APATH="$(pwd)/../home/dev" +fi + +BACKUP_DIR="$APATH/maettleship_save" +SRC_DIR="$APATH/maettleship" + mkdir -p "$BACKUP_DIR/$TIMESTAMP" +source "$SRC_DIR/.env" + +echo "BACKUP_DIR : $BACKUP_DIR" +echo "SRC_DIR : $SRC_DIR" +echo "ENVIRONMENT : $ACTUAL_ENV" if [ $ACTUAL_ENV = 'dev' ]; then - docker exec -i mysql-maettleship mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > "$BACKUP_DIR/$TIMESTAMP/$DB_NAME.sql" + docker exec -i maettleship_db_1 mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > "$BACKUP_DIR/$TIMESTAMP/$DB_NAME.sql" else - db_user_file=$(cat ./secrets/db_user.txt) - db_password_file=$(cat ./secrets/db_password.txt) - db_name_file=$(cat ./secrets/db_name.txt) - docker exec -i mysql-maettleship mysqldump -u $db_user_file -p$db_password_file $db_name_file > "$BACKUP_DIR/$TIMESTAMP/$db_name_file.sql" + 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" fi -find "$BACKUP_DIR/" -type d -mtime +7 -exec rm -rf {} \; \ No newline at end of file +find "$BACKUP_DIR/" -type d -mtime +7 -exec rm -rf {} \; + +echo " "