deploy/dump_db.sh
author Riwad Salim <riwad.salim@yahoo.fr>
Wed, 11 Sep 2019 12:30:41 +0200
changeset 37 d6e8b9ad5a74
parent 23 5249c3c623a6
permissions -rwxr-xr-x
Add tooltip feature with jquery-ui
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env bash
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
SCRIPTNAME=`basename "$0"`
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
usage() {
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
  echo -n "${SCRIPTNAME} [CONFIG] [DB_FILE_PATH]
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
Dump the database to <DB_FILE_PATH> using ansible.
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
Beware this will replace the dest file without warning
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
"
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
}
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
if [[ "$#" -ne 2 ]]; then
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    usage
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    exit 1
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
fi
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
config=${1}
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
db_file_path=${2}
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
case $config in
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    test) configOK=true;;
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    prod) configOK=true;;
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    *)    configOK=false;;
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
esac
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
if [[ "$configOK" = false ]]; then
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    usage
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    exit 1
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
fi
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
pushd "$SCRIPTPATH"
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
ANSIBLE_SSH_PIPELINING=1 ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -v -i "./hosts/hosts.$config" -l "$config" ./dump_db.yml --extra-vars "db_file_path='${db_file_path}'" --ask-vault-pass
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
5249c3c623a6 Add a command to dump the database
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
popd