diff --git a/backup.go b/backup.go index c38ce73..3e08851 100644 --- a/backup.go +++ b/backup.go @@ -33,7 +33,7 @@ func (bacupKey *BackupKey) IsDirectory() (isDirectory bool) { func (bacupKey *BackupKey) IsExpired() (isExpired bool) { if bacupKey.Expiration != nil { - bacupKey.TTL = int64(bacupKey.Expiration.Sub(time.Now().UTC())) + bacupKey.TTL = int64(bacupKey.Expiration.Sub(time.Now().UTC()).Seconds()) isExpired = bacupKey.TTL <= 0 } @@ -115,7 +115,7 @@ func DumpDataSet(dataSet []*BackupKey, dumpFilePath string) { config.LogFatal("Error when trying to encode data set into json. Error: ", err) } - file, error := os.OpenFile(dumpFilePath, os.O_WRONLY|os.O_CREATE, 0666) + file, error := os.OpenFile(dumpFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) defer file.Close() if error != nil { config.LogFatal("Error when trying to open the file `"+dumpFilePath+"`. Error: ", error) diff --git a/config.go b/config.go index cdf1696..cadaefe 100644 --- a/config.go +++ b/config.go @@ -14,6 +14,7 @@ type Config struct { EtcdConfigPath string `json:"etcdConfigPath,omitempty"` DumpFilePath string `json:"dumpFilePath,omitempty"` BackupStrategy *BackupStrategy `json:"backupStrategy,omitempty"` + SyncCluster bool `json:"syncCluster,omitempty"` LogFatal func(v ...interface{}) LogPrintln func(v ...interface{}) } @@ -30,6 +31,7 @@ func (config *Config) ToString() string { stringVersion += ", EtcdConfigPath: " + config.EtcdConfigPath stringVersion += ", DumpFilePath: " + config.DumpFilePath stringVersion += ", BackupStrategy: " + fmt.Sprintf("%#v", config.BackupStrategy) + stringVersion += ", SyncCluster: " + fmt.Sprintf("%#v", config.SyncCluster) return stringVersion } diff --git a/fixtures/etcd-configuration.json b/fixtures/etcd-configuration.json index 31811a2..8f3a602 100644 --- a/fixtures/etcd-configuration.json +++ b/fixtures/etcd-configuration.json @@ -1,10 +1,8 @@ { "cluster": { - "leader": "http://my-leader.com:4001/", + "leader": "http://127.0.0.1:2379", "machines": [ - "http://my-follower1.com:4001/", - "http://my-follower2.com:4001/", - "http://my-follower3.com:4001/" + "http://127.0.0.1:2379" ] }, "config": { diff --git a/main.go b/main.go index e82db29..9758435 100644 --- a/main.go +++ b/main.go @@ -27,9 +27,11 @@ func initializeClient(configFilePath string) *etcd.Client { config.LogFatal("Error when trying to load the configuration file: `"+configFilePath+"`. Error: ", error) } - success := etcdClient.SyncCluster() - if !success { - config.LogFatal("cannot sync machines") + if config.SyncCluster { + success := etcdClient.SyncCluster() + if !success { + config.LogFatal("cannot sync machines") + } } return etcdClient