From 12d1f4f69f4583659831c630d8b7a9afe47a4e5c Mon Sep 17 00:00:00 2001 From: Anders Brander Date: Thu, 25 Jun 2015 14:02:19 +0200 Subject: [PATCH 1/4] Added config file option for disabling cluster sync. --- config.go | 2 ++ main.go | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) 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/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 From 92ac7151568374d57bfd66c679009aeb21e98b3c Mon Sep 17 00:00:00 2001 From: Anders Brander Date: Thu, 25 Jun 2015 14:05:55 +0200 Subject: [PATCH 2/4] Changed default etcd entry point to localhost:2379 (and removed traling slash). --- fixtures/etcd-configuration.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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": { From 993b176746e9fa6d5482acdf9da3b2389278a022 Mon Sep 17 00:00:00 2001 From: Anders Brander Date: Wed, 12 Aug 2015 07:28:38 +0200 Subject: [PATCH 3/4] Restore TTL as seconds instead of nanoseconds. --- backup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup.go b/backup.go index c38ce73..7b2c8e5 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 } From 86782d043ef50c72956b91b869f6f556117d336d Mon Sep 17 00:00:00 2001 From: Anders Brander Date: Mon, 28 Sep 2015 12:52:59 +0200 Subject: [PATCH 4/4] Create backup dump using O_TRUNC. --- backup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup.go b/backup.go index 7b2c8e5..3e08851 100644 --- a/backup.go +++ b/backup.go @@ -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)