71 lines
1.4 KiB
Bash
Executable File
71 lines
1.4 KiB
Bash
Executable File
#! /usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
if [ -z "$1" ]
|
|
then
|
|
REPO="nas:~/borg"
|
|
LOCAL=false
|
|
else
|
|
DISK="$1"
|
|
LOCAL=true
|
|
fi
|
|
|
|
if $LOCAL
|
|
then
|
|
#check if unlocked
|
|
if [ -e "/dev/disk/by-label/$DISK" ]
|
|
then
|
|
echo "Disk already unlocked"
|
|
else
|
|
udisksctl unlock -b /dev/disk/by-partlabel/$DISK --key-file "$HOME/.keys/luks.key"
|
|
fi
|
|
#check if mounted
|
|
if [ -e "/media/$USER/$DISK" ]
|
|
then
|
|
echo "Disk already mounted"
|
|
else
|
|
udisksctl mount -b /dev/disk/by-label/$DISK
|
|
fi
|
|
REPO="/media/$USER/$DISK/borg"
|
|
fi
|
|
|
|
|
|
ARCHIVE="$REPO::$HOSTNAME-$(date +%Y-%m-%dT%T)"
|
|
SRC="$HOME"
|
|
BORG_PASSPHRASE=""
|
|
echo "Enter passphrase for $REPO:"
|
|
read -s BORG_PASSPHRASE
|
|
export BORG_PASSPHRASE
|
|
|
|
borg create --progress --stats --exclude-caches \
|
|
--exclude $HOME/VirtualBox\ VMs \
|
|
--exclude $HOME/.cache \
|
|
--exclude $HOME/Downloads \
|
|
--exclude $HOME/Photos \
|
|
--exclude $HOME/Videos \
|
|
--exclude $HOME/tmp \
|
|
--exclude $HOME/.local/Steam \
|
|
--exclude $HOME/.local/share/Steam \
|
|
--exclude $HOME/Audio \
|
|
--exclude $HOME/nas \
|
|
--exclude $HOME/go \
|
|
--exclude $HOME/.var/app \
|
|
--exclude $HOME/.config/borg/security/ \
|
|
$ARCHIVE $SRC && if ! $LOCAL; then date +%s > $HOME/.lastbak; fi
|
|
|
|
|
|
|
|
borg prune --stats --list --keep-within 1d --glob-archives "$HOSTNAME*" \
|
|
-d 7 \
|
|
-w 4 \
|
|
-m 6 \
|
|
-y 1 \
|
|
$REPO
|
|
|
|
if $LOCAL
|
|
then
|
|
udisksctl unmount -b "/dev/disk/by-label/$DISK"
|
|
udisksctl lock -b "/dev/disk/by-partlabel/$DISK"
|
|
fi
|