-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabs.sh
executable file
·212 lines (190 loc) · 6.59 KB
/
abs.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
#
# This script will backup and restore folders using the incremental option of TAR
# You don't need to create a full backup each time
# The second backup will be a diferencial backup. You will save time and space.
# You just need to change the variables DIRTOBACKUP, BACKUPDESTINATION and DIRTORESTORE
#
# josemedeirosdealmeida@gmail.com
# Jose Almeida
#Load Variables
source albans.conf
config () {
source albans.conf
summary
#echo "The folder configured to backup is $DIRTOBACKUP press [ENTER] to continue without changes or insert a new folder"
echo -e '\nInsert a new configuration information or press [ENTER] to continue without changes\n\n\n'
read -p "Folder to backup is $DIRTOBACKUP define a new one or press ENTER to continue: " DIRTOBACKUPNEW
if [ "$DIRTOBACKUPNEW" == "" ] ; then
echo > /dev/null #Just proceed please...
else
sed -i "/DIRTOBACKUP/c \DIRTOBACKUP=$DIRTOBACKUPNEW # Folder to backup" albans.conf
fi
read -p "Folder to store your backup is $BACKUPDESTINATION define a new one or press ENTER to continue: " BACKUPDESTINATIONNEW
if [ "$BACKUPDESTINATIONNEW" == "" ] ; then
echo > /dev/null #Just proceed please...
else
sed -i "/BACKUPDESTINATION/c \BACKUPDESTINATION=$BACKUPDESTINATIONNEW # Storage path" albans.conf
fi
read -p "Snapshot file is $SNAPSHOTFILE define a new one or press ENTER to continue: " SNAPSHOTFILENEW
if [ "$SNAPSHOTFILENEW" == "" ] ; then
echo > /dev/null #Just proceed please...
else
sed -i "/SNAPSHOTFILE/c \SNAPSHOTFILE=$SNAPSHOTFILENEW # This file can be changed, but cannot be deleted" albans.conf
fi
read -p "Name to be used by system as a reference is $REFERENCE define a new one or press ENTER to continue: " REFERENCENEW
if [ "$REFERENCENEW" == "" ] ; then
echo > /dev/null #Just proceed please...
else
sed -i "/REFERENCE/c \REFERENCE=$REFERENCENEW # This reference name will be used to create the file name, can be changed to another one" albans.conf
fi
read -p "Folder that will be used to restore everything is $DIRTORESTORE define a new one or press ENTER to continue: " DIRTORESTORENEW
if [ "$DIRTORESTORENEW" == "" ] ; then
echo > /dev/null #Just proceed please...
else
sed -i "/DIRTORESTORE/c \DIRTORESTORE=$DIRTORESTORENEW # Folder to restore our tar files. Can be a TAPE, or network file" albans.conf
fi
read -p "Press [Enter] key to continue..."
menu
}
showvars () {
source albans.conf
summary
echo -e "\n\e[21mFolder to backup: \e[1m$DIRTOBACKUP \e[21m"
echo -e "\eFolder to store your backup \e[1m$BACKUPDESTINATION \e[21m"
echo -e "\eSnapshot file: \e[1m$SNAPSHOTFILE \e[21m"
echo -e "\eName to be used by system as a reference: \e[1m$REFERENCE \e[21m"
echo -e "\eFolder that will be used to restore everything: \e[1m$DIRTORESTORE \e[21m"
echo -e '\n\n'
#Validate if the folders declared exist
if [ ! -d "$DIRTOBACKUP" ]; then
echo -e "Folder $DIRTOBACKUP does not exist\n"
fi
if [ ! -d "$BACKUPDESTINATION" ]; then
echo -e "Folder $BACKUPDESTINATION does not exist\n"
fi
if [ ! -f "$BACKUPDESTINATION/$SNAPSHOTFILE" ]; then
echo -e "File $BACKUPDESTINATION/$SNAPSHOTFILE does not exist\n"
fi
if [ ! -d "$DIRTORESTORE" ]; then
echo -e "Folder $DIRTORESTORE does not exist\n"
fi
read -p "Press [Enter] key to continue..."
menu
}
backup () {
source albans.conf
summary
echo "This will backup your $DIRTOBACKUP folder using as snapshot file $BACKUPDESTINATION/$SNAPSHOTFILE. You can run the script several times."
echo -e '\n\n'
mkdir -p $BACKUPDESTINATION
tar -v --create --file=$BACKUPDESTINATION/back_$(echo $REFERENCE)_$(date +\%Y\%m\%d_\%H\%M\%S).tar --listed-incremental=$BACKUPDESTINATION/$SNAPSHOTFILE $DIRTOBACKUP
read -p "Press [Enter] key to continue..."
menu
}
filipa () {
source albans.conf
summary
echo "Filipa... O nome do meu amor! ;)"
echo -e '\n\n'
read -p "Press [Enter] key to continue..."
menu
}
restore () {
source albans.conf
summary
read -p "Do you want to continue restore your backup to $DIRTORESTORE (Y/n)? " choseyorno
if [ "$choseyorno" == "Y" ] ; then
echo "All files will be restored to: $DIRTORESTORE"
sleep 2
mkdir -p $DIRTORESTORE
ls -ltr $BACKUPDESTINATION/back_$REFERENCE* | awk '{print $9}' > /tmp/albansbackup.tmp
sleep 1
while read line; do
tar -v --extract --listed-incremental=$BACKUPDESTINATION/$SNAPSHOTFILE --file $line -C $DIRTORESTORE
done < /tmp/albansbackup.tmp
rm -f /tmp/albansbackup.tmp
echo -e '\nEverything restored!\n'
read -p "Press [Enter] key to continue..."
else
menu
fi
menu
}
restoreuntil () {
source albans.conf
summary
echo "All files will be restored to: $DIRTORESTORE"
ls -ltrh $BACKUPDESTINATION/back_$REFERENCE* | awk '{print $5,"\t\t",$6,"\t\t",$7,"\t",$8,"\t",$9}' > /tmp/albansbackup.tmp
cp /tmp/albansbackup.tmp /tmp/albansbackup.tmp.1
echo -e 'Index\tSize\t\tTimestamp\t\t\tFilename' > /tmp/albansbackup.tmp
awk '$0=((NR-1)?NR-0:"1")" "$0' /tmp/albansbackup.tmp.1 >> /tmp/albansbackup.tmp
cat /tmp/albansbackup.tmp
echo -e '\n'
read -p "Select the Index file until you want to restore (included) or press ENTER to exit: " index
#Check if the variable index is lesser or equal than the number of lines of /tmp/albansbackup.tmp.1
if [ $index -le "$(wc -l /tmp/albansbackup.tmp.1|awk {'print $1'})" ];
then
sleep 1
echo -e 'Building the list of files to restore\n'
sleep 2
cat /tmp/albansbackup.tmp.1 | awk '{print $5}' | head -n $index > /tmp/albansbackup.tmp.until
mkdir -p $DIRTORESTORE
sleep 1
while read line; do
tar -v --extract --listed-incremental=$BACKUPDESTINATION/$SNAPSHOTFILE --file $line -C $DIRTORESTORE
done < /tmp/albansbackup.tmp.until
rm -f /tmp/albansbackup.tm* #Activate to clean logs
read -p "Press [Enter] key to continue..."
menu
else
menu
fi
}
findcontent () {
#Not ready yet
exit 0
}
listdiferences () {
#Not ready yet
#Base to work diff <(tar -tvf /mnt/aaaa/back_tadata_20160729_085423.tar | sort) <(tar -tvf /mnt/aaaa/back_tadata_20160729_090239.tar | sort)
exit 0
}
summary () {
clear
echo -e "\e[1m**********************************"
echo -e "*\033[0;31m\tAlbans Backup System\t\033[0m *"
echo -e "**********************************\e[0m"
}
menu () {
rm -f /tmp/albansbackup.tmp*
clear
while :
do
summary
echo -e "* [c] Config ABS \t\t *"
echo -e "* [s] Show configuration\t *"
echo -e "* [b] Backup\t\t\t *"
echo -e "* [r] Restore\t\t\t *"
echo -e "* [u] Restore Until\t\t *"
echo -e "* [x] Exit\t\t\t *"
echo -e "*\t\t\t\t *"
echo -e "* \t Version $VERSION $DATE *"
echo -e "**********************************"
echo -n -e "Select: "
read yourch
case $yourch in
c) config ;;
s) showvars ;;
b) backup ;;
r) restore ;;
u) restoreuntil ;;
f) filipa ;;
x) exit 0;;
*) echo "Menu: ";
echo "Press Enter to continue. . ." ; read ;;
esac
menu
done
}
menu