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.
59 lines
1.8 KiB
Fish
59 lines
1.8 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
|
|
echo "$LUKS_NAME" > .luks-device
|
|
"
|
|
|
|
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 -rlptgozEv --delete ~ $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
|
|
read -P "Continue? Just press enter to start unmounting! "
|
|
ssh -t -i $KEY $USER@$REMOTE "
|
|
sudo umount $LUKS_MOUNT
|
|
sudo cryptsetup close --type luks (cat .luks-device)
|
|
rmdir $LUKS_MOUNT
|
|
rm .luks-device
|
|
"
|