Skip to content

Commit

Permalink
Group 'kopia snapshot' commands in single file
Browse files Browse the repository at this point in the history
  • Loading branch information
shlokc9 committed Aug 23, 2022
1 parent 98b5b38 commit 75d1885
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions pkg/kopia/command/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,95 @@ func SnapshotCreate(snapshotCreateArgs SnapshotCreateCommandArgs) []string {

return stringSliceCommand(args)
}

type SnapshotRestoreCommandArgs struct {
*CommandArgs
SnapID string
TargetPath string
SparseRestore bool
}

// SnapshotRestore returns kopia command restoring snapshots with given snap ID
func SnapshotRestore(snapshotRestoreArgs SnapshotRestoreCommandArgs) []string {
args := commonArgs(snapshotRestoreArgs.EncryptionKey, snapshotRestoreArgs.ConfigFilePath, snapshotRestoreArgs.LogDirectory, false)
args = args.AppendLoggable(snapshotSubCommand, restoreSubCommand, snapshotRestoreArgs.SnapID, snapshotRestoreArgs.TargetPath)
if snapshotRestoreArgs.SparseRestore {
args = args.AppendLoggable(sparseFlag)
}

return stringSliceCommand(args)
}

type SnapshotDeleteCommandArgs struct {
*CommandArgs
SnapID string
}

// SnapshotDelete returns the kopia command for deleting a snapshot with given snapshot ID
func SnapshotDelete(snapshotDeleteArgs SnapshotDeleteCommandArgs) []string {
args := commonArgs(snapshotDeleteArgs.EncryptionKey, snapshotDeleteArgs.ConfigFilePath, snapshotDeleteArgs.LogDirectory, false)
args = args.AppendLoggable(snapshotSubCommand, deleteSubCommand, snapshotDeleteArgs.SnapID, unsafeIgnoreSourceFlag)

return stringSliceCommand(args)
}

type SnapshotExpireCommandArgs struct {
*CommandArgs
RootID string
MustDelete bool
}

// SnapshotExpire returns the kopia command for removing snapshots with given root ID
func SnapshotExpire(snapshotExpireArgs SnapshotExpireCommandArgs) []string {
args := commonArgs(snapshotExpireArgs.EncryptionKey, snapshotExpireArgs.ConfigFilePath, snapshotExpireArgs.LogDirectory, false)
args = args.AppendLoggable(snapshotSubCommand, expireSubCommand, snapshotExpireArgs.RootID)
if snapshotExpireArgs.MustDelete {
args = args.AppendLoggable(deleteFlag)
}

return stringSliceCommand(args)
}

type SnapshotGCCommandArgs struct {
*CommandArgs
}

// SnapshotGC returns the kopia command for issuing kopia snapshot gc
func SnapshotGC(snapshotGCArgs SnapshotGCCommandArgs) []string {
args := commonArgs(snapshotGCArgs.EncryptionKey, snapshotGCArgs.ConfigFilePath, snapshotGCArgs.LogDirectory, false)
args = args.AppendLoggable(snapshotSubCommand, gcSubCommand, deleteFlag)

return stringSliceCommand(args)
}

type SnapListAllCommandArgs struct {
*CommandArgs
}

// SnapListAll returns the kopia command for listing all snapshots in the repository with their sizes
func SnapListAll(snapListAllArgs SnapListAllCommandArgs) []string {
args := commonArgs(snapListAllArgs.EncryptionKey, snapListAllArgs.ConfigFilePath, snapListAllArgs.LogDirectory, false)
args = args.AppendLoggable(
snapshotSubCommand,
listSubCommand,
allFlag,
deltaFlag,
showIdenticalFlag,
jsonFlag,
)

return stringSliceCommand(args)
}

type SnapListAllWithSnapIDsCommandArgs struct {
*CommandArgs
}

// SnapListAllWithSnapIDs returns the kopia command for listing all snapshots in the repository with snapshotIDs
func SnapListAllWithSnapIDs(snapListAllWithSnapIDsArgs SnapListAllWithSnapIDsCommandArgs) []string {
args := commonArgs(snapListAllWithSnapIDsArgs.EncryptionKey, snapListAllWithSnapIDsArgs.ConfigFilePath, snapListAllWithSnapIDsArgs.LogDirectory, false)
args = args.AppendLoggable(manifestSubCommand, listSubCommand, jsonFlag)
args = args.AppendLoggableKV(filterFlag, kopia.ManifestTypeSnapshotFilter)

return stringSliceCommand(args)
}

0 comments on commit 75d1885

Please sign in to comment.