494 字
2 分钟
利用API添加虚拟机到备份组
问题
这边开始用rubrik来替换vdp做虚拟机备份。
其实我个人觉得vdp也挺好用的,但是场景就是vdp的备份限于本地存储,而rubrik可以备份到Azure和GCP上面去。相当于跨到云上去了,增加了一点可靠性。
介于rubrik在选择虚拟机到时候比较的麻烦,所以利用它提供的API调用后,直接将要备份的虚拟机加入到指定的备份组里面去,应用备份策略。
解决
- 这里用了rubrik提供的go语言接口
- 可以在这里看看 “github.com/rubrikinc/rubrik-sdk-for-go/rubrikcdm”
我的代码结构:

其中rubrik-functions.go是一些功能函数包,包括写的添加vm到SLA策略的函数,列出受保护的虚拟机的函数,检查虚拟机名是否正确的函数。
template是为了提供web界面,做的rubrik.html的页面。
main.go就是主文件了。下面给出比较结构性的部分。
就是验证,验证完了就是操作,操作好了,给个提示。
就是这样,打完收工。
package main
import ( "fmt" "html/template" "log" "net/http"
Md "./rubrikmd" //这样的结构便于引用 "gopkg.in/gomail.v2" //发邮件的模块,用于提醒加入成功 auth "gopkg.in/korylprince/go-ad-auth.v2" //验证模块,用于验证操作人是否有权限)
const ( host = "0.0.0.0" port = "8084")
// Webshow 用于增加vm到受保护的策略中func Webshow(w http.ResponseWriter, r *http.Request) { r.ParseForm() if r.Method == "GET" { t, _ := template.ParseFiles("./templates/rubik.html") t.Execute(w, nil) } else if r.Method == "POST" { vmname := r.Form.Get("vmname") netid := r.Form.Get("account") password := r.Form.Get("password") if len(netid) == 0 { fmt.Fprintf(w, "You must fill your netid correctly!") } if len(password) == 0 { fmt.Fprint(w, "Check your password,please!") }
config := &auth.Config{ Server: "dc01.test.local", Port: 389, BaseDN: "OU=example,OU=USERS,OU=ACCTS,dc=test,dc=local", Security: auth.SecurityNone, }
status, err := auth.Authenticate(config, netid, password) if err != nil { fmt.Fprint(w, "login failed! You should check your network first!") } else { if !status { fmt.Fprintf(w, "login failed! please double check your account and password!") } else { if Md.Detect(vmname) != nil { fmt.Fprintf(w, "the VM cannot found! please double check and try again!") } else { Md.AddVMintoProtect(vmname, "ProtectPolies30days") fmt.Fprint(w, "Your request is accepted!")
利用API添加虚拟机到备份组
https://dididudu998.github.io/posts/利用api添加虚拟机到备份组/