-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackup.sh
executable file
·56 lines (45 loc) · 1.09 KB
/
backup.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
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# This script tars a file and encrypts it with openssl
# The password is managed using password-store
# (http://git.zx2c4.com/password-store)
# TODO Offsite backups with rsync
VERSION=0.3
ENC="aes-256-cbc"
# This folder contains a list of symbolic links
# of what you wish to backup
LOCAL="$HOME/.backup-links"
# The name of your backup
OUTPUT="$(date "+%F.%T-backup.tar.gz.aes")"
# Where to store your backups (should be a flash drive)
#REMOTE="$HOME/Desktop"
REMOTE="/media/Backup"
snapshot() {
PASS="$(pass general/backup)"
tar zcfh - $LOCAL |openssl enc $ENC -salt -k pass:$PASS > "$REMOTE/$OUTPUT"
}
# $1 = encrypted backup
recover() {
PASS="$(pass general/backup)"
openssl $ENC -d -k pass:$PASS -in $1 |tar xz
}
usage() {
echo "Options"
echo " -b Create backup"
echo " -r [file] Recover file"
echo " -v Version"
echo " -h Print this message"
}
main() {
while getopts ":rbvh" OPTION
do
case $OPTION in
h) usage; exit 0;;
b) snapshot; exit 0;;
r) recover $OPTARG; exit 0;;
v) version; exit 0;;
?) echo "Invalid argument."; usage ;;
esac
done
exit 0
}
main $*