Check if dataset exist, create dataset
This commit is contained in:
parent
74602dc0df
commit
abaa4a11f9
28
cmd/utils.go
28
cmd/utils.go
@ -4,7 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
//"log"
|
||||||
"sort"
|
"sort"
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
@ -15,6 +15,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
"github.com/c2h5oh/datasize"
|
"github.com/c2h5oh/datasize"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -411,6 +412,31 @@ func zfsCopyIncremental(firstsnap string, secondsnap string, dest string) error
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return true if dataset exist, false if not, false & error if anything else
|
||||||
|
func doZfsDatasetExist(dataset string) (bool, error) {
|
||||||
|
cmd := fmt.Sprintf("zfs list %s", dataset)
|
||||||
|
out, err := executeCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
if strings.HasSuffix(strings.TrimSuffix(out, "\n"), "dataset does not exist") {
|
||||||
|
return false, nil
|
||||||
|
} else {
|
||||||
|
return false, errors.New(fmt.Sprintf("%v; command returned \"%s\"", err, out))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create ZFS dataset. mountpoint can be "none", then the dataset won't be mounted
|
||||||
|
func createZfsDataset(dataset, mountpoint, compression string) error {
|
||||||
|
cmd := fmt.Sprintf("zfs create -o mountpoint=%s -o compression=%s %s", mountpoint, compression, dataset)
|
||||||
|
out, err := executeCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New(fmt.Sprintf("%v; command returned \"%s\"", err, out))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* rc.conf management
|
* rc.conf management
|
||||||
|
Loading…
Reference in New Issue
Block a user