Skip to content

Instantly share code, notes, and snippets.

@jasontbradshaw
Last active December 28, 2021 12:56
Show Gist options
  • Save jasontbradshaw/6a69d7c9ae0c73f54200 to your computer and use it in GitHub Desktop.
Save jasontbradshaw/6a69d7c9ae0c73f54200 to your computer and use it in GitHub Desktop.
A backup script using bup.
#!/usr/bin/env bash
# Strict mode (see: http://redsymbol.net/articles/unofficial-bash-strict-mode/).
set -euo pipefail
IFS=$'\n\t'
# We name the repository directory after the system's hostname and the current
# year/month. We include the year/month combo so our backup repository doesn't
# continue to grow forever, and we can manually delete old ones as necessary.
name="$(hostname)"
repository_dir="$(dirname "${1:-}/gets-removed")"
repository="${repository_dir}/${name}/$(date -u +'%Y-%m')"
# Set the `bup` directory here so it affects all the `bup` commands.
export BUP_DIR="${repository}"
# Create the backup repository if it doesn't exist.
if [ ! -d "${repository}" ]; then
bup init
fi
# Do the backup as non-intrusively as possible.
echo "Indexing ${name}..."
nice -n19 ionice -c3 \
bup index \
--exclude-rx='^/dev/.*' \
--exclude-rx='^/proc/.*' \
--exclude-rx='^/sys/.*' \
--exclude-rx='^/tmp/.*' \
--exclude-rx='^/run/.*' \
--exclude-rx='^/mnt/.*' \
--exclude-rx='^/media/.*' \
--exclude-rx='^/var/lib/docker/devicemapper/.*' \
--exclude-rx='^/var/cache/packman/pkg/.*' \
--exclude-rx='.*/lost\+found/.*' \
--exclude-rx='^/home/[^/]+/\.cache/.*' \
--exclude-rx='^/home/[^/]+/VirtualBox VMs/.*' \
--exclude-rx='^/home/[^/]+/\.config/[^/]*chrom[^/]*/Default/File System/.*' \
--exclude-rx='^/home/[^/]+/\.config/[^/]*chrom[^/]*/Default/GPUCache/.*' \
--exclude-rx='^/home/[^/]+/\.local/share/Trash/.*' \
--exclude-rx='^/home/[^/]+/\.mozilla/firefox/[^/]+/Cache' \
--exclude-rx='^/home/[^/]+/\.gvfs' \
--exclude-rx='^/home/[^/]+/\.thumbnails/.*' \
--exclude-rx='\.pyc$' \
'/'
echo "Backing up ${name} to '${repository}'..."
nice -n19 ionice -c3 \
bup save \
--name="${name}" \
--compress=0 \
-vv \
'/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment