Any Golang Alternative/API for backup CLI command


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 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)


	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
    ctx := context.Background()
    err = os.MkdirAll(fileStorePath, 0777)
	if err != nil && !os.IsExist(err) {
		return nil,err

	backupService, err := newBackupService()
	if err != nil {
		return nil,err

	id, backupFilenames, err := backupService.CreateBackup(ctx)
	if err != nil {
		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:

(.....some path......)
Failed to establish connection with InfluxDB:2020/05/19 13:47:25 app.Run: 404 page not found

Kindly help

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.