Skip to content

Instantly share code, notes, and snippets.

@dmuth
Created October 23, 2018 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmuth/b2117a851d51dba3f924627f75a4e831 to your computer and use it in GitHub Desktop.
Save dmuth/b2117a851d51dba3f924627f75a4e831 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Download a copy of Anthrocon's website, with (hopefully) working links,
# and tar it up to a single file.
#
# Errors are fatal
set -e
START_DIR=$PWD
TMP=$(mktemp -d /tmp/backup-anthrocon-XXXXX)
BACKUP=anthrocon-website-backup-$(date +%Y%m%d-%H%M%S).tgz
DOMAIN="www.anthrocon.org"
URL="https://${DOMAIN}/"
echo "# "
echo "# Changing to temp directory: ${TMP}"
echo "# "
pushd $TMP > /dev/null
echo "# "
echo "# Backing up ${URL}..."
echo "# "
#
# From https://www.guyrutenberg.com/2014/05/02/make-offline-mirror-of-a-site-using-wget/
#
# --mirror – Makes (among other things) the download recursive.
# --convert-links – convert all the links (also to stuff like CSS stylesheets) to relative, so it will be suitable for offline viewing.
# --adjust-extension – Adds suitable extensions to filenames (html or css) depending on their content-type.
# --page-requisites – Download things like CSS style-sheets and images required to properly display the page offline.
# --no-parent – When recursing do not ascend to the parent directory. It useful for restricting the download to only a portion of the site.
#
set +e
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent ${URL} 2>&1 | tee output.txt
EXIT_CODE=$?
set -e
#EXIT_CODE=255 # Debugging
if test "${EXIT_CODE}" -ne 0
then
echo "! "
echo "! wget exited with non-zero code: ${EXIT_CODE}"
echo "! "
echo "! Moving log from output.txt to ${START_DIR}..."
echo "! "
mv output.txt ${START_DIR}
exit ${EXIT_CODE}
fi
tar cfvz ${BACKUP} ${DOMAIN}
echo "# "
echo "# Moving backup: ${BACKUP} "
echo "# ...back to starting directory of ${START_DIR}..."
echo "# "
mv ${BACKUP} ${START_DIR}
echo "# Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment