-
-
Save fernando-nog/915eacbee8d83a8a5981d0bb920e40f7 to your computer and use it in GitHub Desktop.
shell scrtip for backup and restore pentaho system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Maintain for @sowe Rafael Valenzuela <ravamo@gmail.com> | |
# redcloverbi.wordpress.com for more information | |
# basic backup and restore script for pentaho in Production enviroment doc | |
# https://help.pentaho.com/Documentation/6.1/0P0/000/020 | |
# https://help.pentaho.com/Documentation/6.1/0P0/000/Backup_and_Restore_Pentaho_Repositories | |
set -e | |
set -u | |
DATE=$(date +"%Y%m%d") | |
PENTAHO_DIR='' | |
TYPEACCTION='' | |
URL='' | |
USER='' | |
PASS='' | |
FILE='' | |
LOGFILE='' | |
CHARSET='' | |
WITHMANIFEST='' | |
NAMEFILE='' | |
OVERWRITE='' | |
function _console(){ | |
local message=${1:-''} | |
[[ -n "$message" ]] && echo -e "$message" | |
} | |
function _die(){ | |
local message=${1:-''} | |
local exit_code=${2:-2} | |
_console "$message" | |
exit $exit_code | |
} | |
function _status(){ | |
echo $? | |
case $? in | |
1) _die "Publish to server failed" 1;; | |
2) _die "Publish to server failed" 2;; | |
3) _console "Publish successful";; | |
5) _die "Authentication to the publish server failed. Username or password is incorrect." 5;; | |
6) _die "Datasource publish failed" 6;; | |
7) _console "XMLA catalog already exists";; | |
8) _console "Schema already exists";; | |
9) _console "Content about to be published already exists";; | |
10) _die "Error publishing to the server due to prohibited symbols in the name of the content" 10;; | |
0) _console "Everything ok ";; | |
*) _console "Unknown error code: $?";; | |
esac | |
} | |
function rsync_mode(){ | |
local fileOrigin =${1.-''} | |
local fileDestination =${2.-''} | |
_console "rsync -avzc --no-whole-file" $fileOrigin $fileDestination | |
rsync -avzc --no-whole-file ${fileOrigin} ${fileDestination} | |
} | |
function backup (){ | |
local typeAcction=${1:-'backup'} | |
local url=${2:-'http://localhost:8080/pentaho/'} | |
local user=${3:-'admin'} | |
local password=${4:-'password'} | |
local file=${5:-'/tmp/'} | |
local logfile=${6:-'/tmp/'} | |
local charset=${7:-'UTF-8'} | |
local withManifest=${8:-true} | |
local nameFile=${9:-''} | |
local direction=${11:-''} | |
cd ${direction} | |
# ./import-export.sh --backup --url=http://localhost:8080/pentaho --username=admin --password=password --file-path=/home/Downloads/backup.zip --logfile=/temp/logfile.log | |
cmd="time import-export.sh --${typeAcction} --url=${url} --username=${user} --password=${password} --file-path=${file}${nameFile}-$DATE.zip --logfile=${logfile}logfile.log --charset=${charset} --withManifest=${withManifest}" | |
_console "Executing: $cmd" | |
sleep 1 | |
eval $cmd | |
_status | |
} | |
function restore (){ | |
local typeAcction=${1:-'restore'} | |
local url=${2:-'http://localhost:8080/pentaho/'} | |
local user=${3:-'admin'} | |
local password=${4:-'password'} | |
local file=${5:-'/tmp/'} | |
local logfile=${6:-'/tmp/'} | |
local charset=${7:-'UTF-8'} | |
local withManifest=${8:-true} | |
local nameFile=${9:-''} | |
local overwrite=${10:-true} | |
local direction=${11:-''} | |
cd ${direction} | |
# ./import-export.sh --restore --url=http://localhost:8080/pentaho --username=admin --password=password --file-path=/home/Downloads/backup.zip --overwrite=true --logfile=/temp/logfile.log | |
cmd="time import-export.sh --${typeAcction} --url=${url} --username=${user} --password=${password} --file-path=${file}${nameFile}-$DATE.zip --logfile=${logfile}logfile.log --charset=${charset} --overwrite=${overwrite}" | |
_console "Executing: $cmd" | |
sleep 1 | |
eval $cmd | |
_status | |
} | |
function help(){ | |
_console "Usage: pentaho_backup system .sh <[options]>" | |
_console "Options:" | |
_console " typeAcction | t = restore or backup" | |
_console " url | l = pentaho url" | |
_console " user| u = pentaho user (admin)" | |
_console " password | p = password of pentaho user" | |
_console " file | f = path of backup or restore" | |
_console " logfile | log = log file" | |
_console " charset |c = charset system (UTf-8)" | |
_console " withManifest | w = include manifest" | |
_console " nameFile | n = file to backup or restore" | |
_console " direction | d = pentaho file directiron" | |
_console " overwrite | o = over write the solution" | |
exit 0 | |
} | |
## | |
# ::main:: | |
# | |
for i in `seq 1 $#`; do | |
eval OPTION="\$$i" | |
OPTARG=$(echo $OPTION | cut -d'=' -f2) | |
OPTION=$(echo $OPTION | cut -d'=' -f1) | |
case $OPTION in | |
--direction | -d ) PENTAHO_DIR=${OPTARG};; | |
--typeAcction | -t ) TYPEACCTION=${OPTARG};; | |
--url | -l ) URL=${OPTARG};; | |
--user | -u ) USER=${OPTARG};; | |
--pass | -p ) PASS=${OPTARG};; | |
--file | -f ) FILE=${OPTARG};; | |
--logfile | -log ) LOGFILE=${OPTARG};; | |
--charset | -c ) CHARSET=${OPTARG};; | |
--withManifest| -w ) WITHMANIFEST=${OPTARG};; | |
--nameFile | -n ) NAMEFILE=${OPTARG};; | |
--overwrite | -o ) OVERWRITE=${OPTARG};; | |
--help | -h ) help;; | |
esac | |
done | |
if [ "$TYPEACCTION" == "backup" ]; then | |
echo $TYPEACCTION | |
backup $TYPEACCTION $URL $USER $PASS $FILE $LOGFILE $CHARSET $WITHMANIFEST $NAMEFILE $PENTAHO_DIR | |
_console "Backup finished" | |
if [ "$RSYNC" == "true"]; then | |
rsync_mode $FILE $RSYNC | |
_console "rsync finished" | |
fi | |
else | |
restore $TYPEACCTION $URL $USER $PASS $FILE $LOGFILE $OVERWRITE | |
_console "Restore finished" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment