Last active
December 29, 2022 20:48
-
-
Save mattstibbs/a33a8a66791a3a6fee205a0adcee3ef7 to your computer and use it in GitHub Desktop.
A pre-backup script for using with Duplicacy backups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Gather current power status | |
AC_POWER=`ioreg -l | grep ExternalConnected | cut -d"=" -f2 | sed -e 's/ //g'` | |
# Gather details about current wifi network | |
WIFI_NETWORK=`networksetup -getairportnetwork en0 | grep 'Current Wi-Fi Network' | cut -c 24-` | |
# Specify the name of your home / office wifi network here | |
HOME_WIFI=my_home_wifi | |
ON_HOME_WIFI=No | |
if [[ "$WIFI_NETWORK" == "$HOME_WIFI" ]] | |
then | |
ON_HOME_WIFI=Yes | |
fi | |
# Enter IP address or hostname of your storage server here | |
STORAGE_SERVER="my_server.local" | |
# Work out if specified server is reachable | |
REACHABLE=No | |
ping -c1 -W1 -q $STORAGE_SERVER &>/dev/null | |
status=$( echo $? ) | |
if [[ $status == 0 ]] | |
then | |
REACHABLE=Yes | |
fi | |
echo On AC Power: $AC_POWER | |
echo Current Wifi Network: $WIFI_NETWORK | |
echo On Home Wifi: $ON_HOME_WIFI | |
echo Server Reachable: $REACHABLE | |
# Uncomment this to abort backup if running on battery | |
if [ "$AC_POWER" == "No" ] | |
then | |
echo Aborting: Not running on AC power | |
exit 1 | |
fi | |
# Uncomment this to abort backup if the storage server is not reachable | |
if [ "$REACHABLE" == "No" ] | |
then | |
echo Aborting: Storage server not reachable | |
exit 1 | |
fi | |
# Uncomment this to abort backup if you are not on the specified wifi network | |
if [ "$ON_HOME_WIFI" == "No" ] | |
then | |
echo Aborting: Not on home wifi | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment