-
Notifications
You must be signed in to change notification settings - Fork 13
/
backup.sh
148 lines (124 loc) · 4.01 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
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
#!/bin/bash
# author: ellermister
# Backup files to the cloud for free
chunkBytesSize=$(expr 1024 \* 5) # KB
outPath=outs
realImage=bbb.jpg
action=$1
filePath=$2
# 上传图片
upload_image(){
local img_path=$1
a9ih0st="YUhSMGNITTZMeTlpWVdscWFXRm9ZVzh1WW1GcFpIVXVZMjl0TDJKMWFXeGtaWEpwYm01bGNpOWhjR2t2WTI5dWRHVnVkQzltYVd4bApMM1Z3Ykc5aFpBbz0K"
curl -s $(echo "$a9ih0st"|base64 -d|base64 -d) \
-H 'Accept: application/json' \
-H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/533.37' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-F 'no_compress=1' \
-F 'id=WU_FILE_0' \
-F 'is_avatar=0' \
-F "media=@$img_path" \
| grep -o -P '(?<="org_url":").*?(?=")'
}
# 伪装为图片
disguised_as_image(){
cat $realImage $1 > "$1.jpg"
echo "$1.jpg"
}
# 分割到文件块
split_to_chunk_file(){
echo "chunk file : $1"
local filePath=$1
local fileName=$(basename "$filePath")
if [[ -z $filePath || ! -f $filePath ]];then
echo "filePath not found!"
exit
fi
fileSize=$(du -b $filePath | awk '{print $1}')
echo "The filesize is:$fileSize"
echo "chunk size is: $chunkBytesSize"
subFileNum=$(expr $fileSize / $(expr $chunkBytesSize \* 1024 ))
if [ $(expr $fileSize % $chunkBytesSize) -ne 0 ];then
subFileNum=$(expr $subFileNum + 1)
fi
echo "sub file number: $subFileNum"
echo "$fileName will be divided into $subFileNum"
local i=1
local skipnum=0
while [ $i -le $subFileNum ]
do
echo "$fileName$i"
dd if=$filePath of="$outPath/$fileName.$i" bs=1024 count=$chunkBytesSize skip=$skipnum
i=$(expr $i + 1)
skipnum=$(expr $skipnum + $chunkBytesSize)
done
echo "$fileName has been divided into $subFileNum"
i=1
echo -e "fileName=$fileName\nfileSize=$fileSize\nchunkBytesSize=$chunkBytesSize\nsubFileNum=$subFileNum" > "$fileName.fbi"
while [ $i -le $subFileNum ]
do
echo "disguised as a image: $outPath/$fileName.$i"
fakeImage=$(disguised_as_image "$outPath/$fileName.$i")
fakeImageUrl=$(upload_image "$fakeImage")
echo "splitFiles[$i]=$fakeImageUrl" >> "$fileName.fbi"
# delete temp file
rm -f "$fakeImage" "$outPath/$fileName.$i"
i=$(expr $i + 1)
done
echo "Done !"
}
# 恢复备份文件
recover_backup_file(){
fbHeadFile=$1
source $fbHeadFile
if [ -z $fileName ];then
echo "Invalid meta information file!"
exit 1
fi
echo $fileName;
realfileSize=$(du -b $realImage | awk '{print $1}')
i=1
rm -f "$outPath/finish.tmp"
touch "$outPath/finish.tmp"
while [ $i -le $subFileNum ]
do
packFileUrl=${splitFiles[$i]}
echo $packFileUrl
wget $packFileUrl -O "$outPath/tmp.$i"
dd if="$outPath/tmp.$i" of="$outPath/tmp.output.$i" bs=$realfileSize skip=1
cat "$outPath/finish.tmp" "$outPath/tmp.output.$i" > "$outPath/finish.tmp2"
mv "$outPath/finish.tmp2" "$outPath/finish.tmp"
rm -f "$outPath/tmp.output.$i" "$outPath/tmp.$i"
i=$(expr $i + 1)
done
mv "$outPath/finish.tmp" "$outPath/$fileName"
}
if [[ -z $action || -z $filePath ]];then
echo "Usage: ./backup.sh [ACTION] [FILENAME]"
echo ""
echo -e "./backup.sh upload pyinstall.exe \t backup file to cloud"
echo -e "./backup.sh download pyinstall.exe.fbi \t recover backup file from cloud"
exit 1
fi
if [ ! -f $filePath ];then
echo "$filePath: not exist!"
exit 1
fi
if [ ! -f $realImage ];then
echo "$realImage: not exist!"
exit 1
fi
if [ ! -d $outPath ];then
mkdir $outPath
fi
if [ $action == "upload" ];then
split_to_chunk_file $filePath
elif [ $action == "download" ];then
recover_backup_file $filePath
fi
# 备份文件
# ./backup.sh upload pyinstall.exe
# 恢复文件
# ./backup.sh download pyinstall.exe.fbi