Beispiel #1
0
// Snapshots returns the current snapshots on the volume (sorted by date)
func (c *BtrfsConn) Snapshots() ([]string, error) {
	c.Lock()
	defer c.Unlock()

	glog.V(2).Infof("listing snapshots of volume:%v and c.name:%s ", c.root, c.name)
	output, err := runcmd(c.sudoer, "subvolume", "list", "-s", c.root)
	if err != nil {
		glog.Errorf("Could not list subvolumes of %s: %s", c.root, err)
		return nil, err
	}

	var files []os.FileInfo
	for _, line := range strings.Split(string(output), "\n") {
		glog.V(2).Infof("line: %s", line)
		if parts := strings.Split(line, "path"); len(parts) == 2 {
			label := strings.TrimSpace(parts[1])
			label = strings.TrimPrefix(label, "volumes/")
			glog.V(2).Infof("looking for tenant:%s in label:'%s'", c.name, label)
			if strings.HasPrefix(label, c.name+"_") {
				file, err := os.Stat(filepath.Join(c.root, label))
				if err != nil {
					glog.Errorf("Could not stat snapshot %s: %s", label, err)
					return nil, err
				}
				files = append(files, file)
				glog.V(2).Infof("found snapshot:%s", label)
			}
		}
	}

	return volume.FileInfoSlice(files).Labels(), nil
}
Beispiel #2
0
// Snapshots returns the current snapshots on the volume
func (c *RsyncConn) Snapshots() ([]string, error) {
	c.Lock()
	defer c.Unlock()

	files, err := ioutil.ReadDir(c.root)
	if err != nil {
		return nil, err
	}

	var labels []os.FileInfo
	for _, file := range files {
		if file.IsDir() {
			if strings.HasPrefix(file.Name(), c.name+"_") {
				labels = append(labels, file)
			}
		}
	}

	return volume.FileInfoSlice(labels).Labels(), nil
}