#1305 added formatting of new backup device

This commit is contained in:
rootzoll 2020-07-04 13:43:21 +02:00
parent 1fe9fde962
commit f9af9d6bc8

View file

@ -3,7 +3,7 @@
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# adding and removing a backup device (usb thumbdrive)"
echo "# blitz.backupdevice.sh status"
echo "# blitz.backupdevice.sh on [?DEVICEUUID]"
echo "# blitz.backupdevice.sh on [?DEVICEUUID|DEVICENAME]"
echo "# blitz.backupdevice.sh off"
echo "# blitz.backupdevice.sh mount"
echo "error='missing parameters'"
@ -17,8 +17,23 @@ source /mnt/hdd/raspiblitz.conf
# STATUS
#########################
# is on or off
if [ "${localBackupDeviceUUID}" == "" ] || [ "${localBackupDeviceUUID}" == "off" ]; then
if [ "$1" = "status" ]; then
if [ "${localBackupDeviceUUID}" != "" ] && [ "${localBackupDeviceUUID}" != "off" ]; then
echo "backupdevice=1"
echo "UUID='${localBackupDeviceUUID}'"
# check if nackup device is mounted
backupDeviceExists=$(df | grep -c "/mnt/backup")
if [ ${backupDeviceExists} -gt 0 ]; then
echo "isMounted=1"
else
echo "isMounted=0"
fi
else
echo "backupdevice=0"
# get all the devices that are not mounted and possible candidates
drivecounter=0
@ -38,26 +53,6 @@ if [ "${localBackupDeviceUUID}" == "" ] || [ "${localBackupDeviceUUID}" == "off"
echo "backupCandidates=${drivecounter}"
fi
if [ "$1" = "status" ]; then
if [ "${localBackupDeviceUUID}" == "" ] || [ "${localBackupDeviceUUID}" == "off" ]; then
echo "backupdevice=1"
echo "UUID='${localBackupDeviceUUID}'"
# check if nackup device is mounted
backupDeviceExists=$(df | grep -c "/mnt/backup")
if [ ${backupDeviceExists} -gt 0 ]; then
echo "isMounted=1"
else
echo "isMounted=0"
fi
else
echo "backupdevice=0"
echo "UUID=''"
echo "isMounted=0"
fi
exit 0
fi
@ -79,9 +74,39 @@ if [ "$1" = "on" ]; then
# check that device is connected
uuidConnected=$(lsblk -o UUID | grep -c "${uuid}")
if [ ${uuidConnected} -eq 0 ]; then
echo "# UUID not found - test is its a valid device name like sdb ..."
isDeviceName=$(lsblk -o NAME,TYPE | grep "disk" | awk '$1=$1' | cut -d " " -f 1 | grep -c "${uuid}")
if [ ${isDeviceName} -eq 1 ]; then
hdd="${uuid}"
echo "# OK found device name ${hdd} that will now be formatted ..."
echo "# Wiping all partitions (sfdisk/wipefs)"
sudo sfdisk --delete /dev/${hdd} 1>&2
sudo wipefs -a /dev/${hdd} 1>&2
partitions=$(lsblk | grep -c "${hdd}")
if [ ${partitions} -gt 0 ]; then
echo "# WARNING: partitions are still not clean"
error='partitioning failed'
exit 1
fi
# using FAT32 here so that the backup can be easily opened on Windows and Mac
echo "# Create on big partition"
sudo parted /dev/${hdd} mklabel msdos
sudo parted /dev/${hdd} mkpart primary fat32 0% 100% 1>&2
echo "# Formatting FAT32"
sudo mkfs.vfat -F 32 -n 'BLITZBACKUP' /dev/${hdd}1 1>&2
echo "# Getting new UUID"
uuid=$(lsblk -o UUID,NAME | grep "${hdd}1" | cut -d " " -f 1)
if [ "${uuid}" == "" ]; then
error='formatting failed'
exit 1
fi
echo "# OK device formatted --> UUID is ${uuid}"
else
echo "error='device not found'"
exit 1
fi
fi
# change raspiblitz.conf
entryExists=$(cat /mnt/hdd/raspiblitz.conf | grep -c 'localBackupDeviceUUID=')