1

How can I set this up so that it itself checks if there is an sd or usb, so it makes a backup depending on whether I have an sd card or usb disk attached?

dd if=/dev/mmcblk0 of=${BACKUP_PATH}/${HOSTNAME}${ARCHITECTURE}bits-${BACKUP_DATO}.img bs=1MB status=progress
echo "Backup Image from SD-Kort"

dd if=/dev/sda of=${BACKUP_PATH}/${HOSTNAME}${ARCHITECTURE}bits-${BACKUP_DATO}.img bs=1MB status=progress echo "Backup Image from USB"

Bodo
  • 253
  • 1
  • 7
Assassins
  • 23
  • 5

1 Answers1

1

If exactly one of /dev/mmcblk0 and /dev/sda exists and shall be saved, you could use something like

if [ -e /dev/mmcblk0 ]
then
    dd if=/dev/mmcblk0 of=${BACKUP_PATH}/${HOSTNAME}${ARCHITECTURE}bits-${BACKUP_DATO}.img bs=1MB status=progress
    echo "Backup Image from SD-Kort"
else
    dd if=/dev/sda of=${BACKUP_PATH}/${HOSTNAME}${ARCHITECTURE}bits-${BACKUP_DATO}.img bs=1MB status=progress
    echo "Backup Image from USB"
fi

or

if [ -b /dev/mmcblk0 ]
...

-e checks the existence of any file system object, -b checks for the existence of a block device, -f checks for a regular file (which does not match here).

Depending on your needs you could also check what device is mounted as /, e.g. by parsing the output of mount.

Bodo
  • 253
  • 1
  • 7