mirror of
https://github.com/erenfro/systemrescue-backup.git
synced 2024-12-22 08:11:07 -05:00
Added parser and module loader
This commit is contained in:
parent
3dd55283a2
commit
cd9f398eaa
3 changed files with 234 additions and 2 deletions
107
src/functions.sh
107
src/functions.sh
|
@ -4,13 +4,15 @@
|
||||||
### Default global configuration definitions
|
### Default global configuration definitions
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
|
declare -r systemrescue_version="0.0.1"
|
||||||
|
systemrescue_cd_version="11.02"
|
||||||
|
backup_engine="resticprofile"
|
||||||
restic_version="0.17.0"
|
restic_version="0.17.0"
|
||||||
resticprofile_version="0.28.0"
|
resticprofile_version="0.28.0"
|
||||||
systemrescuecd_version="11.02"
|
|
||||||
backup_engine="resticprofile"
|
|
||||||
|
|
||||||
scriptPath="$(dirname "$(readlink -f "$0")")"
|
scriptPath="$(dirname "$(readlink -f "$0")")"
|
||||||
configPath="$(readlink -f "${scriptPath}/../config")"
|
configPath="$(readlink -f "${scriptPath}/../config")"
|
||||||
|
debug=false
|
||||||
|
|
||||||
if [[ ! -d "${configPath}" ]]; then
|
if [[ ! -d "${configPath}" ]]; then
|
||||||
# Start searching for common configuration paths
|
# Start searching for common configuration paths
|
||||||
|
@ -41,7 +43,29 @@ is_bin_in_path() {
|
||||||
builtin type -P "$1" &>/dev/null
|
builtin type -P "$1" &>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echoreg() {
|
||||||
|
if [[ "$1" == "-d" ]]; then
|
||||||
|
shift
|
||||||
|
if $debug; then
|
||||||
|
echo "$*" 1>&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$*" 1>&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
echoerr() {
|
echoerr() {
|
||||||
|
if [[ "$1" == "-d" ]]; then
|
||||||
|
shift
|
||||||
|
if $debug; then
|
||||||
|
echo "$*" 1>&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$*" 1>&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echodebug() {
|
||||||
echo "$*" 1>&2
|
echo "$*" 1>&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +77,85 @@ exit_fail() {
|
||||||
exit "$rc"
|
exit "$rc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run-parts() {
|
||||||
|
if [[ $# -lt 1 ]]; then
|
||||||
|
return 1
|
||||||
|
elif [[ ! -d "$1" ]]; then
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
local script
|
||||||
|
|
||||||
|
for script in "${1%/}"/*; do
|
||||||
|
case $script in
|
||||||
|
*~ | *.bak | */#*# | *.swp)
|
||||||
|
: ;; # Ignore backup/editor files
|
||||||
|
*.new | *.rpmsave | *.rpmorig | *.rpmnew)
|
||||||
|
: ;; # Ignore package management files
|
||||||
|
*)
|
||||||
|
if [[ -x "$script" ]]; then
|
||||||
|
if ! "$script"; then
|
||||||
|
echoerr "$script failed"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
load-parts() {
|
||||||
|
if [[ $# -lt 1 ]]; then
|
||||||
|
echoerr -d "load-parts parameters are invalid"
|
||||||
|
return 1
|
||||||
|
elif [[ ! -d "$1" ]]; then
|
||||||
|
echoerr -d "load-parts missing directory '$1'"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
local script
|
||||||
|
|
||||||
|
for script in "${1%/}"/*; do
|
||||||
|
case $script in
|
||||||
|
*~ | *.bak | */#*# | *.swp)
|
||||||
|
: ;; # Ignore backup/editor files
|
||||||
|
*.new | *.rpmsave | *.rpmorig | *.rpmnew)
|
||||||
|
: ;; # Ignore package management files
|
||||||
|
*)
|
||||||
|
if [[ -r "$script" ]]; then
|
||||||
|
set -e
|
||||||
|
echoreg -d "Loading script: $script"
|
||||||
|
source "$script"
|
||||||
|
set +e
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
load_module() {
|
||||||
|
local module="$1"
|
||||||
|
local submod="$2"
|
||||||
|
|
||||||
|
if [[ -z "$module" ]]; then
|
||||||
|
echoerr -d "load_module missing module"
|
||||||
|
return 1
|
||||||
|
elif [[ -z "$submod" ]]; then
|
||||||
|
echoerr -d "load_module missing submodule"
|
||||||
|
return 2
|
||||||
|
else
|
||||||
|
if [[ ! -d "${scriptPath}/${module}" ]]; then
|
||||||
|
echoerr -d "load_module missing module directory '${scriptPath}/${module}'"
|
||||||
|
return 3
|
||||||
|
elif [[ ! -d "${scriptPath}/${module}/${submod}" ]]; then
|
||||||
|
echoerr -d "load_module missing submodule directory '${scriptPath}/${submod}'"
|
||||||
|
return 4
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
load-parts "${scriptPath}/${module}/${submod}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
### BACKUP and RESTORE FUNCTIONS
|
### BACKUP and RESTORE FUNCTIONS
|
||||||
|
|
0
src/recovery/init/100_init
Normal file
0
src/recovery/init/100_init
Normal file
129
src/srb
129
src/srb
|
@ -10,3 +10,132 @@ else
|
||||||
exit 255
|
exit 255
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
showHelp() {
|
||||||
|
local section="$1"
|
||||||
|
|
||||||
|
echo "No help yet"
|
||||||
|
echo "Usage: $0 [global-options] <command> [options]"
|
||||||
|
echo
|
||||||
|
echo "Commands:"
|
||||||
|
echo " backup Perform system backup"
|
||||||
|
echo " restore Perform system restore"
|
||||||
|
echo " recovery Update/Generate system recovery disc image"
|
||||||
|
echo
|
||||||
|
echo "Global Options:"
|
||||||
|
echo " --debug, -d Enable Debug Logging"
|
||||||
|
echo " --help, -h Show this help"
|
||||||
|
echo
|
||||||
|
echo "Options (per command):"
|
||||||
|
|
||||||
|
if [[ -z "$section" || "$section" == "backup" ]]; then
|
||||||
|
echo "backup:"
|
||||||
|
echo " --exclude <pattern> Exclude devices matching the pattern from backup or restore."
|
||||||
|
echo " --exclude-file <file> Exclude devices listed in the specified file from backup or restore."
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$section" || "$section" == "restore" ]]; then
|
||||||
|
echo "restore:"
|
||||||
|
echo " --exclude <pattern> Exclude devices matching the pattern from backup or restore."
|
||||||
|
echo " --exclude-file <file> Exclude devices listed in the specified file from backup or restore."
|
||||||
|
echo " --rename <old> <new> Rename a device during the restore process."
|
||||||
|
echo " --no-uuid Disable restoring of UUIDs during restore."
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$section" || "$section" == "recovery" ]]; then
|
||||||
|
echo "recovery:"
|
||||||
|
echo " --sysrecue-cd-version=ver System Rescue CD version to use: $systemrescue_cd_version"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Examples:"
|
||||||
|
echo " $0 backup --exclude /dev/sda1"
|
||||||
|
echo " $0 restore --rename /dev/sda /dev/sdb"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Main function to handle command-line arguments and invoke appropriate functions
|
||||||
|
main() {
|
||||||
|
local help=false
|
||||||
|
|
||||||
|
#if [[ "$1" == "--help" ]]; then
|
||||||
|
# showHelp
|
||||||
|
# exit 0
|
||||||
|
#fi
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
help=true
|
||||||
|
shift
|
||||||
|
#showHelp
|
||||||
|
#exit 0
|
||||||
|
;;
|
||||||
|
-d|--debug)
|
||||||
|
debug=true;
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
#--*|-*)
|
||||||
|
# echo "Unknown option $1"
|
||||||
|
# exit 1
|
||||||
|
# ;;
|
||||||
|
*)
|
||||||
|
POSITIONAL_ARGS+=("$1") # save positional arg
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
set -- "${POSITIONAL_ARGS[@]}" # restore positional args
|
||||||
|
|
||||||
|
if $help; then
|
||||||
|
showHelp "$1"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
version)
|
||||||
|
echo "SystemRescue Backup version v${systemrescue_version}"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
backup)
|
||||||
|
echo "SystemRescue Backup -- Backup Mode"
|
||||||
|
;;
|
||||||
|
restore)
|
||||||
|
echo "SystemRescue Backup -- Restore Mode"
|
||||||
|
;;
|
||||||
|
recovery)
|
||||||
|
shift
|
||||||
|
while [[ "$#" -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--sysrecue-cd-version=*)
|
||||||
|
systemrescue_cd_version="${1#*=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid option: $1"
|
||||||
|
echo "Use --help to display the help message."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "SystemRescue Backup -- Recovery CD"
|
||||||
|
echo "opt: $*"
|
||||||
|
if ! load_module recovery init; then
|
||||||
|
exit_fail 200 "FATAL: Failed to load recovery init module. ($?)"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid command: $1"
|
||||||
|
echo "Use --help to display the help message."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Call the main function with all arguments
|
||||||
|
main "$@"
|
||||||
|
|
Loading…
Reference in a new issue