Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
Expand All @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions fixtures/etcd-configuration.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down