-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrear-backup_v0.1.0.sh
137 lines (102 loc) · 5.92 KB
/
rear-backup_v0.1.0.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# name : rear-backup
# desciption : create temporary connects and paths for rear backup
# autor : speefak ( [email protected] )
# licence : (CC) BY-NC-SA
# version : 0.1.0
# notice :
# infosource :
#
#------------------------------------------------------------------------------------------------------------
############################################################################################################
####################################### define global variables ########################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
Version=0.1.0
ScriptName=$(basename $0)
SSHFSUser=speefak
SSHFSHost=192.168.1.X
BackupTargetDirRemoteHost="ISO_Backups"
BackupFileSuffix="entire_disk"
SSHFSMountpoint="/mnt/${SSHFSUser}@$(echo ${SSHFSHost} | tr -d "/")_ReaR"
RearOutputDir="${SSHFSMountpoint}/${BackupTargetDirRemoteHost}"
#------------------------------------------------------------------------------------------------------------
############################################################################################################
######################################## set vars from options ##########################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------------
############################################################################################################
########################################### define functions ###########################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
script_information () {
printf " Scriptname: $ScriptName\n"
printf " Version: $Version \n"
printf " Location: $(pwd)/$ScriptName\n"
printf " Filesize: $(ls -lh $0 | cut -d " " -f5)\n"
}
#------------------------------------------------------------------------------------------------------------
usage() {
printf "\n"
printf " Usage: $(basename $0) <options> "
printf "\n"
printf " -h => help dialog \n"
printf "\e[0;31m\n $1\e[0m\n"
printf "\n"
exit
}
#------------------------------------------------------------------------------------------------------------
############################################################################################################
############################################# start script #############################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
# check for script information
if [[ $1 == "-i" ]]; then
printf "\n"
script_information
printf "\n"
fi
#------------------------------------------------------------------------------------------------------------
# check for root permission
if [ ! "$(whoami)" = "root" ]; then printf "\nAre You Root ?\n\n";exit 1;fi
#------------------------------------------------------------------------------------------------------------
# check help dialog
if [[ -n $HelpDialog ]] || [[ -z $1 ]]; then usage "help dialog" ; fi
#------------------------------------------------------------------------------------------------------------
# create local mountpoint, mount ssh remote host and create iso backup target dir
mkdir -p "${SSHFSMountpoint}"
sshfs -o allow_other,follow_symlinks ${SSHFSUser}@${SSHFSHost}: ${SSHFSMountpoint}
mkdir -p "${RearOutputDir}"
#-------------------------------------------------------------------------------------------------------------
# backup existing ReaR configuration and setup temporary ReaR configuration
cp /etc/rear/local.conf /etc/rear/local.conf_bak
echo '
OUTPUT=ISO
ISO_DIR='${RearOutputDir}'
OUTPUT_URL=null
BACKUP=NETFS
BACKUP_URL="iso:///backup"
BACKUP_PROG_COMPRESS_OPTIONS=( --use-compress-program=pigz )
REQUIRED_PROGS+=( pigz )
USER_INPUT_TIMEOUT=3
AUTORESIZE_PARTITIONS=true
' > /etc/rear/local.conf
#------------------------------------------------------------------------------------------------------------
# start ReaR backup
rear -v mkbackup
#------------------------------------------------------------------------------------------------------------
# restore ReaR configuration
mv /etc/rear/local.conf_bak /etc/rear/local.conf
#------------------------------------------------------------------------------------------------------------
# rename iso backup file
cd ${RearOutputDir}
mv "$(ls | grep -w rear-$(hostname).iso)" "$(hostname)_$(date +%F-%H%M%S)_${BackupFileSuffix}.iso"
cd -
printf "\n final image stored in ${RearOutputDir}/$(hostname)_$(date +%F-%H%M%S)_${BackupFileSuffix}.iso \n"
#------------------------------------------------------------------------------------------------------------
# unmount and delete directories
umount ${SSHFSMountpoint}
rmdir ${SSHFSMountpoint}
#------------------------------------------------------------------------------------------------------------
exit 0