Skip to content

Commit

Permalink
Add the timestamp when creating the backup file (elastic#11034)
Browse files Browse the repository at this point in the history
  • Loading branch information
ph authored Mar 28, 2019
1 parent dcd98bd commit 1342d5f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
5 changes: 4 additions & 1 deletion x-pack/libbeat/management/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package management
import (
"fmt"
"os"
"time"

"github.com/pkg/errors"

Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions x-pack/libbeat/tests/system/test_management.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import os
import glob
import json
import requests
import string
Expand Down Expand Up @@ -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")
Expand All @@ -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,
Expand Down

0 comments on commit 1342d5f

Please sign in to comment.