mirror of
https://github.com/erenfro/systemrescue-backup.git
synced 2024-12-22 08:11:07 -05:00
Checkpoint update
This commit is contained in:
parent
961f42f1fe
commit
3a2d0fbb4e
8 changed files with 210 additions and 21 deletions
|
@ -6,34 +6,26 @@
|
||||||
|
|
||||||
declare -r systemrescue_version="0.0.1"
|
declare -r systemrescue_version="0.0.1"
|
||||||
systemrescue_cd_version="11.02"
|
systemrescue_cd_version="11.02"
|
||||||
|
systemrescue_data_dir="/var/backups/systemrescue-backup"
|
||||||
|
systemrescue_cache_dir="/var/cache/systemrescue-backup"
|
||||||
|
systemrescue_temp_dir="/tmp/systemrescue-backup"
|
||||||
backup_engine="resticprofile"
|
backup_engine="resticprofile"
|
||||||
restic_version="0.17.0"
|
|
||||||
resticprofile_version="0.28.0"
|
|
||||||
|
|
||||||
scriptPath="$(dirname "$(readlink -f "$0")")"
|
scriptPath="$(dirname "$(readlink -f "$0")")"
|
||||||
configPath="$(readlink -f "${scriptPath}/../config")"
|
configPath="$(readlink -f "${scriptPath}/../config")"
|
||||||
debug=false
|
debug=false
|
||||||
|
|
||||||
if [[ ! -d "${configPath}" ]]; then
|
if [[ ! -r "${configPath}/srb.cfg" ]]; then
|
||||||
# Start searching for common configuration paths
|
# Start searching for common configuration paths
|
||||||
if [[ -r "$HOME/.config/systemrescue-backup/srb.cfg" ]]; then
|
if [[ -r "$HOME/.config/systemrescue-backup/srb.cfg" ]]; then
|
||||||
configPath="$HOME/.config/systemrescue-backup"
|
configPath="$HOME/.config/systemrescue-backup"
|
||||||
elif [[ -r "/etc/systemrescue-backup/srb.cfg" ]]; then
|
elif [[ -r "/etc/systemrescue-backup/srb.cfg" ]]; then
|
||||||
configPath="/etc/systemrescue-backup"
|
configPath="/etc/systemrescue-backup"
|
||||||
else
|
else
|
||||||
echoerr "No configuration file path found. Defaults will be used." 1>&2
|
echoerr "Warning: No configuration file path found. Defaults will be used."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f "${configPath}/srb.cfg" ]]; then
|
|
||||||
# Fail on any issues loading configuration
|
|
||||||
trap "echo \"ERROR: Configuration failed to load without error\"" ERR
|
|
||||||
set -e
|
|
||||||
source "${configPath}/srb.cfg"
|
|
||||||
set +e
|
|
||||||
trap - ERR
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
### Utility & Common Functions
|
### Utility & Common Functions
|
||||||
|
@ -77,6 +69,18 @@ exit_fail() {
|
||||||
exit "$rc"
|
exit "$rc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_config() {
|
||||||
|
if [[ -f "${configPath}/srb.cfg" ]]; then
|
||||||
|
# Fail on any issues loading configuration
|
||||||
|
trap "echo \"ERROR: Configuration failed to load without error\"" ERR
|
||||||
|
set -e
|
||||||
|
source "${configPath}/srb.cfg"
|
||||||
|
set +e
|
||||||
|
trap - ERR
|
||||||
|
echoreg -d "Loaded configuration file: ${configPath}/srb.cfg"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
run-parts() {
|
run-parts() {
|
||||||
if [[ $# -lt 1 ]]; then
|
if [[ $# -lt 1 ]]; then
|
||||||
return 1
|
return 1
|
||||||
|
@ -159,12 +163,34 @@ load_module() {
|
||||||
echoreg -d "Loaded Modules in: ${scriptPath}/${module}/${submod}/"
|
echoreg -d "Loaded Modules in: ${scriptPath}/${module}/${submod}/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_modules() {
|
||||||
|
local module="$1"
|
||||||
|
local submodules=("init" "prepare" "execute" "finalize")
|
||||||
|
local order mod
|
||||||
|
|
||||||
|
for load in "${submodules[@]}"; do
|
||||||
|
if [[ "$load" == "finalize" ]]; then
|
||||||
|
order=("$backup_engine" "$module")
|
||||||
|
else
|
||||||
|
order=("$module" "$backup_engine")
|
||||||
|
fi
|
||||||
|
|
||||||
|
for mod in "${order[@]}"; do
|
||||||
|
if ! load_module "$mod" "$load"; then
|
||||||
|
exit_fail 200 "FATAL: Failed to load $module $load module. ($?)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$load" == "init" ]]; then
|
||||||
|
load_config
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
### BACKUP and RESTORE FUNCTIONS
|
### BACKUP and RESTORE FUNCTIONS
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
#dumpPartitions() {
|
|
||||||
backup_partitions() {
|
backup_partitions() {
|
||||||
local rootPart rootDisk
|
local rootPart rootDisk
|
||||||
|
|
||||||
|
@ -177,7 +203,6 @@ backup_partitions() {
|
||||||
mount | grep "$rootPart" > "${restoreDir}/mounts.dump"
|
mount | grep "$rootPart" > "${restoreDir}/mounts.dump"
|
||||||
}
|
}
|
||||||
|
|
||||||
#restorePartitions() {
|
|
||||||
restore_partitions() {
|
restore_partitions() {
|
||||||
local rootPart rootDisk
|
local rootPart rootDisk
|
||||||
|
|
||||||
|
@ -203,7 +228,6 @@ restore_partitions() {
|
||||||
echo "Partition table and UUID information have been restored."
|
echo "Partition table and UUID information have been restored."
|
||||||
}
|
}
|
||||||
|
|
||||||
#restoreBtrFSSubvolumes() {
|
|
||||||
restore_btrfs_subvolumes() {
|
restore_btrfs_subvolumes() {
|
||||||
local rootBase subvolID subvolPath
|
local rootBase subvolID subvolPath
|
||||||
|
|
||||||
|
@ -219,7 +243,6 @@ restore_btrfs_subvolumes() {
|
||||||
done < "${restoreDir}/btrfs.dump"
|
done < "${restoreDir}/btrfs.dump"
|
||||||
}
|
}
|
||||||
|
|
||||||
#restoreBtrFSMounts() {
|
|
||||||
restore_btfs_mounts() {
|
restore_btfs_mounts() {
|
||||||
local rootBase mountSource mountDest
|
local rootBase mountSource mountDest
|
||||||
|
|
||||||
|
|
8
src/recovery/finalize/100_cleanup
Normal file
8
src/recovery/finalize/100_cleanup
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
umount "${systemrescue_data_dir}/build/build_into_srm/var/backups/systemrescue-backup/backupdb" &>/dev/null
|
||||||
|
umount "${systemrescue_data_dir}/build/build_into_srm/etc/resticprofile" &>/dev/null
|
||||||
|
|
||||||
|
if [[ -d "${systemrescue_data_dir}/build/build_into_srm" ]]; then
|
||||||
|
rm -rf "${systemrescue_data_dir}/build/build_into_srm" || exit 1
|
||||||
|
fi
|
|
@ -1 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
echoreg -d "Loaded Recovery Initialization"
|
echoreg -d "Loaded Recovery Initialization"
|
||||||
|
|
||||||
|
# Setup Defaults according to what's been develeoped and tested
|
||||||
|
systemrescue_cd_version="11.02"
|
||||||
|
systemrescue_cd_iso_url="https://sourceforge.net/projects/systemrescuecd/files/sysresccd-x86/{SYSRESCUECD_VERSION}/systemrescue-{SYSRESCUECD_VERSION}-amd64.iso/download"
|
||||||
|
systemrescue_cd_customize_url=""https://gitlab.com/systemrescue/systemrescue-sources/-/raw/main/airootfs/usr/share/sysrescue/bin/sysrescue-customize?inline=false""
|
||||||
|
|
21
src/recovery/prepare/100_prepare
Normal file
21
src/recovery/prepare/100_prepare
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mkdir -p "$systemrescue_data_dir" || return 1
|
||||||
|
mkdir -p "$systemrescue_temp_dir" || return 1
|
||||||
|
mkdir -p "$systemrescue_cache_dir" || return 1
|
||||||
|
|
||||||
|
mkdir -p "${systemrescue_data_dir}/build/build_into_srm/var/backups/systemrescue-backup/backupdb" || return 1
|
||||||
|
#mount --bind "${systemrescue_data_dir}/backupdb" "${systemrescue_data_dir}/build/build_into_srm/var/backups/systemrescue-backup/backupdb" || exit 1
|
||||||
|
if ! mount --bind "${systemrescue_data_dir}/backupdb" "${systemrescue_data_dir}/build/build_into_srm/var/backups/systemrescue-backup/backupdb"; then
|
||||||
|
if ! cp -a "${systemrescue_data_dir}/backupdb/" "${systemrescue_data_dir}/build/build_into_srm/var/backups/systemrescue-backup/backupdb/"; then
|
||||||
|
exit_fail 205 "FATAL: Failed to copy backupdb files over to recovery image build"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# mkdir -p "${systemrescue_data_dir}/build/build_into_srm/etc/resticprofile"
|
||||||
|
# if ! mount --bind "${resticprofile_config_dir}" "${systemrescue_data_dir}/build/build_into_srm/etc/resticprofile"; then
|
||||||
|
# if ! cp -a "${resticprofile_config_dir}" "${systemrescue_data_dir}/build/build_into_srm/etc/resticprofile"; then
|
||||||
|
# exit_fail 205 "FATAL: Failed to copy resticprofile config files over to recovery image build"
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
#mount --bind "/etc/resticprofile" "${systemrescue_data_dir}/build/build_into_srm/etc/resticprofile" || return 1
|
5
src/resticprofile/finalize/100_cleanup
Normal file
5
src/resticprofile/finalize/100_cleanup
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ -d "${systemrescue_data_dir}/build/build_into_srm/usr/local/bin" ]]; then
|
||||||
|
rm -rf "${systemrescue_data_dir}/build/build_into_srm/usr/local/bin" || return 1
|
||||||
|
fi
|
58
src/resticprofile/init/001_default
Normal file
58
src/resticprofile/init/001_default
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echoreg -d "Loaded resticprofile Recovery Module Initialization"
|
||||||
|
|
||||||
|
# Setup Defaults according to what's been develeoped and tested
|
||||||
|
restic_version="0.17.0"
|
||||||
|
resticprofile_version="0.28.0"
|
||||||
|
resticprofile_config_dir="/etc/resticprofile"
|
||||||
|
|
||||||
|
resticprofile_init_find_config() {
|
||||||
|
local -a checkpaths
|
||||||
|
local path
|
||||||
|
local os
|
||||||
|
|
||||||
|
os=$(uname -s)
|
||||||
|
|
||||||
|
case "$os" in
|
||||||
|
Darwin)
|
||||||
|
checkpaths+=(
|
||||||
|
"$HOME/Library/Preferences/resticprofile"
|
||||||
|
"/Library/Preferences/resticprofile"
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
CYGWIN*|MINGW*|MSYS_NT*)
|
||||||
|
exit_fail 255 "FATAL: Windows is not supported";;
|
||||||
|
*)
|
||||||
|
checkpaths+=(
|
||||||
|
"$HOME/.config/resticprofile"
|
||||||
|
"/etc/xdg/resticprofile"
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
checkpaths+=(
|
||||||
|
"/usr/local/etc/restic/"
|
||||||
|
"/usr/local/etc/resticprofile"
|
||||||
|
"/etc/restic"
|
||||||
|
"/etc/resticprofile"
|
||||||
|
"/etc/restic"
|
||||||
|
"/opt/local/etc/restic"
|
||||||
|
"/opt/local/etc/resticprofile"
|
||||||
|
)
|
||||||
|
|
||||||
|
for path in "${checkpaths[@]}"; do
|
||||||
|
if compgen -G "${path}/profiles.*" > /dev/null; then
|
||||||
|
resticprofile_config_dir="$path"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If it still doesn't exist, we got issues
|
||||||
|
if ! compgen -G "${resticprofile_config_dir}/profiles.*" > /dev/null; then
|
||||||
|
exit_fail 210 "Failed to find resticprofile configuration directory"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echoreg "Found resticprofile configuration in '$resticprofile_config_dir'"
|
||||||
|
}
|
||||||
|
|
||||||
|
resticprofile_init_find_config
|
50
src/resticprofile/prepare/100_prepare
Normal file
50
src/resticprofile/prepare/100_prepare
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echoreg "Using SystemRescueCD Version: $systemrescue_cd_version"
|
||||||
|
echoreg "Using Restic Version: $restic_version"
|
||||||
|
echoreg "Using ResticProfile Version: $resticprofile_version"
|
||||||
|
|
||||||
|
mkdir -p "${systemrescue_cache_dir}" || return 1
|
||||||
|
mkdir -p "${systemrescue_data_dir}/build/build_into_srm/usr/local/bin" || return 1
|
||||||
|
mkdir -p "${systemrescue_temp_dir}/restic-install" || return 1
|
||||||
|
|
||||||
|
if [[ ! -f "${systemrescue_cache_dir}/restic_${restic_version}_linux_amd64.bz2" ]]; then
|
||||||
|
curl -C - -Lso "${systemrescue_cache_dir}/restic_${restic_version}_linux_amd64.bz2" "https://github.com/restic/restic/releases/download/v${restic_version}/restic_${restic_version}_linux_amd64.bz2" || return 1
|
||||||
|
fi
|
||||||
|
bunzip2 -k "${systemrescue_cache_dir}/restic_${restic_version}_linux_amd64.bz2" || return 1
|
||||||
|
chmod 755 "${systemrescue_cache_dir}/restic_${restic_version}_linux_amd64"
|
||||||
|
chown root:root "${systemrescue_cache_dir}/restic_${restic_version}_linux_amd64"
|
||||||
|
mv "${systemrescue_cache_dir}/restic_${restic_version}_linux_amd64" "${systemrescue_data_dir}/build/build_into_srm/usr/local/bin/restic" || return 1
|
||||||
|
|
||||||
|
if [[ ! -f "${systemrescue_cache_dir}/resticprofile_${resticprofile_version}_linux_amd64.tar.gz" ]]; then
|
||||||
|
curl -C - -Lso "${systemrescue_cache_dir}/resticprofile_${resticprofile_version}_linux_amd64.tar.gz" "https://github.com/creativeprojects/resticprofile/releases/download/v${resticprofile_version}/resticprofile_${resticprofile_version}_linux_amd64.tar.gz" || return 1
|
||||||
|
fi
|
||||||
|
tar -xzf "${systemrescue_cache_dir}/resticprofile_${resticprofile_version}_linux_amd64.tar.gz" -C "${systemrescue_temp_dir}/restic-install" || return 1
|
||||||
|
chmod 755 "${systemrescue_temp_dir}/restic-install/resticprofile"
|
||||||
|
chown root:root "${systemrescue_temp_dir}/restic-install/resticprofile"
|
||||||
|
mv "${systemrescue_temp_dir}/restic-install/resticprofile" "${systemrescue_data_dir}/build/build_into_srm/usr/local/bin/resticprofile" || return 1
|
||||||
|
rm -rf "${systemrescue_temp_dir}/restic-install" || return 1
|
||||||
|
|
||||||
|
mkdir -p "${systemrescue_data_dir}/build/build_into_srm/etc/resticprofile"
|
||||||
|
if ! mount --bind "${resticprofile_config_dir}" "${systemrescue_data_dir}/build/build_into_srm/etc/resticprofile"; then
|
||||||
|
if ! cp -a "${resticprofile_config_dir}" "${systemrescue_data_dir}/build/build_into_srm/etc/"; then
|
||||||
|
exit_fail 205 "FATAL: Failed to copy resticprofile config files over to recovery image build"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $debug; then
|
||||||
|
echo "==========================================================================="
|
||||||
|
echo "Cache Dir: $systemrescue_cache_dir"
|
||||||
|
ls -lR "$systemrescue_cache_dir"
|
||||||
|
echo "====="
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "Data Dir: $systemrescue_data_dir"
|
||||||
|
ls -lR "$systemrescue_data_dir"
|
||||||
|
echo "====="
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "Temp Dir: $systemrescue_temp_dir"
|
||||||
|
ls -lR "$systemrescue_temp_dir"
|
||||||
|
echo "==========================================================================="
|
||||||
|
fi
|
25
src/srb
25
src/srb
|
@ -127,7 +127,12 @@ main() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--cd-version=*)
|
--cd-version=*)
|
||||||
systemrescue_cd_version="${1#*=}"
|
systemrescue_cd_version="${1#*=}"
|
||||||
echoreg -d "SystemRescueCD Version arg = $systemrescue_cd_version"
|
echoreg -d "Args: SystemRescueCD Version = $systemrescue_cd_version"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--cd-url=*)
|
||||||
|
systemrescue_cd_url="${1#*=}"
|
||||||
|
echoreg -d "Args: SystemRescueCD Download url = $systemrescue_cd_url"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -140,9 +145,21 @@ main() {
|
||||||
|
|
||||||
echo "SystemRescue Backup -- Recovery CD"
|
echo "SystemRescue Backup -- Recovery CD"
|
||||||
echoreg -d "opt: $*"
|
echoreg -d "opt: $*"
|
||||||
if ! load_module recovery init; then
|
|
||||||
exit_fail 200 "FATAL: Failed to load recovery init module. ($?)"
|
run_modules recovery
|
||||||
fi
|
|
||||||
|
# if ! load_module recovery init; then
|
||||||
|
# exit_fail 200 "FATAL: Failed to load recovery init module. ($?)"
|
||||||
|
# fi
|
||||||
|
# if ! load_module "$backup_engine" init; then
|
||||||
|
# exit_fail 201 "FATAL: Failed to load '$backup_engine' init module. ($?)"
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# load_config
|
||||||
|
|
||||||
|
# if ! load_module "$backup_engine" prepare; then
|
||||||
|
# exit_fail 202 "FATAL Failed to load '$backup_engine' prepare module. ($?)"
|
||||||
|
# fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid command: $1"
|
echo "Invalid command: $1"
|
||||||
|
|
Loading…
Reference in a new issue