-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup_to_external_hdd.sh
executable file
·90 lines (63 loc) · 2.46 KB
/
backup_to_external_hdd.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash -
#===============================================================================
#
# FILE: backup_to_external_hdd.sh
#
# USAGE: backup_to_external_hdd.sh
#
# DESCRIPTION: This script will perform an backup to certain directory ,tar zipped to external HDD.
#
# OPTIONS: ---
# REQUIREMENTS: cryptsetup tar mount
# BUGS: ---
# NOTES: Static variable values for few variables
# AUTHOR: Bhaskar Chowdhury (https://about.me/unixbhaskar), unixbhaskar@gmail.com
# ORGANIZATION: Independent
# CREATED: 05/08/2020 13:13
# REVISION: 1.0
#===============================================================================
set -o nounset # Treat unset variables as an error
if [[ $UID -ne 0 ]];then
printf "Without superuser power you can not run this scipt.\n"
exit 1
fi
crypt=$(command -v cryptsetup)
external_drive=$(fdisk -l | grep sdb | gawk '{ print $2 }' | tr -d :)
bkup2="/backup2"
tar=$(command -v tar)
home_backupfile="home-backup-$(date +'%F').tar.gz"
data_backupfile="data-backup-$(date +'%F').tar.gz"
default_backup_lvm="/dev/mapper/backup2"
#Actaual meat of the script , which might be converted to a function ,later task.
if [[ $external_drive != "" ]];then
mkdir -p $bkup2
$crypt luksOpen $external_drive $bkup2
#need to put your passphrase on the stdin
mount $default_backup_lvm $bkup2
printf "Check status and dump of the luks device.....\n\n"
$crypt luksDump $external_drive
sleep 2
$crypt -v status $bkup2
printf "\n\n Time to take backup ...hold on ....it will take sometime ...\n\n"
cd $bkup2
printf "Checking that we are in correct dir : $(pwd) \n\n"
home_backup=$($tar --exclude="/home/bhaskar/git-linux" --exclude="/home/bhaskar/Pictures" --exclude="/home/bhaskar/Music" -cvzf $home_backupfile /home/bhaskar)
eval $home_backup
printf "\n Executing this : tar -czf $data_backupfile /data \n\n"
data_backup=$($tar --exclude="/data/linux" --exclude="/data/asp" --exclude="/data/firefox_log" -cvzf $data_backupfile /data)
eval $data_backup
printf "\n\n Checkout their existence ...\n\n"
find . -name "home-backup-*" -type f -print0 -exec ls -al {} \;
find . -name "data-backup-*" -type f -print0 -exec ls -al {} \;
printf "\n\nShould I close this connection[Y/N]: %s"
read_response
if [[ $read_response == "Y" ]];then
umount /backup2
$crypt luksClose $bkup2
else
continue
fi
else
printf "Device not mounted"
exit 1
fi