Init
This commit is contained in:
45
usr/sbin/tupper
Executable file
45
usr/sbin/tupper
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Inform user
|
||||
echo "Welcome to tupper! Running on $(date)"
|
||||
|
||||
# Check access rights of config file
|
||||
CONF="/etc/tupper.conf"
|
||||
if [ "$(stat -c '%U' $CONF)" != "root" ] && [ "$(stat -c '%A' $CONF)" = "*------" ]; then
|
||||
echo "Config file $CONF must be owned by root without any rights for group and other (**00) set" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
# Include config file
|
||||
source "$CONF"
|
||||
|
||||
# Check if required variables are set
|
||||
if [ "$SSH_URI$SSH_PASS$TARGET" = "" ]; then
|
||||
echo "Config file $CONF must contain SSH_URI, SSH_PASS and TARGET" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check privileges
|
||||
if [ "$UID" -ne 0 ]; then
|
||||
echo "$0 must be run as root. Quitting." 1>2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create temporary mountpoint
|
||||
MOUNTPOINT="$(mktemp --directory)"
|
||||
|
||||
# Check if SSHFS needs to be mounted
|
||||
if [ "$(mount | grep $MOUNTPOINT | wc -l)" -eq 0 ]; then
|
||||
echo "$SSH_PASS" | sshfs -o password_stdin "$SSH_URI" "$MOUNTPOINT"
|
||||
fi
|
||||
|
||||
# Backup
|
||||
export BORG_PASSPHRASE
|
||||
borg create --stats "$MOUNTPOINT::"'{now}' "$TARGET"
|
||||
borg list "$MOUNTPOINT"
|
||||
|
||||
# Unmount and clean up mountpoint
|
||||
fusermount -u "$MOUNTPOINT" && \
|
||||
rm -rf "$MOUNTPOINT"
|
||||
|
||||
# Inform user
|
||||
echo "Goodbye from tupper! Finished on $(date)"
|
||||
Reference in New Issue
Block a user