Created
May 23, 2016 14:03
-
-
Save prenagha/c5d6c2ebf3de0a4f61afdf3610e57363 to your computer and use it in GitHub Desktop.
Arq Backup Check
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 | |
# | |
# Use with Arq Backup www.arqbackup.com | |
# To check backup complete marker files in Amazon AWS S3 | |
# See related script that writes these files arq-complete.sh: | |
# https://gist.github.com/prenagha/f11e0b800d7f1a5733dab1289febad51 | |
# | |
set -e | |
trap 'notify' INT TERM ERR | |
function notify { | |
msg=$1 | |
if [ -z "$1" ] | |
then | |
msg="Failed checking ${bset}" | |
fi | |
/usr/local/bin/terminal-notifier \ | |
-title "Arq Backup Check" \ | |
-message "${msg}" \ | |
-sound default \ | |
-activate com.haystacksoftware.Arq \ | |
-sender com.haystacksoftware.Arq | |
} | |
files="xxx.main.txt xxx.main.txt" | |
for file in ${files} | |
do | |
bset=`basename ${file} .txt` | |
tmp=/tmp/arq-check-${file} | |
bucket=xxxxx | |
resource="/${bucket}/${file}" | |
contentType="text/plain" | |
dateValue=`/bin/date "+%a, %d %b %Y %H:%M:%S %z"` | |
stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}" | |
s3Key=xxxxxx | |
s3Secret="xxxxxx" | |
signature=`echo -en ${stringToSign} | /usr/bin/openssl sha1 -hmac ${s3Secret} -binary | /usr/bin/base64` | |
echo "000" > "${tmp}" | |
/usr/bin/curl --silent --fail --output "${tmp}" \ | |
-H "Host: ${bucket}.s3.amazonaws.com" \ | |
-H "Date: ${dateValue}" \ | |
-H "Content-Type: ${contentType}" \ | |
-H "Authorization: AWS ${s3Key}:${signature}" \ | |
https://${bucket}.s3.amazonaws.com/${file} | |
tooOld=`date -v-2w +%s | bc` | |
last=`head -1 ${tmp} | bc` | |
if [ "${last}" -lt "${tooOld}" ] | |
then | |
notify "Stale ${bset} `date -r ${last} +%m/%d/%Y`" | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment