mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 16:34:32 +01:00
bookmark every snapshot
replication logic already supports bookmarks \o/ refs #34
This commit is contained in:
parent
51af880701
commit
ed68bffea5
@ -129,14 +129,21 @@ func (a *IntervalAutosnap) doSnapshots(didSnaps chan struct{}) {
|
|||||||
suffix := time.Now().In(time.UTC).Format("20060102_150405_000")
|
suffix := time.Now().In(time.UTC).Format("20060102_150405_000")
|
||||||
snapname := fmt.Sprintf("%s%s", a.Prefix, suffix)
|
snapname := fmt.Sprintf("%s%s", a.Prefix, suffix)
|
||||||
|
|
||||||
a.log.WithField(logFSField, d.ToString()).
|
l := a.log.WithField(logFSField, d.ToString()).
|
||||||
WithField("snapname", snapname).
|
WithField("snapname", snapname)
|
||||||
Info("create snapshot")
|
|
||||||
|
|
||||||
|
l.Info("create snapshot")
|
||||||
err := zfs.ZFSSnapshot(d, snapname, false)
|
err := zfs.ZFSSnapshot(d, snapname, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.WithError(err).Error("cannot create snapshot")
|
a.log.WithError(err).Error("cannot create snapshot")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l.Info("create corresponding bookmark")
|
||||||
|
err = zfs.ZFSBookmark(d, snapname, snapname)
|
||||||
|
if err != nil {
|
||||||
|
a.log.WithError(err).Error("cannot create bookmark")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@ -46,6 +46,7 @@ func (p *Pruner) Run(ctx context.Context) (r []PruneResult, err error) {
|
|||||||
|
|
||||||
log := log.WithField(logFSField, fs.ToString())
|
log := log.WithField(logFSField, fs.ToString())
|
||||||
|
|
||||||
|
// only prune snapshots, bookmarks are kept forever
|
||||||
snapshotFilter := NewTypedPrefixFilter(p.SnapshotPrefix, zfs.Snapshot)
|
snapshotFilter := NewTypedPrefixFilter(p.SnapshotPrefix, zfs.Snapshot)
|
||||||
fsversions, err := zfs.ZFSListFilesystemVersions(fs, snapshotFilter)
|
fsversions, err := zfs.ZFSListFilesystemVersions(fs, snapshotFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
35
zfs/zfs.go
35
zfs/zfs.go
@ -286,9 +286,17 @@ func ZFSDestroy(dataset string) (err error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func zfsBuildSnapName(fs *DatasetPath, name string) string { // TODO defensive
|
||||||
|
return fmt.Sprintf("%s@%s", fs.ToString(), name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func zfsBuildBookmarkName(fs *DatasetPath, name string) string { // TODO defensive
|
||||||
|
return fmt.Sprintf("%s#%s", fs.ToString(), name)
|
||||||
|
}
|
||||||
|
|
||||||
func ZFSSnapshot(fs *DatasetPath, name string, recursive bool) (err error) {
|
func ZFSSnapshot(fs *DatasetPath, name string, recursive bool) (err error) {
|
||||||
|
|
||||||
snapname := fmt.Sprintf("%s@%s", fs.ToString(), name)
|
snapname := zfsBuildSnapName(fs, name)
|
||||||
cmd := exec.Command(ZFS_BINARY, "snapshot", snapname)
|
cmd := exec.Command(ZFS_BINARY, "snapshot", snapname)
|
||||||
|
|
||||||
stderr := bytes.NewBuffer(make([]byte, 0, 1024))
|
stderr := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
@ -308,3 +316,28 @@ func ZFSSnapshot(fs *DatasetPath, name string, recursive bool) (err error) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ZFSBookmark(fs *DatasetPath, snapshot, bookmark string) (err error) {
|
||||||
|
|
||||||
|
snapname := zfsBuildSnapName(fs, snapshot)
|
||||||
|
bookmarkname := zfsBuildBookmarkName(fs, bookmark)
|
||||||
|
|
||||||
|
cmd := exec.Command(ZFS_BINARY, "bookmark", snapname, bookmarkname)
|
||||||
|
|
||||||
|
stderr := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
|
cmd.Stderr = stderr
|
||||||
|
|
||||||
|
if err = cmd.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = cmd.Wait(); err != nil {
|
||||||
|
err = ZFSError{
|
||||||
|
Stderr: stderr.Bytes(),
|
||||||
|
WaitErr: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user