Skip to content

Instantly share code, notes, and snippets.

@stemid
Created June 25, 2018 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stemid/74a2aed8ed0322e4b7753b5d3f6b6007 to your computer and use it in GitHub Desktop.
Save stemid/74a2aed8ed0322e4b7753b5d3f6b6007 to your computer and use it in GitHub Desktop.
Backup script for my personal laptop
#!/usr/bin/env bash
# Simple backup script for borg. http://borgbackup.readthedocs.io/en/stable/
# Install on Fedora: sudo dnf install borgbackup
#
# Configure BORG_REPO below to match some path on your own system. In my case
# it points to an autofs mount on my network backup device.
# Configure your own borg_excludes.
# by Stefan Midjich <swehack at gmail dot com>
export BORG_REPO="/media/nas/backups/$(hostname -s)-borgbackup"
borg_excludes=(
--exclude '.cache/*'
--exclude '.config/Google*'
--exclude '.mozilla/*'
--exclude '.meteor/*'
--exclude 'Dokument/ISO/*'
--exclude 'Hämtningar/*'
--exclude 'VirtualBox*/*'
--exclude 'VirtualMachines/*'
--exclude 'Backups/*'
--exclude 'Spel/*'
)
# Unfortunately borg init does not support the environment variables but it's
# only used once.
if [ ! -d $BORG_REPO ]; then
echo "Initializing new repository, you will be asked for the repository password thrice!"
borg init -e repokey
fi
echo -n "Enter passphrase for key $BORG_REPO: "
read -s password
echo
export BORG_PASSPHRASE="$password"
borg create --stats --progress --compression lz4 \
"${borg_excludes[@]}" \
'::{user}-{now}' .
borg prune --list --keep-last 5
# This is not really necessary but it doesn't hurt either.
BORG_PASSPHRASE=
password=
export -n BORG_PASS
#!/usr/bin/env bash
# Simple backup script for borg. http://borgbackup.readthedocs.io/en/stable/
# Install on Fedora: sudo dnf install borgbackup
#
# Configure BORG_REPO below to match some path on your own system. In my case
# it points to an autofs mount on my network backup device.
# Configure restore_dir to point to where you want the backup restored
# to. In my case I avoid restoring it straight to my home dir in case I need
# to inspect it first.
# by Stefan Midjich <swehack at gmail dot com>
BORG_REPO="/media/nas/backups/$(hostname -s)-borgbackup"
restore_dir=$HOME/Backups/restore
test -d "$restore_dir" || mkdir "$restore_dir"
cd "$restore_dir"
test -d $BORG_REPO || exit 1
echo -n "Enter passphrase for key $BORG_REPO: "
read -s password
echo
BORG_PASSPHRASE="$password"
borg extract --progress \
"$@"
BORG_PASSPHRASE=
password=
export -n BORG_PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment