Skip to content

Instantly share code, notes, and snippets.

@yottatsa
Last active January 25, 2018 15:48
Show Gist options
  • Select an option

  • Save yottatsa/085b2623b774843e7ea242d3236d058d to your computer and use it in GitHub Desktop.

Select an option

Save yottatsa/085b2623b774843e7ea242d3236d058d to your computer and use it in GitHub Desktop.
#!/bin/sh -e
# Author: yottatsa
su - yottatsa -c 'make backup' 2>&1 | /usr/bin/logger -t backup
if \
[ $(date -d "today" "+%m") -ne $(date -d "tomorrow" "+%m") ] || \
[ "$(date '+%a')" = "Tue" -a $(date +%d) -lt 29 -a $(date +%d) -gt 2 ]
then
(
cd "/media/portable/backup"
mask="$(readlink latest | sed 's,-..$,,')"
file="$(echo $mask | sed 's,-,_,').tar.gz"
tar czf "${file}" -C ./ "$mask"* latest
find -maxdepth 1 -name '*.gpg' -delete
gpg --yes --encrypt -r {{ backup_recipient }} "${file}"
find -maxdepth 1 -name '*.tar.gz' -delete
s3cmd put "${file}.gpg" s3://{{ backup_bucket }}/
) 2>&1 | /usr/bin/logger -t backup
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment