From 1342d5ffc3a6d7b7d8e55fde91d0b09a442c1087 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Thu, 28 Mar 2019 08:43:21 -0400 Subject: [PATCH] Add the timestamp when creating the backup file (#11034) Fixes: #10031 --- CHANGELOG.next.asciidoc | 1 + x-pack/libbeat/management/enroll.go | 5 ++++- x-pack/libbeat/tests/system/test_management.py | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index b8b65e1c137e..24d9c6324d22 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -152,6 +152,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Report faulting file when config reload fails. {pull}[11304]11304 - Remove IP fields from default_field in Elasticsearch template. - Fix a typo in libbeat/outputs/transport/client.go by updating `c.conn.LocalAddr()` to `c.conn.RemoteAddr()`. {pull}11242[11242] +- Management configuration backup file will now have a timestamps in their name. {pull}11034[11034] *Auditbeat* diff --git a/x-pack/libbeat/management/enroll.go b/x-pack/libbeat/management/enroll.go index bd5eb7408694..1265d57fc467 100644 --- a/x-pack/libbeat/management/enroll.go +++ b/x-pack/libbeat/management/enroll.go @@ -7,6 +7,7 @@ package management import ( "fmt" "os" + "time" "github.com/pkg/errors" @@ -52,8 +53,10 @@ func Enroll( configFile := cfgfile.GetDefaultCfgfile() + ts := time.Now().Unix() + // backup current settings: - backConfigFile := configFile + ".bak" + backConfigFile := configFile + "." + string(ts) + ".bak" fmt.Println("Saving a copy of current settings to " + backConfigFile) err = file.SafeFileRotate(backConfigFile, configFile) if err != nil { diff --git a/x-pack/libbeat/tests/system/test_management.py b/x-pack/libbeat/tests/system/test_management.py index 76d68279cb8f..e62e64435673 100644 --- a/x-pack/libbeat/tests/system/test_management.py +++ b/x-pack/libbeat/tests/system/test_management.py @@ -1,5 +1,6 @@ import sys import os +import glob import json import requests import string @@ -39,6 +40,8 @@ def test_enroll(self): Enroll the beat in Kibana Central Management """ + assert len(glob.glob(os.path.join(self.working_dir, "mockbeat.yml.*.bak"))) == 0 + # We don't care about this as it will be replaced by enrollment # process: config_path = os.path.join(self.working_dir, "mockbeat.yml") @@ -61,9 +64,9 @@ def test_enroll(self): assert config_content != new_content # Settings backup has been created - assert os.path.isfile(os.path.join( - self.working_dir, "mockbeat.yml.bak")) - backup_content = open(config_path + ".bak", 'r').read() + backup_file = glob.glob(os.path.join(self.working_dir, "mockbeat.yml.*.bak"))[0] + assert os.path.isfile(backup_file) + backup_content = open(backup_file).read() assert config_content == backup_content @unittest.skipIf(not INTEGRATION_TESTS,