-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdr_backup.sh
115 lines (80 loc) · 3.03 KB
/
cdr_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
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
#!/bin/bash
DATE="$(which date)"
TIMESTAMP=`$DATE '+%Y.%m.%d'`
export WORK_DIR=`pwd`
echo ""
echo "Linux Backup and Restore Helper"
echo ""
echo "Hello $USER, Please follow on-screen instructions"
echo ""
echo "This script creates and restores backups of a drive, sudo is required"
echo "To find out drive letters run 'sudo fdisk -l' and identify your drive"
echo "Script works from current working directory."
echo ""
echo "Please select function..."
echo "b: Make a backup"
echo "r: Restore a backup"
echo "q: quit"
echo ""
read -p "What would you like to do (b/r/q): " PART
if [ $PART = b ]; then
echo ""
echo "Which device would you like to clone?"
read -p "Please provide the letter (sdX): " DRIVE_B
echo ""
echo "Cloning /dev/sd${DRIVE_B}"
echo ""
echo "Output file name structure is NAME_${TIMESTAMP}.zip"
read -p "Please specify NAME part: " NAMEB
echo ""
echo "Output file will be named ${NAMEB}_${TIMESTAMP}.zip"
echo ""
echo "This will take a while. Please wait... "
echo ""
sudo dd if=/dev/sd${DRIVE_B} of=${NAMEB}_${TIMESTAMP}.img conv=noerror status=progress
echo ""
echo "Compressing ${NAMEB}_${TIMESTAMP}.img, please wait..."
zip ${NAMEB}_$TIMESTAMP.zip ${NAMEB}_${TIMESTAMP}.img
echo ""
echo "Removing ${NAMEB}_${TIMESTAMP}.img"
sudo rm ${NAMEB}_${TIMESTAMP}.img
SIZE="$(du -h ${NAMEB}_${TIMESTAMP}.zip | awk '{ print $1 }')"
echo ""
echo "The file ${NAMEB}_${TIMESTAMP}.zip is about ${SIZE}."
echo "Full file path is ${WORK_DIR}/${NAMEB}_${TIMESTAMP}.zip"
elif [ $PART = r ]; then
echo ""
echo "This part will restore a backup."
echo ""
echo "Script looks for input file with the following pattern NAME_YYYY.MM.DD.zip"
echo ""
echo "To which device would you like to write?"
read -p "Please provide the letter (sdX): " DRIVE_R
echo ""
echo "Which file you want to restore?"
read -p "Please specify NAME part of the name: " NAMER
read -p "Please specify YYYY part of the name: " YEAR
read -p "Please specify MM part of the name: " MONTH
read -p "Please specify DD part of the name: " DAY
echo "Script will restore backup file named ${NAMER}_${YEAR}.${MONTH}.${DAY}.zip"
echo "To drive /dev/sd${DRIVE_R}"
echo ""
read -p "Press enter to continue or Ctrl+C to abort " foo
echo ""
echo "Unzipping ${NAMER}_${YEAR}.${MONTH}.${DAY}.zip"
echo "This will take a while. Please wait..."
echo ""
unzip ${NAMER}_${YEAR}.${MONTH}.${DAY}.zip
echo ""
echo "Writing ${NAMER}_${YEAR}.${MONTH}.${DAY}.img to /dev/sd${DRIVE_R}"
echo "This will take a while. Please wait..."
sudo dd if=${NAMER}_${YEAR}.${MONTH}.${DAY}.img of=/dev/sd${DRIVE_R} conv=noerror status=progress
echo ""
echo "Removing ${NAMER}_${YEAR}.${MONTH}.${DAY}.img"
sudo rm ${NAMER}_${YEAR}.${MONTH}.${DAY}.img
echo ""
echo "Drive /dev/sd${DRIVE_R} is ready for use"
else
echo "Nothing has been done..."
fi
echo ""