#!/bin/bash set -o nounset declare INC_PATH="./inc" declare CONF_PATH="." declare l_res export arg_source_machine export cfg_source_possible_addresses export cfg_rsh_command export cfg_rsync_copy_opts export cfg_rsync_reporting_opts export cfg_rsync_exclude_basepath export cfg_rsync_source_paths export cfg_rsync_dest_basepath export runtime_source_address export log_type log_message source "$INC_PATH/functions.sh" parse_args "$@" l_res=$? if [ $l_res -ne 0 ] then print_usage exit 1 fi log_type=LOG_ERR log_message="Curent environnement is not usable, aborting" run_or_die 2 check_env log_type=LOG_ERR log_message="Unable to load conf for '$arg_source_machine'" run_or_die 3 load_conf "$CONF_PATH/bkp.ini" "$arg_source_machine" log LOG_NOTICE main "Starting backup of '$arg_source_machine'" log_type=LOG_ERR log_message="Unable to reach '$arg_source_machine'" run_or_die 4 find_source_address "$cfg_source_possible_addresses" log LOG_NOTICE main "Source machine '$arg_source_machine' will be accessed via '${runtime_source_address:-localhost}'" if [ -z "$runtime_source_address" ] then runtime_rsh_command="" runtime_rsync_src="" else runtime_rsh_command="$cfg_rsh_command" runtime_rsync_src="$runtime_source_address:" fi if [ "isset" == "${cfg_pre_backup_remote_script_path:+isset}" ] then log_type=LOG_ERR log_message="Unable to execute pre_backup_script on '$arg_source_machine'" eval "echo $runtime_rsh_command $runtime_source_address $cfg_pre_backup_remote_script_path" run_or_die 5 eval "$runtime_rsh_command $runtime_source_address $cfg_pre_backup_remote_script_path" fi runtime_rsync_dest_basepath="$cfg_rsync_dest_basepath/$arg_source_machine" runtime_rsync_opts="$cfg_rsync_copy_opts $cfg_rsync_reporting_opts" l_oldifs=$IFS IFS=", " for runtime_rsync_source_path in $cfg_rsync_source_paths do runtime_rsync_dest_lastpath="$(basename $runtime_rsync_source_path)" [ "$runtime_rsync_dest_lastpath" == "/" ] && runtime_rsync_dest_lastpath="rootfs" log LOG_NOTICE main "Starting backup from ${runtime_rsync_src}${runtime_rsync_source_path} to $runtime_rsync_dest_basepath/$runtime_rsync_dest_lastpath" runtime_rsync_exclude_opts="" if [ -n "$cfg_rsync_exclude_basepath" ] then runtime_rsync_exclude_file="$cfg_rsync_exclude_basepath/$arg_source_machine/exclude-$runtime_rsync_dest_lastpath.lst" if [ -r "$runtime_rsync_exclude_file" ] then runtime_rsync_exclude_opts="--exclude-from=$runtime_rsync_exclude_file --delete-excluded" else log LOG_NOTICE main "No exclude file : '$runtime_rsync_exclude_file'" fi fi rsync -e "$runtime_rsh_command" $runtime_rsync_opts $runtime_rsync_exclude_opts "${runtime_rsync_src}${runtime_rsync_source_path}/" "$runtime_rsync_dest_basepath/$runtime_rsync_dest_lastpath/" | tee "$runtime_rsync_dest_basepath/$runtime_rsync_dest_lastpath.log" l_res=$? if [ $l_res -ne 0 ] then log LOG_WARN rsync "rsync has returned a non-0 code : '$l_res'" fi log LOG_NOTICE main "Ending backup" sync done IFS="$l_oldifs" if [ "isset" == "${cfg_post_backup_remote_script_path:+isset}" ] then log_type=LOG_ERR log_message="Unable to execute post_backup_script on '$arg_source_machine'" run_or_die 6 eval "$runtime_rsh_command $runtime_source_address $cfg_post_backup_remote_script_path" fi