diff --git a/README.md b/README.md index 6b85aea..5bb4eb9 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ Usage of ./duetbackup: Directory on Duet to create a backup of (default "0:/sys") -domain string Domain of Duet Wifi - -keepLocal - Keep files locally that have been deleted on the Duet -outDir string Output dir of backup -password string Connection password (default "reprap") -port uint Port of Duet Wifi (default 80) + -removeLocal + Remove files locally that have been deleted on the Duet ``` diff --git a/duetbackup.go b/duetbackup.go index 04f31a2..e3b35a3 100644 --- a/duetbackup.go +++ b/duetbackup.go @@ -115,7 +115,7 @@ func getFileList(baseURL string, dir string, first uint64) (*filelist, error) { return &fl, nil } -func updateLocalFiles(baseURL string, fl *filelist, outDir string, keepLocal bool) error { +func updateLocalFiles(baseURL string, fl *filelist, outDir string, removeLocal bool) error { fileDownloadURL := "rr_download?name=" + url.QueryEscape(fl.Dir+"/") @@ -138,7 +138,7 @@ func updateLocalFiles(baseURL string, fl *filelist, outDir string, keepLocal boo } // Go recursively into this directory - if err = syncFolder(baseURL, fl.Dir+"/"+file.Name, fileName, keepLocal); err != nil { + if err = syncFolder(baseURL, fl.Dir+"/"+file.Name, fileName, removeLocal); err != nil { return err } continue @@ -212,7 +212,7 @@ func removeDeletedFiles(fl *filelist, outDir string) error { return nil } -func syncFolder(address, folder, outDir string, keepLocal bool) error { +func syncFolder(address, folder, outDir string, removeLocal bool) error { log.Println("Fetching filelist for", folder) fl, err := getFileList(address, url.QueryEscape(folder), 0) if err != nil { @@ -220,11 +220,11 @@ func syncFolder(address, folder, outDir string, keepLocal bool) error { } log.Println("Checking files to be downloaded from", folder) - if err = updateLocalFiles(address, fl, outDir, keepLocal); err != nil { + if err = updateLocalFiles(address, fl, outDir, removeLocal); err != nil { return err } - if !keepLocal { + if removeLocal { log.Println("Checking no longer existing files in", outDir) if err = removeDeletedFiles(fl, outDir); err != nil { return err @@ -246,7 +246,7 @@ func connect(address, password string) error { func main() { var domain, dirToBackup, outDir, password string - var keepLocal bool + var removeLocal bool var port uint64 flag.StringVar(&domain, "domain", "", "Domain of Duet Wifi") @@ -254,7 +254,7 @@ func main() { flag.StringVar(&dirToBackup, "dirToBackup", sysDir, "Directory on Duet to create a backup of") flag.StringVar(&outDir, "outDir", "", "Output dir of backup") flag.StringVar(&password, "password", "reprap", "Connection password") - flag.BoolVar(&keepLocal, "keepLocal", false, "Keep files locally that have been deleted on the Duet") + flag.BoolVar(&removeLocal, "removeLocal", false, "Remove files locally that have been deleted on the Duet") flag.Parse() if domain == "" || outDir == "" { @@ -270,7 +270,7 @@ func main() { os.Exit(0) } - err := syncFolder(address, dirToBackup, outDir, keepLocal) + err := syncFolder(address, dirToBackup, outDir, removeLocal) if err != nil { log.Fatal(err) os.Exit(1)