-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypted_rsync.sh
44 lines (44 loc) · 1.08 KB
/
encrypted_rsync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# VARIABLES (Not yet coded for - Script is not yet polished but will give a good template)
#
# ENC_DEVICE=$1
# MOUNT_POINT=$2
# IP=$3
# PORT=$4
#
#### AUTO MOUNT ENCRYPTED VOLUME ####
echo "Sending Keyfile"
echo "..."
scp -q -P $PORT keyfile $IP:/home
echo ""
echo "Opening Encrypted Volume"
echo "..."
ssh -q -t -p$PORT $IP "sudo chmod 600 /home/keyfile"
ssh -q -t -p$PORT $IP "sudo cryptsetup luksOpen /dev/xvdc encrypted --key-file /home/keyfile"
echo ""
echo "Removing Keyfile"
echo "..."
echo ""
ssh -q -t -p$PORT $IP "sudo rm -f keyfile"
echo "Mounting Encrypted Volume"
echo "..."
ssh -q -t -p$PORT $IP "sudo mount /dev/mapper/encrypted /mnt/encrypted/"
echo ""
echo "Running Rsync"
echo "..."
#### RUNNING SYNC ####
rsync -e 'ssh -p $PORT' -aruvhq /home $IP:/mnt/encrypted/data | pv
#### UNMOUNT AND ENCRYPT VOLUME ####
echo ""
echo "Rsync Complete"
echo "..."
echo ""
echo "Unmounting Volume"
echo "..."
ssh -q -t -p$PORT $IP "sudo umount /mnt/encrypted/"
echo ""
echo "Encrypting Volume"
echo "..."
ssh -q -t -p$PORT $IP "sudo cryptsetup luksClose encrypted"
echo ""
echo "Completed"