influxdata / influxdata/influxdb

Any Golang Alternative/API for backup CLI command

Open
#18,162 1 comment 0 reactions 0 assignees View on GitHub
1.x
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

Hi!

I am trying to programatically take backup of InfluxDB to another server using golang.

I am able to do that via command line function of golang as follows:
```
cmd := exec.Command(configInfluxDB.InfluxdExeutablePath, "backup", "-portable", "-database", configInfluxDB.Database, "-host", configInfluxDB.HostName+":8088", fileStorePath)
```

However, I am unable to find any golang api function for the same purpose.

I would like to know similar function which could take the parameters path , database , host and file path and then take the backup

I tried using the backend functions defined in [https://github.com/influxdata/influxdb/blob/master/cmd/influx/backup.go](url) as follows:

```
func newBackupService() (influxdb.BackupService, error) {
return &http.BackupService{
Addr: "http://localhost:8086",
Token: "admin:admin",
}, nil
}

func ConnectToDB(fullFileName string) (*InfluxReader, error) {
// Read InfluxDB instance's properties from an external file.
configInfluxDB, err := loadInfluxProperty(fullFileName)

fmt.Println("hello")

HTTPAddr := fmt.Sprintf("http://%s:%s",configInfluxDB.HostName, configInfluxDB.PortNumber)
c, _ := client.NewHTTPClient(client.HTTPConfig{
Addr: HTTPAddr,
Username: configInfluxDB.UserName,
Password: configInfluxDB.Password,
})
_, _, err = c.Ping(0)
if err != nil {
log.Fatal("Error creating InfluxDB Client: ", err.Error())
}
defer c.Close()

var slash = ""
if string(os.TempDir()[0]) == "C" {
slash = "\\"
} else {
slash = "/"
}
fileStorePath := os.TempDir() + slash + configInfluxDB.Database
fmt.Println(fileStorePath)

ctx := context.Background()

err = os.MkdirAll(fileStorePath, 0777)
if err != nil && !os.IsExist(err) {
fmt.Println("e1")
return nil,err
}

backupService, err := newBackupService()
if err != nil {
fmt.Println("e2")
return nil,err
}

id, backupFilenames, err := backupService.CreateBackup(ctx)
if err != nil {
fmt.Println("e3")
return nil,err
}

fmt.Printf("Backup ID %d contains %d files\n", id, len(backupFilenames))
fmt.Printf("Backup complete")

var files []string
err = filepath.Walk(fileStorePath, visit(&files))
if err != nil {
fmt.Println("Could not store file names:", err)
return nil, err
}
return &InfluxReader{ConfigInfluxDB: configInfluxDB,File: files,Path: fileStorePath}, err
}
```

On running the code, the output is:
```
hello
(.....some path......)
e3
Failed to establish connection with InfluxDB:2020/05/19 13:47:25 app.Run: 404 page not found
```

Kindly help
Thanks

Contributor guide

Open the contributing guide

Research direction

Start with cmd/influx/backup.go and the BackupService implementation used by newBackupService. Reproduce the 404 from CreateBackup and compare the service address and endpoint with the command-line backup path. Done would mean establishing whether a supported Go API exists and documenting or implementing a working way to provide the requested backup parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.