Skip to content

Instantly share code, notes, and snippets.

@woodruffw
Created January 30, 2016 02:47
Show Gist options
  • Select an option

  • Save woodruffw/fb45555e7c866ee1c657 to your computer and use it in GitHub Desktop.

Select an option

Save woodruffw/fb45555e7c866ee1c657 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# wwwbackup: back woodruffw.us files up to tarball, rotate weekly
if [[ "$(hostname)" != "athena" ]] ; then
echo "Wrong host, dummy."
exit 1
fi
shopt -s nullglob
cap="7" # don't go over 7 stored backups
www_root="/usr/share/nginx/html"
backup_dir="${HOME}/www_backups"
backup_slug="${backup_dir}/$(date +%Y-%m-%d).tar.gz"
mkdir -p "${backup_dir}"
tar czf "${backup_slug}" "${www_root}"
old_backups=$(ls ${backup_dir}/*.tar.gz | sort -r | sed -e "1,${cap}d")
[[ -n "${old_backups}" ]] && echo "${old_backups}" | xargs rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment