Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# weresync backup
#
# autobackup on disk connect via udev rules :
# - [How to Auto Backup Files to USB Media When Connected](https://www.tecmint.com/auto-backup-files-to-usb-media-in-linux/)
# - [udev - ArchWiki](https://wiki.archlinux.org/index.php/udev)
# - [[SOLVED] automatic usb-backup with udev-rules + script / Newbie Corner / Arch Linux Forums](https://bbs.archlinux.org/viewtopic.php?id=32639)
# udevadm info -a -n sda > disk info
stop_weresync(){
WSPID=$(sudo pgrep weresync-daemon)
if [[ $WSPID ]]
then
echo "weresync-daemon running - killing it"
sudo kill $WSPID
else
echo "weresync-daemon NOT running"
fi
}
start_weresync(){
WSPID=$(sudo pgrep weresync-daemon)
if [[ $WSPID ]]
then
echo "weresync-daemon running - killing it"
sudo kill $WSPID
else
echo "weresync-daemon NOT running - starting it"
sudo weresync-daemon & >/dev/null 2>&1
fi
}
# declare list of backup hddids as associative array
declare -A hddids
hddids[black]='usb-WD_Elements_25A2_5758343145423941385A4836-0:0'
hddids[orange]='ata-ST1000LM035-1RK172_WQ966TVB'
for hddkey in "${!hddids[@]}"; do
if ls -1 /dev/disk/by-id/ | grep -q ${hddids[$hddkey]}
then
hdddevice=$(readlink /dev/disk/by-id/${hddids[$hddkey]} | rev | cut -d"/" -f 1 | rev)
echo "Present hdd $hddkey : ${hddids[$hddkey]} | device : /dev/$hdddevice"
echo "Starting weresync from /dev/sda /to dev/$hdddevice"
weresync \
--excluded-partitions "3,4,6" \
--bootloader grub2 \
--root-partition 5 \
--efi-partition 2 \
/dev/sda /dev/$hdddevice
else
echo "NOT Present hdd $hddkey : ${hddids[$hddkey]}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment