hook functions
This commit is contained in:
parent
2bf4d0dd0f
commit
0491598c1f
|
@ -13,9 +13,9 @@ set -u
|
||||||
# to exit with a non-zero status, or zero if all commands exit successfully.
|
# to exit with a non-zero status, or zero if all commands exit successfully.
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
local_tasks() {
|
source "${LIBDIR}/utilities.sh"
|
||||||
log_error "The 'local_tasks' function hasn't been customized"
|
source "${LIBDIR}/dump.sh"
|
||||||
}
|
|
||||||
# Called from main, it is wrapping the local_tasks function defined in the real script
|
# Called from main, it is wrapping the local_tasks function defined in the real script
|
||||||
local_tasks_wrapper() {
|
local_tasks_wrapper() {
|
||||||
log "START LOCAL_TASKS"
|
log "START LOCAL_TASKS"
|
||||||
|
@ -23,17 +23,19 @@ local_tasks_wrapper() {
|
||||||
# Remove old log directories
|
# Remove old log directories
|
||||||
find "${LOCAL_BACKUP_DIR}/" -type d -name "${PROGNAME}.errors-*" -ctime +30 -delete
|
find "${LOCAL_BACKUP_DIR}/" -type d -name "${PROGNAME}.errors-*" -ctime +30 -delete
|
||||||
|
|
||||||
# This function must be defined in the calling script
|
local_tasks_type="$(type -t local_tasks)"
|
||||||
local_tasks
|
if [ "${local_tasks_type}" = "function" ]; then
|
||||||
|
local_tasks
|
||||||
|
else
|
||||||
|
log_error "There is no 'local_tasks' function to execute"
|
||||||
|
fi
|
||||||
|
|
||||||
# TODO: check if this is still needed
|
# TODO: check if this is still needed
|
||||||
# print_error_files_content
|
# print_error_files_content
|
||||||
|
|
||||||
log "STOP LOCAL_TASKS"
|
log "STOP LOCAL_TASKS"
|
||||||
}
|
}
|
||||||
sync_tasks() {
|
|
||||||
log_error "The 'sync_tasks' function hasn't been customized"
|
|
||||||
}
|
|
||||||
# Called from main, it is wrapping the sync_tasks function defined in the real script
|
# Called from main, it is wrapping the sync_tasks function defined in the real script
|
||||||
sync_tasks_wrapper() {
|
sync_tasks_wrapper() {
|
||||||
declare -a SERVERS # Indexed array for server/port values
|
declare -a SERVERS # Indexed array for server/port values
|
||||||
|
@ -121,8 +123,12 @@ sync_tasks_wrapper() {
|
||||||
)
|
)
|
||||||
readonly rsync_default_excludes
|
readonly rsync_default_excludes
|
||||||
|
|
||||||
# This function must be defined in the calling script
|
sync_tasks_type="$(type -t sync_tasks)"
|
||||||
sync_tasks
|
if [ "${sync_tasks_type}" = "function" ]; then
|
||||||
|
sync_tasks
|
||||||
|
else
|
||||||
|
log_error "There is no 'sync_tasks' function to execute"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
sync() {
|
sync() {
|
||||||
|
@ -171,7 +177,7 @@ sync() {
|
||||||
rsync_server=$(echo "${server}" | cut -d':' -f1)
|
rsync_server=$(echo "${server}" | cut -d':' -f1)
|
||||||
rsync_port=$(echo "${server}" | cut -d':' -f2)
|
rsync_port=$(echo "${server}" | cut -d':' -f2)
|
||||||
|
|
||||||
log "START SYNC_TASKS - ${sync_name} : server=${server}"
|
log "START SYNC_TASKS - \"${sync_name}\" : server=${server}"
|
||||||
|
|
||||||
# Rsync complete log file for the current run
|
# Rsync complete log file for the current run
|
||||||
RSYNC_LOGFILE="/var/log/${PROGNAME}.${sync_name}.rsync.log"
|
RSYNC_LOGFILE="/var/log/${PROGNAME}.${sync_name}.rsync.log"
|
||||||
|
@ -261,7 +267,7 @@ sync() {
|
||||||
rsync_main_args+=("root@${rsync_server}:${REMOTE_BACKUP_DIR}/")
|
rsync_main_args+=("root@${rsync_server}:${REMOTE_BACKUP_DIR}/")
|
||||||
|
|
||||||
# … log it
|
# … log it
|
||||||
log "SYNC_TASKS - ${sync_name} Rsync main command : ${rsync_bin} ${rsync_main_args[*]}"
|
log "SYNC_TASKS - \"${sync_name}\" Rsync main command : ${rsync_bin} ${rsync_main_args[*]}"
|
||||||
|
|
||||||
# … execute it
|
# … execute it
|
||||||
${rsync_bin} "${rsync_main_args[@]}"
|
${rsync_bin} "${rsync_main_args[@]}"
|
||||||
|
@ -315,7 +321,7 @@ sync() {
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
# Default return-code (0 == succes)
|
# Default return-code (0 == succes)
|
||||||
declare -i GLOBAL_RC=0
|
GLOBAL_RC=0
|
||||||
|
|
||||||
# Possible error codes
|
# Possible error codes
|
||||||
readonly E_NOSRVAVAIL=21 # No server is available
|
readonly E_NOSRVAVAIL=21 # No server is available
|
||||||
|
@ -376,6 +382,12 @@ setup() {
|
||||||
# Enable/disable mtree (default: enabled)
|
# Enable/disable mtree (default: enabled)
|
||||||
: "${MTREE_ENABLED:=1}"
|
: "${MTREE_ENABLED:=1}"
|
||||||
|
|
||||||
|
# If "setup_custom" exists and is a function, let's call it
|
||||||
|
setup_custom_type="$(type -t setup_custom)"
|
||||||
|
if [ "${setup_custom_type}" = "function" ]; then
|
||||||
|
setup_custom
|
||||||
|
fi
|
||||||
|
|
||||||
## Force umask
|
## Force umask
|
||||||
umask 077
|
umask 077
|
||||||
|
|
||||||
|
@ -385,6 +397,7 @@ setup() {
|
||||||
trap "clean_temp_files" EXIT
|
trap "clean_temp_files" EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
# Start timer
|
# Start timer
|
||||||
START_EPOCH=$(/bin/date +%s)
|
START_EPOCH=$(/bin/date +%s)
|
||||||
|
|
|
@ -186,12 +186,12 @@ local_tasks() {
|
||||||
########## Network ################
|
########## Network ################
|
||||||
|
|
||||||
# Dump network routes with mtr and traceroute (warning: could be long with aggressive firewalls)
|
# Dump network routes with mtr and traceroute (warning: could be long with aggressive firewalls)
|
||||||
### dump_traceroute
|
dump_traceroute
|
||||||
|
|
||||||
########## Server state ###########
|
########## Server state ###########
|
||||||
|
|
||||||
# Run dump-server-state to extract system information
|
# Run dump-server-state to extract system information
|
||||||
### dump_server_state
|
dump_server_state
|
||||||
|
|
||||||
# Dump file access control lists
|
# Dump file access control lists
|
||||||
### dump_facl
|
### dump_facl
|
||||||
|
@ -235,24 +235,31 @@ local_tasks() {
|
||||||
### log "LOCAL_TASKS - stop ${dump_file}"
|
### log "LOCAL_TASKS - stop ${dump_file}"
|
||||||
### }
|
### }
|
||||||
|
|
||||||
########## Libraries ##################################################
|
|
||||||
|
|
||||||
source ./lib/utilities.sh
|
|
||||||
source ./lib/dump.sh
|
|
||||||
source ./lib/main.sh
|
|
||||||
|
|
||||||
########## Optional configuration #####################################
|
########## Optional configuration #####################################
|
||||||
|
|
||||||
# If you set a value (like "linux", "openbsd"…) it will be used,
|
setup_custom() {
|
||||||
# Default: uname(1) in lowercase.
|
# If you set a value (like "linux", "openbsd"…) it will be used,
|
||||||
### SYSTEM="linux"
|
# Default: uname(1) in lowercase.
|
||||||
|
### SYSTEM="linux"
|
||||||
|
|
||||||
# If you set a value it will be used,
|
# If you set a value it will be used,
|
||||||
# Default: hostname(1).
|
# Default: hostname(1).
|
||||||
### HOSTNAME="example-host"
|
### HOSTNAME="example-host"
|
||||||
|
|
||||||
# Email subect for notifications
|
# Email subect for notifications
|
||||||
### MAIL_SUBJECT="[info] EvoBackup - Client ${HOSTNAME}"}"
|
### MAIL_SUBJECT="[info] EvoBackup - Client ${HOSTNAME}"
|
||||||
|
|
||||||
|
# No-op in case nothing is executed
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
########## Libraries ##################################################
|
||||||
|
|
||||||
|
# Change this to wherever you install the libraries
|
||||||
|
LIBDIR="./lib"
|
||||||
|
|
||||||
|
source "${LIBDIR}/main.sh"
|
||||||
|
|
||||||
|
########## Let's go! ##################################################
|
||||||
|
|
||||||
# Call main function
|
|
||||||
main
|
main
|
Loading…
Reference in a new issue