Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Created November 20, 2020 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidpixo/65c68174cde3c861938657ab32652b89 to your computer and use it in GitHub Desktop.
Save kidpixo/65c68174cde3c861938657ab32652b89 to your computer and use it in GitHub Desktop.
# 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