start() {
local step=0
+ tput civis -- invisible
while [ "$step" -lt "${#CMDS[@]}" ]; do
${CMDS[$step]} & pid=$!
while ps -p $pid &>/dev/null; do
echo -ne "\\r[ ✔ ] ${STEPS[$step]}\\n"
step=$((step + 1))
done
+ tput cnorm -- normal
}
-#echo '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
+
spinner()
{
local pid=$!
#SFTP_OPTS="-i ${DEFAULT_SSH_KEY} -o PasswordAuthentication=no -oPort=${SSHport}"
}
-#>/dev/null 2>&1
-###############################
-# Backup listing
-###############################
-# Get Names Addresses and Ports in $HostsFile
-#declare -rx STEPS=(
-# 'download'
-# 'check'
-# 'backup'
-#)
-#IFS=$'\n'
run_ssh_cmd() {
local run="${1}"
warning "${run}"
fi
}
-#${SSH_STR} /system script environment get [find name=BackupPassword] value;
-#exit 0
+ # Examples:
+ # bin_pass="$(${SSH_STR} ':put [/system script environment get [find name=BackupPassword] value]')"
+ # bin_pass="$(${SSH_STR} ':put $BackupPassword')" # if BackupPassword is a global
+
backup_binary() {
local bin_name="${1}"
- local crypt="${2:-$DEFAULT_BIN_CRYPT}"
- local bin_pass="${3:-$DEFAULT_BINPWD}"
+ local bin_pass="${2:-$DEFAULT_BINPWD}"
+ local bin_crypt="${DEFAULT_BIN_CRYPT}"
+ local bin_tmp="Binary.backup"
local log_msg
local crypt_str
- local router_crypt="$(${SSH_STR} ':put $BackupEncrypt')"
- local router_bin_pass="$(${SSH_STR} ':put $BackupPassword')"
- if [ -n ${router_crypt} ]; then
- warning "TRUE"
- else
- warning "FALSE"
- fi
- #${SSH_STR} :put [/system script environment get [find name=BackupPassword] value];
- # Examples:
- # bin_pass="$(${SSH_STR} ':put [/system script environment get [find name=BackupPassword] value]')"
- # bin_pass="$(${SSH_STR} ':put $BackupPassword')" # if BackupPassword is a global
- if ${SSH_STR} /system/script environment find where name=BackupEncrypt && ${SSH_STR} /system/script environment find where name=BackupPassword; then
-
- #bin_pass=${SSH_STR} /system/script/environment/get ([ /system/script/environment find name='BackupPassword' ]->value);
- bin_pass=
- crypt_str="dont-encrypt=no password=${bin_pass}"
- warning "${crypt_str}"
+ if [ -n "$(${SSH_STR} ':put $BackupEncrypt')" ] && [ -n "$(${SSH_STR} ':put $BackupPassword')" ] ; then
+ crypt_str="dont-encrypt=no password=$(${SSH_STR} ':put $BackupPassword')"
else
- if [ -n ${crypt} ] && [ -n {passwd} ]; then
- crypt_str="dont-encrypt=no password=${passwd}"
+ if [ -n ${bin_crypt} ]; then
+ crypt_str="dont-encrypt=no password=${bin_pass}"
else
crypt_str="dont-encrypt=yes"
fi
+ fi
+
+ local BKPSTR="/system backup save name=${bin_tmp} ${crypt_str}"
+ local T_BKPCLN="/file remove [find name=${bin_tmp}]"
+
+ if ${SSH_STR} ${BKPSTR}; then
+ log_msg="Create binary backup ${bin_tmp} on ${RouterName} success."
+ log_success "${log_msg}"
+ log_msg="- Start download ${bin_tmp} file to ${BackupDir}..."
+ log_info "${log_msg}"
+ return 0
+ if ${SCP_STR}:/${bin_tmp} ${bin_name}; then
+ sleep 2
+ log_msg="- Binary Backup download complete!"
+ log_success "${log_msg}"
+ return 0
+ else
+ log_msg="- Error! Download binary backup on ${RoutrName} failed!"
+ log_error "${log_msg}"
+ fi
+ else
+ log_msg="- Error create binary backup ${bin_tmp} on ${RouterName}!"
+ log_error "${log_msg}"
fi
- # if [ -n $]; then
-# local BKPSTR="system backup save name=${bin_name} dont-encrypt=no password=$BKP_BINPWD"
-# T_BKPCLN="file remove [find name=$TGT_BKPNAME_BIN]"
+ log_msg="- Remove ${bin_tmp} file on ${RouterName}."
+ if [ -t 1 ] && $DEBUG_OUT; then
+ section "CLEANUP"
+ fi
+ log_info "${log_msg}"
+
+ if ${SSH_STR} ${T_BKPCLN}; then
+ log_msg="- Remove ${bin_tmp} file on ${RouterName} complete succesfully!"
+ log_success "${log_msg}"
+ else
+ log_msg="- Error Remove ${bin_tmp} file on ${RouterName}!"
+ log_error "${log_msg}"
+ fi
}
readarray -t lines < $HostsFile
-#declare -r STEPS=($lines)
-#declare -r MAX_STEPS=${#lines[@]}
-#declare -r BAR_SIZE="##########"
-#declare -r MAX_BAR_SIZE=${#BAR_SIZE}
for HR in "${lines[@]}"; do
-# perc=$(((HR + 1) * 100 / MAX_STEPS))
-# percBar=$((perc * MAX_BAR_SIZE / 100))
-# declare -rx CMDS=(
-# "${CMD_SSH} ${SSH_OPTS} ${SSHuser}@${SSHhost} export >$current_config"
-# 'sleep 10'
-# 'sleep 1'
-#)
while IFS=$' ' read -a HR ; do
-#|| [ -n "$HR" ]; do
[[ -z ${HR[0]} ]] && continue
DStamp=$(date '+%Y%m%d')
SSHhost=${HR[1]}
SSHport=${HR[2]}
SSHuser=${HR[3]}
-SSHpassword=${HR[4]}
+backup_pass=${HR[4]}
get_connections_str
-backup_binary "BinaryTest.backup"
+#backup_binary "BinaryTest.backup"
-exit 0
+#exit 0
#warning "SSH_STR = ${SSH_STR}"
#warning "SCP_STR = ${SCP_STR}"
#exit 0
precedent_config=${BaseDir}"Precedent-Config.rsc"
current_config=${TempDir}"Config.rsc"
diff_config=${TempDir}"Diff-Config.rsc"
-current_backup="Binary.backup"
+bin_tmp="Binary.backup"
log_msg="Set variables for ${RouterName} success!"
log_success "${log_msg}"
log_msg="- Copy configuration to ${BackupDir}/${save_config} and ${precedent_config} success."
log_success "${log_msg}"
- log_msg="Create ${current_backup} file on ${RouterName}..."
- log_info "${log_msg}"
-# if [ $? -eq 0 ]; then
- if ${SSH_STR} system backup save name=${current_backup}; then
- log_msg="Create binary backup ${current_backup} on ${RouterName} success."
- log_success "${log_msg}"
-
- log_msg="- Start download ${current_backup} file to ${BackupDir}..."
- log_info "${log_msg}"
-
-# if ${SFTP_STR}:$current_backup; then
- # ${CMD_SFTP} ${SFTP_OPTS} ${SSHuser}@${SSHhost}:$current_backup
- if ${SCP_STR}:/${current_backup} ${save_backup}; then
- sleep 2
- log_msg="- Binary Backup download complete!"
- log_success "${log_msg}"
- else
- log_msg="- Error! Save binary backup on ${RoutrName} failed!"
- log_error "${log_msg}"
- fi
- else
- log_msg="Error create binary backup ${current_backup} on ${RouterName}!"
- log_error "${log_msg}"
- fi
-
- log_msg="- Remove ${current_backup} file on ${RouterName}."
- if [ -t 1 ] && $DEBUG_OUT; then
- section "CLEANUP"
- fi
+ log_msg="Create ${bin_tmp} file on ${RouterName}..."
log_info "${log_msg}"
- if ${SSH_STR} /file remove ${current_backup}; then
- log_msg="- Remove ${current_backup} file on ${RouterName} complete succesfully!"
- log_success "${log_msg}"
- else
- log_msg="- Error Remove ${current_backup} file on ${RouterName}!"
- log_error "${log_msg}"
- fi
+ backup_binary ${bin_tmp} ${backup_pass}
+# if [ $? -eq 0 ]; then
cd "${BaseDir}"
# echo -ne "\\r[${BAR_SIZE:0:percBar}] $perc %"
#echo "[] $perc %"
done
-log_msg="All Done! Exit 0."
+
if [ -t 1 ] && $DEBUG_OUT; then
section " DONE "
fi
+log_msg="All Done! Exit 0."
log_success "${log_msg}"
exit 0