Skip to content

Commit

Permalink
Add mongodump task
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome-quere committed Apr 20, 2017
1 parent 0a1dfe4 commit d363938
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions indi-backup
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ source $IB_LIB_DIR/utils.sh

source $IB_LIB_DIR/task.sh
source $IB_LIB_DIR/tasks/docker-mysql-dumper.sh
source $IB_LIB_DIR/tasks/mongo.sh
source $IB_LIB_DIR/tasks/mysql.sh
source $IB_LIB_DIR/tasks/subtask.sh
source $IB_LIB_DIR/tasks/tarball.sh
Expand Down
3 changes: 3 additions & 0 deletions lib/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function ib_task_run() {
subtask)
ib_task_subtask_run "$taskName" || return -1
;;
mongo)
ib_task_mongo_run "$taskName" || return -1
;;
mysql)
ib_task_mysql_run "$taskName" || return -1
;;
Expand Down
64 changes: 64 additions & 0 deletions lib/tasks/mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
################################################################################
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Indigen-Solution
# See the AUTHORS file for details.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
################################################################################

##
# This method execute a task of type "mysql"
# @param taskName The name of the task to execute
##
function ib_task_mongo_run() {
local taskName="$1";
local host=$(ib_get_conf_value "IB_TASK_${taskName}_HOST")
local port=$(ib_get_conf_value "IB_TASK_${taskName}_PORT")
local user=$(ib_get_conf_value "IB_TASK_${taskName}_USER")
local password=$(ib_get_conf_value "IB_TASK_${taskName}_PASSWORD")
local databases=$(ib_get_conf_value "IB_TASK_${taskName}_DATABASES")
local storageName=$(ib_get_conf_value "IB_TASK_${taskName}_STORAGE")

[ -z "$databases" ] && databases="__ALL__"

[ -z "$storageName" ] && echo "No valid IB_TASK_${taskName}_STORAGE found" && return -1

local options=""
[ ! -z "$host" ] && options="${options} --host=${host}"
[ ! -z "$port" ] && options="${options} --port=${port}"
[ ! -z "$user" ] && options="${options} --username=${user}"
[ ! -z "$password" ] && options="${options} --password=${password}"


if [[ "$databases" == "__ALL__" ]]
then
mongodump $options --archive --gzip |
ib_storage_run "$storageName" "$taskName" "${taskName}-${DATE}.archive.gz" || return -1
return 0
fi

for database in $databases
do
mongodump $options --db="$database" --archive --gzip |
ib_storage_run "$storageName" "$taskName" "${database}-${DATE}.archive.gz" || return -1
done
return 0;
}
3 changes: 2 additions & 1 deletion lib/tasks/tarball-incremental.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function ib_task_tarball-incremental_run() {
[ -z "$masterFrequencyValue" ] && masterFrequencyValue=1

if [[ (( "$masterFrequency" == "weekly" ) && ( $(date "+%u") -eq "$masterFrequencyValue" )) || \
(( "$masterFrequency" == "monthly" ) && ( $(date "+%d") -eq "$masterFrequencyValue" )) ]]
(( "$masterFrequency" == "monthly" ) && ( $(date "+%d") -eq "$masterFrequencyValue" )) || \
( ! -f "$listFile" ) ]]
then
rm -f "$listFile"
masterTag="master"
Expand Down

0 comments on commit d363938

Please sign in to comment.