I'd like to write a script that backups data on a USB device every time the latter is getting plugged in a random USB slot. Now I know about the KERNEL=sdX identifier but the problem is that depending on the slot and on whether other devices are already plugged in the sdX will change. What would be the best way to identify my USB device in udev ? I've been thinking about using partuuid but I don't know how and I don't know where the partuuid is stored in the first place or how it is worked out.
How to get udev to identify a USB device regardless of the USB port it is plugged in?
udev
If you partition your device using gdisk as opposed to fdisk you will create a GPT-style partition table which, for each partition, can hold a PARTUUID and a PARTLABEL. The c command in gdisk allows you to set the partition name, ie the PARTLABEL.These partition ids do not change when you reformat the partition by creating a new filesystem on it. Most filesystems allow you to get or set a UUID and LABEL on the filesystem. The means to do so depends on the filesystem type, eg for ext3/4 it is tune2fs with -U and -L. These appear as UUID and LABEL in Linux.Do not confuse these 2 sets of ids. blkid will show all of them:/dev/sdb1: LABEL=MYLABEL UUID=A369-D716 TYPE=vfat PARTLABEL=My new partition \  PARTUUID=f0817245-d3ce-408b-9457-e33dfc04aebeYou can see the udev attributes with $ udevadm info -p $(udevadm info -q path -n /dev/sdb1)...E: ID_FS_LABEL=MYLABELE: ID_FS_LABEL_ENC=MYLABELE: ID_FS_UUID=A369-D716E: ID_FS_UUID_ENC=A369-D716E: ID_PART_ENTRY_UUID=f0817245-d3ce-408b-9457-e33dfc04aebeE: ID_PART_TABLE_UUID=7301d696-b66d-4f85-8272-7dd5e29175aeE: ID_PART_ENTRY_NAME=My\x20new\x20partition