Skip to content

Instantly share code, notes, and snippets.

@Igaryu
Last active April 16, 2023 09:20
Show Gist options
  • Save Igaryu/18b5cea31a90387fee01f9ab70e3335a to your computer and use it in GitHub Desktop.
Save Igaryu/18b5cea31a90387fee01f9ab70e3335a to your computer and use it in GitHub Desktop.
Script per TIme Machine senza dischi collegati permanentemente
#!/bin/bash
#
# Disk volumes CONSTANTS sets
#
Disco01="/Volumes/1st Time Capsule/" # Mount point first device: adapt
Device01="4AB05D67-2513-4EAB-8AC0-C258A4FBE1E4" # UID for first device
Disco02="/Volumes/2nd Time Capsule/" # Mount point second device: adapt
Device02="A5FAFBBE-2C0A-4252-99F1-92847B6D6416" # UID for second device
##
## If ANY parameter is passed, script will become verbose!
##
#
# if first MountPoint exist
# skip mount operatiion,
# else
# notice
# mount quietly first backup volume
#
if [ -d "$Disco01" ]; then
if [ $# -gt 0 ]; then
echo "Il volume di backup $Disco01 è già montato!!!"
fi
else
if [ $# -gt 0 ]; then
echo "$Disco01 non montato: provvedo a montarlo..."
fi
/usr/sbin/diskutil quiet mount "$Device01"
fi
#
# if second MountPoint exist
# skip mount operatiion,
# else
# notice
# mount quietly second backup volume
#
if [ -d "$Disco02" ]; then
if [ $# -gt 0 ]; then
echo "Il volume di backup $Disco02 è già montato!!!"
fi
else
if [ $# -gt 0 ]; then
echo "$Disco02 non montato: provvedo a montarlo..."
fi
/usr/sbin/diskutil quiet mount "$Device02"
fi
#
# Execute backup waiting end backup (--block) before continuing script
# if multiple disks are used as backup set --rotation kees live correct
# disk selection per backup.
#
if [ $# -gt 0 ]; then
echo "Eseguo backup..."
fi
/usr/bin/tmutil startbackup --block --rotation
#
# Umount the two discks protecting them
# from ransomware infection
if [ $# -gt 0 ]; then
echo "Smonto disco $Disco01 ..."
fi
/usr/sbin/diskutil unmount force "$Device01"
if [ $# -gt 0 ]; then
echo "Smonto disco $Disco02"
fi
/usr/sbin/diskutil unmount force "$Device02"
if [ $# -gt 0 ]; then
echo "Backup terminato !!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment