Skip to content

Instantly share code, notes, and snippets.

@Darkhand81
Created September 4, 2015 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Darkhand81/e3f240c514dd87dc4285 to your computer and use it in GitHub Desktop.
Save Darkhand81/e3f240c514dd87dc4285 to your computer and use it in GitHub Desktop.
Data redundancy bash scripts for the PiKeeper NAS project
#!/bin/bash
# ------------------------------------------------
# PiKeeper sync disable script
# This file should typically be placed in:
# /etc/smartmontools/run.d/
# ------------------------------------------------
# Configuration:
#
# Name and location of the script's log file:
logfile="/home/pi/sync_log.log"
dt=$(date '+%D %r');
# Create NOSYNC file when disk errors are detected, which the
# rsync script watches for to disable syncing to/from a bad disk
echo -e "\n$dt - Creating NOSYNC file to disable rsync"
touch /home/pi/NOSYNC
#!/bin/bash
# ------------------------------------------------
# PiKeeper data redundancy script
#
# This file should be run daily
# (Typically placed in /etc/cron.daily/)
# ------------------------------------------------
# Configuration:
#
# Name and location of the script's log file:
logfile="/home/pi/sync_log.log"
# Directory to sync FROM:
syncfrom="/media/storage/"
# Directory to sync TO:
syncto="/media/backup/"
# Name and location of the file to look for
# to stop syncing due to drive failure
# (NOTE: This must match the name and location listed
# in the smartmon disable script, typically at
# /etc/smartmontools/run.d/disable_rsync_script):
haltfile="/home/pi/NOSYNC"
# ------------------------------------------------
dt=$(date '+%D %r');
if [ -f "$haltfile" ]
then
echo -e "\n$dt - $haltfile file found, rsync is disabled!" >> $logfile
exit 1
else
echo -e "\n$dt - Cron is executing syncscript:" >> $logfile
rsync -av --delete --exclude 'Downloads/Torrents/Leeching/*' --log-file=$logfile $syncfrom $syncto
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment