From d363938ad77d41edfe820347244fae2685769a06 Mon Sep 17 00:00:00 2001 From: Jerome Quere Date: Thu, 20 Apr 2017 21:41:03 +0200 Subject: [PATCH] Add mongodump task --- indi-backup | 1 + lib/task.sh | 3 ++ lib/tasks/mongo.sh | 64 ++++++++++++++++++++++++++++++++ lib/tasks/tarball-incremental.sh | 3 +- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/mongo.sh diff --git a/indi-backup b/indi-backup index 1f81a99..9c7cd59 100755 --- a/indi-backup +++ b/indi-backup @@ -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 diff --git a/lib/task.sh b/lib/task.sh index 1aa8519..ac5c600 100644 --- a/lib/task.sh +++ b/lib/task.sh @@ -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 ;; diff --git a/lib/tasks/mongo.sh b/lib/tasks/mongo.sh new file mode 100644 index 0000000..858f36a --- /dev/null +++ b/lib/tasks/mongo.sh @@ -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; +} diff --git a/lib/tasks/tarball-incremental.sh b/lib/tasks/tarball-incremental.sh index b928dd8..4b29dca 100644 --- a/lib/tasks/tarball-incremental.sh +++ b/lib/tasks/tarball-incremental.sh @@ -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"