Skip to content

Commit

Permalink
Added CLI build script, handle authentication error
Browse files Browse the repository at this point in the history
  • Loading branch information
tizbac committed Dec 20, 2023
1 parent 53b0ef3 commit 74feacf
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 138 deletions.
3 changes: 3 additions & 0 deletions build_cli.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set CGO_ENABLED=1
set GOOS=windows
go build -o proxmoxbackupgo_cli.exe
19 changes: 16 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,17 @@ func main() {
f2.Write(previous_didx)*/

/*
Here we download the previous dynamic index to figure out which chunks are the same of what
we are going to upload to avoid unnecessary traffic and compression cpu usage
*/

if !bytes.HasPrefix(previous_didx, didxMagic) {
fmt.Printf("Previous index has wrong magic (%s)!\n", previous_didx[:8])

} else {

//Header as per proxmox documentation is fixed size of 4096 bytes,
//then offset of type uint64 and sha256 digests follow , so 40 byte each record until EOF
previous_didx = previous_didx[4096:]
for i := 0; i*40 < len(previous_didx); i += 1 {
e := DidxEntry{}
Expand Down Expand Up @@ -155,7 +161,7 @@ func main() {
A.writeCB = func(b []byte) {
chunkpos := PXAR_CHK.C.Scan(b)

if chunkpos > 0 {
if chunkpos > 0 { //We test if cyclic polynomial hash returned the expected value for chunk boundary
for chunkpos > 0 {

PXAR_CHK.current_chunk = append(PXAR_CHK.current_chunk, b[:chunkpos]...)
Expand Down Expand Up @@ -224,8 +230,14 @@ func main() {
PCAT1_CHK.current_chunk = append(PCAT1_CHK.current_chunk, b...)
}
}

//This is the entry point of backup job which will start streaming with the PCAT and PXAR write callback
//Data to be hashed and eventuall uploaded

A.WriteDir(backupdir, "", true)

//Here we write the remainder of data for which cyclic hash did not trigger

if len(PXAR_CHK.current_chunk) > 0 {
h := sha256.New()
h.Write(PXAR_CHK.current_chunk)
Expand Down Expand Up @@ -263,7 +275,7 @@ func main() {
client.UploadCompressedChunk(PCAT1_CHK.wrid, shahash, PCAT1_CHK.current_chunk)
}

//Avoid incurring in request entity too large
//Avoid incurring in request entity too large by chunking assignment PUT requests in blocks of at most 128 chunks
for k := 0; k < len(PXAR_CHK.assignments); k += 128 {
k2 := k + 128
if k2 > len(PXAR_CHK.assignments) {
Expand All @@ -289,6 +301,7 @@ func main() {

fmt.Printf("New %d , Reused %d\n", newchunk, reusechunk)

//Remove VSS snapshot on windows, on linux for now NOP
VSSCleanup()
if runtime.GOOS == "windows" {
systray.Quit()
Expand Down
17 changes: 17 additions & 0 deletions pbsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ type BackupManifest struct {
Unprotected Unprotected `json:"unprotected"`
}

type AuthErr struct {
}

func (e *AuthErr) Error() string {
return "Authentication error"
}

type PBSClient struct {
baseurl string
certfingerprint string
Expand Down Expand Up @@ -384,6 +391,16 @@ func (pbs *PBSClient) Connect(reader bool) {

//fmt.Println(string(b2))
}
lines := strings.Split(string(buf), "\n")

if len(lines) > 0 {
toks := strings.Split(lines[0], " ")
if len(toks) > 1 && toks[1] != "101" {
fmt.Println("Unexpected response code: " + strings.Join(toks[1:], " "))
return nil, &AuthErr{}
}
}

fmt.Printf("Upgraderesp: %s\n", string(buf))
fmt.Println("Successfully upgraded to HTTP/2.")
return conn, nil
Expand Down
Loading

0 comments on commit 74feacf

Please sign in to comment.