Skip to content
Snippets Groups Projects
Commit 3df6a514 authored by Bob Mottram's avatar Bob Mottram
Browse files

Ability to autodetect backup drive

parent 70f55026
No related branches found
No related tags found
No related merge requests found
......@@ -387,6 +387,9 @@ install_web_admin
function_check setup_final
setup_final
function_check store_drives_baseline
store_drives_baseline
echo ''
echo $"${PROJECT_NAME} installation is complete."
echo ''
......
......@@ -368,14 +368,23 @@ function backup_postgresql {
backup_directory_to_usb $temp_backup_dir postgresql
}
backup_device="$1"
# has the remove option been set ?
remove_option=$2
if [[ $1 == "remove" ]]; then
remove_option="$2"
if [[ "$backup_device" == "remove" ]]; then
remove_option=$1
fi
if [[ "$backup_device" == "detect" || "$backup_device" == "auto"* ]]; then
backup_device=$(detect_connected_drives)
if [[ "$backup_device" != 'sd'* ]]; then
echo $'No backup device was detected'
exit 356835
fi
fi
gpg_agent_setup root
backup_mount_drive "$1" "$2"
backup_mount_drive "$backup_device" "$2"
remove_backup_directory "$remove_option"
make_backup_directory
check_storage_space_remaining
......
......@@ -147,7 +147,7 @@ function backup_to_friends_servers {
function backup_mount_drive {
if [ "$1" ]; then
if [[ "$1" == "/dev/"* ]]; then
USB_DRIVE=$1
USB_DRIVE="$1"
else
USB_DRIVE=/dev/${1}1
fi
......@@ -156,12 +156,12 @@ function backup_mount_drive {
# get the admin user
ADMIN_USERNAME=$(get_completion_param "Admin user")
if [ "$2" ]; then
ADMIN_USERNAME=$2
ADMIN_USERNAME="$2"
fi
ADMIN_NAME=$(getent passwd "$ADMIN_USERNAME" | cut -d: -f5 | cut -d, -f1)
if [ "$3" ]; then
RESTORE_APP=$3
RESTORE_APP="$3"
fi
# check that the backup destination is available
......@@ -836,4 +836,26 @@ function backup_extra_directories {
done <"$BACKUP_EXTRA_DIRECTORIES"
}
DRIVES_BASELINE_FILE=/root/.drives_baseline
function store_drives_baseline {
if [ -f $DRIVES_BASELINE_FILE ]; then
return
fi
# shellcheck disable=SC2012
ls -gA /dev/sd* | awk -F '/dev/' '{print $2}' > $DRIVES_BASELINE_FILE
}
function detect_connected_drives {
if [ ! -f $DRIVES_BASELINE_FILE ]; then
# shellcheck disable=SC2012
ls -gA /dev/sd* | awk -F '/dev/' '{print $2}' > $DRIVES_BASELINE_FILE
return
fi
# shellcheck disable=SC2012
ls -gA /dev/sd* | awk -F '/dev/' '{print $2}' > /tmp/.drives_current
diff /tmp/.drives_current ${DRIVES_BASELINE_FILE} | awk -F '< ' '{print $2}' | sed '/^$/d' | sed 's/[0-9]*//g' | uniq | head -n 1
}
# NOTE: deliberately no exit 0
......@@ -45,6 +45,8 @@ function install_final {
split_gpg_key_into_fragments
lockdown_permissions
store_drives_baseline
mark_completed "${FUNCNAME[0]}"
clear
echo ''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment