Created
January 30, 2016 02:47
-
-
Save woodruffw/fb45555e7c866ee1c657 to your computer and use it in GitHub Desktop.
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
| #!/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