-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackUp.go
70 lines (61 loc) · 1.7 KB
/
backUp.go
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
package GoLib
import (
"strings"
"time"
)
//主要获取备份字典
//获取字典前缀
func getBackUpSuffix() []string {
return []string{"gz", "sql", "bak", "log", "old", "tar.gz", "tar.tgz", "rar", "zip", "tar.bz2", "7z", "sql~", "sql.gz", "tar.7z", "tar.xz", "sql.zip"}
}
//年份的备份,一般都是5
func getYearPrefix(num int) (result []string) {
year := time.Now().Year()
for i := 0; i <= num; i++ {
result = append(result, Int2Str(year-i))
}
year = 0
return
}
//域名的备份
func getDomainPrefix(url string) (result []string) {
domain := GetDomain(url)
//ip就只添加ip即可
if IsIp(domain) == false {
//直接把域名丢进去的形式
result = append(result, domain)
domains := strings.Split(domain, ".")
//最简单的分割加入
for _, d := range domains {
result = append(result, d)
}
//直接字符串拼接的形式
for k, _ := range domains {
result = append(result, strings.Join(domains[k:], "."))
result = append(result, strings.Join(domains[k:], "-"))
result = append(result, strings.Join(domains[k:], "_"))
}
} else {
result = append(result, domain)
}
domain = ""
return
}
//获取字典后缀
func getBackUpPrefix(url string) []string {
result := []string{"bbs", "web", "www", "forum", "backup", "wwwroot", "upload", "0", "1", "123", "temp", "website", "db", "data", "code", "oa", "sysadmin", "test", "新建文件夹", "database", "user", "shopping", "sql"}
return result
}
//获取备份字典
func GetBackUpDict(url string) (result []string) {
suffix := getBackUpSuffix()
prefix := getBackUpPrefix(url)
for _, p := range prefix {
for _, s := range suffix {
result = append(result, p+"."+s)
}
}
suffix = nil
prefix = nil
return
}