Skip to content

Instantly share code, notes, and snippets.

@bolorino
Created August 18, 2021 23:07
Show Gist options
  • Save bolorino/1e11b4beebd03e63b966224895129db9 to your computer and use it in GitHub Desktop.
Save bolorino/1e11b4beebd03e63b966224895129db9 to your computer and use it in GitHub Desktop.
Borg backup repository mount for users
#!/bin/sh
# Mount/umount user's personal backup borg repository
# Zenity version
# @bolorino
CONFIG_REPO_FILE=~/.config/backups/repo-$USER.conf
if [ ! -f "$CONFIG_REPO_FILE" ]; then
zenity --error --width 300 --text "Config file missing."
exit 1
fi
if [ ! -O "$CONFIG_REPO_FILE" ]; then
zenity --error --width 300 --text "The configuration file does not belong to the user."
exit 1
fi
if [ $(stat -L -c "%a" "$CONFIG_REPO_FILE") != "600" ]; then
zenity --error --width 300 --text "The configuration file does not have the proper permissions."
exit 1
fi
# Include config file
. "$CONFIG_REPO_FILE"
if [[ $(findmnt -M "$MOUNT_POINT") ]]; then
borg umount "$MOUNT_POINT"
zenity --info --width 300 --text "Backup unmounted."
else
borg mount "$BORG_REPO" "$MOUNT_POINT"
zenity --info --width 300 --text "The backup is mounted in $MOUNT_POINT \n
Rerun this script to unmount."
fi
#!/bin/sh
# Mount/umount user's personal backup borg repository
# @bolorino
CONFIG_REPO_FILE=~/.config/backups/repo-$USER.conf
if [ ! -f "$CONFIG_REPO_FILE" ]; then
echo "Config file missing."
exit 1
fi
if [ ! -O "$CONFIG_REPO_FILE" ]; then
echo "The configuration file does not belong to the user."
exit 1
fi
if [ $(stat -L -c "%a" "$CONFIG_REPO_FILE") != "600" ]; then
echo "The configuration file does not have the proper permissions."
exit 1
fi
# Include config file
. "$CONFIG_REPO_FILE"
if [[ $(findmnt -M "$MOUNT_POINT") ]]; then
borg umount "$MOUNT_POINT"
echo "Backup unmounted."
else
borg mount "$BORG_REPO" "$MOUNT_POINT"
echo "The backup is mounted in $MOUNT_POINT"
echo "Rerun this script to unmount."
fi
# User's Borg repository config
# ~/.config/backups/repo-$USER.conf
# This config file should be chmod 600
# Used by borg-mount-personal-repo.sh
# @bolorino
export BORG_REPO=repo://url
export BORG_PASSPHRASE='borg-repository-password'
# Check that the user has permission to mount it
MOUNT_POINT=/mount/point/to/the/backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment