mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-24 11:09:12 +08:00
weed backup: add ttl and replication parameter
This commit is contained in:
parent
f9c1cd7370
commit
5904d78bd4
@ -17,10 +17,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BackupOptions struct {
|
type BackupOptions struct {
|
||||||
master *string
|
master *string
|
||||||
collection *string
|
collection *string
|
||||||
dir *string
|
dir *string
|
||||||
volumeId *int
|
volumeId *int
|
||||||
|
ttl *string
|
||||||
|
replication *string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -29,6 +31,15 @@ func init() {
|
|||||||
s.collection = cmdBackup.Flag.String("collection", "", "collection name")
|
s.collection = cmdBackup.Flag.String("collection", "", "collection name")
|
||||||
s.dir = cmdBackup.Flag.String("dir", ".", "directory to store volume data files")
|
s.dir = cmdBackup.Flag.String("dir", ".", "directory to store volume data files")
|
||||||
s.volumeId = cmdBackup.Flag.Int("volumeId", -1, "a volume id. The volume .dat and .idx files should already exist in the dir.")
|
s.volumeId = cmdBackup.Flag.Int("volumeId", -1, "a volume id. The volume .dat and .idx files should already exist in the dir.")
|
||||||
|
s.ttl = cmdBackup.Flag.String("ttl", "", `backup volume's time to live, format:
|
||||||
|
3m: 3 minutes
|
||||||
|
4h: 4 hours
|
||||||
|
5d: 5 days
|
||||||
|
6w: 6 weeks
|
||||||
|
7M: 7 months
|
||||||
|
8y: 8 years
|
||||||
|
default is the same with origin`)
|
||||||
|
s.replication = cmdBackup.Flag.String("replication", "", "backup volume's replication, default is the same with origin")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdBackup = &Command{
|
var cmdBackup = &Command{
|
||||||
@ -73,17 +84,34 @@ func runBackup(cmd *Command, args []string) bool {
|
|||||||
fmt.Printf("Error get volume %d status: %v\n", vid, err)
|
fmt.Printf("Error get volume %d status: %v\n", vid, err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
ttl, err := needle.ReadTTL(stats.Ttl)
|
var ttl *needle.TTL
|
||||||
if err != nil {
|
if *s.ttl != "" {
|
||||||
fmt.Printf("Error get volume %d ttl %s: %v\n", vid, stats.Ttl, err)
|
ttl, err = needle.ReadTTL(*s.ttl)
|
||||||
return true
|
if err != nil {
|
||||||
|
fmt.Printf("Error generate volume %d ttl %s: %v\n", vid, *s.ttl, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ttl, err = needle.ReadTTL(stats.Ttl)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error get volume %d ttl %s: %v\n", vid, stats.Ttl, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
replication, err := storage.NewReplicaPlacementFromString(stats.Replication)
|
var replication *storage.ReplicaPlacement
|
||||||
if err != nil {
|
if *s.replication != "" {
|
||||||
fmt.Printf("Error get volume %d replication %s : %v\n", vid, stats.Replication, err)
|
replication, err = storage.NewReplicaPlacementFromString(*s.replication)
|
||||||
return true
|
if err != nil {
|
||||||
|
fmt.Printf("Error generate volume %d replication %s : %v\n", vid, *s.replication, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
replication, err = storage.NewReplicaPlacementFromString(stats.Replication)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error get volume %d replication %s : %v\n", vid, stats.Replication, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err := storage.NewVolume(*s.dir, *s.collection, vid, storage.NeedleMapInMemory, replication, ttl, 0)
|
v, err := storage.NewVolume(*s.dir, *s.collection, vid, storage.NeedleMapInMemory, replication, ttl, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error creating or reading from volume %d: %v\n", vid, err)
|
fmt.Printf("Error creating or reading from volume %d: %v\n", vid, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user