You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB
Fish

#!/usr/bin/env fish
set REMOTE "your-backup-ssh-server" # ip/host where to backup to
set REMOTE_PATH "~/backup/current" # remote location where backup is mirrored
set USER username # ssh user
set KEY ~/.ssh/id_backup_key # ssh key
set SSH_OPT # possible ssh options
set LUKS_DEVICE "~/storage" # luks device or file to open
set LUKS_NAME "luks_"(random) # generate a random name for the luks groups
set LUKS_MOUNT "~/backup" # the mount point where the container is mounted to
set RSYNC_IGNORE_FILE "~/.backup-ignore" # the file containing the blacklist
# open luks container
set_color -o green
echo "Mounting luks container..."
set_color normal
ssh $SSH_OPT -t -i $KEY $USER@$REMOTE "
if [ -d $REMOTE_PATH ]
set_color -o green; echo \"backup already mounted!\"
set_color normal
exit
end
mkdir $LUKS_MOUNT
sudo cryptsetup open --type luks $LUKS_DEVICE $LUKS_NAME
sudo mount /dev/mapper/$LUKS_NAME $LUKS_MOUNT
"
if test "$argv" = '--browse'
set_color -o green
echo "LUKS mounted, connecting..."
set_color normal
ssh -i $KEY $USER@$REMOTE
else
# sync with rsync
set_color -o green
echo "Syncing filesystem..."
set_color normal
rsync --exclude-from=$RSYNC_IGNORE_FILE -rlptgozEP ~ $USER@$REMOTE:$REMOTE_PATH #TODO find more applicable options
end
# unmount luks container
set_color -o green
echo "Syncing complete - unmounting luks container..."
set_color normal
ssh -t -i $KEY $USER@$REMOTE "
sudo umount $LUKS_MOUNT
sudo cryptsetup close --type luks $LUKS_NAME
rmdir $LUKS_MOUNT
"