Skip to content

Commit c257ad6

Browse files
authored
add hostname to backup manifest (#18847)
Signed-off-by: --global <[email protected]>
1 parent 1fe6c68 commit c257ad6

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

go/vt/mysqlctl/backupengine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ type BackupManifest struct {
327327

328328
TabletAlias string
329329

330+
Hostname string
331+
330332
Keyspace string
331333

332334
Shard string

go/vt/mysqlctl/builtinbackupengine.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"vitess.io/vitess/go/ioutil"
4040
"vitess.io/vitess/go/mysql"
4141
"vitess.io/vitess/go/mysql/replication"
42+
"vitess.io/vitess/go/netutil"
4243
"vitess.io/vitess/go/os2"
4344
"vitess.io/vitess/go/protoutil"
4445
"vitess.io/vitess/go/vt/log"
@@ -1008,6 +1009,12 @@ func (be *BuiltinBackupEngine) backupManifest(
10081009
}
10091010
}()
10101011

1012+
// Get the hostname
1013+
hostname, err := netutil.FullyQualifiedHostname()
1014+
if err != nil {
1015+
hostname = ""
1016+
}
1017+
10111018
// JSON-encode and write the MANIFEST
10121019
bm := &builtinBackupManifest{
10131020
// Common base fields
@@ -1021,6 +1028,7 @@ func (be *BuiltinBackupEngine) backupManifest(
10211028
Incremental: !fromPosition.IsZero(),
10221029
ServerUUID: serverUUID,
10231030
TabletAlias: params.TabletAlias,
1031+
Hostname: hostname,
10241032
Keyspace: params.Keyspace,
10251033
Shard: params.Shard,
10261034
BackupTime: params.BackupTime.UTC().Format(time.RFC3339),

go/vt/mysqlctl/mysqlshellbackupengine.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
"vitess.io/vitess/go/mysql"
3737
"vitess.io/vitess/go/mysql/capabilities"
38+
"vitess.io/vitess/go/netutil"
3839
"vitess.io/vitess/go/vt/log"
3940
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
4041
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
@@ -204,6 +205,12 @@ func (be *MySQLShellBackupEngine) ExecuteBackup(ctx context.Context, params Back
204205
}
205206
defer closeFile(mwc, backupManifestFileName, params.Logger, &finalErr)
206207

208+
// Get the hostname
209+
hostname, err := netutil.FullyQualifiedHostname()
210+
if err != nil {
211+
hostname = ""
212+
}
213+
207214
// JSON-encode and write the MANIFEST
208215
bm := &MySQLShellBackupManifest{
209216
// Common base fields
@@ -218,6 +225,7 @@ func (be *MySQLShellBackupEngine) ExecuteBackup(ctx context.Context, params Back
218225
FinishedTime: FormatRFC3339(time.Now().UTC()),
219226
ServerUUID: serverUUID,
220227
TabletAlias: params.TabletAlias,
228+
Hostname: hostname,
221229
Keyspace: params.Keyspace,
222230
Shard: params.Shard,
223231
MySQLVersion: mysqlVersion,

go/vt/mysqlctl/mysqlshellbackupengine_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"vitess.io/vitess/go/ioutil"
3131
"vitess.io/vitess/go/mysql/fakesqldb"
32+
"vitess.io/vitess/go/netutil"
3233
"vitess.io/vitess/go/sqltypes"
3334
"vitess.io/vitess/go/vt/logutil"
3435
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
@@ -401,6 +402,10 @@ func TestMySQLShellBackupEngine_ExecuteBackup_ReleaseLock(t *testing.T) {
401402

402403
require.Equal(t, mysqlShellBackupEngineName, manifest.BackupMethod)
403404

405+
if hostname, err := netutil.FullyQualifiedHostname(); err == nil {
406+
require.Equal(t, hostname, manifest.Hostname)
407+
}
408+
404409
// did we notice the lock was release and did we release it ours as well?
405410
require.Contains(t, logger.String(), "global read lock released after",
406411
"failed to release the global lock after mysqlsh")

go/vt/mysqlctl/xtrabackupengine.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
"vitess.io/vitess/go/ioutil"
3636
"vitess.io/vitess/go/mysql/replication"
37+
"vitess.io/vitess/go/netutil"
3738
"vitess.io/vitess/go/vt/logutil"
3839
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
3940
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
@@ -245,6 +246,12 @@ func (be *XtrabackupEngine) executeFullBackup(ctx context.Context, params Backup
245246
}
246247
defer closeFile(mwc, backupManifestFileName, params.Logger, &finalErr)
247248

249+
// Get the hostname
250+
hostname, err := netutil.FullyQualifiedHostname()
251+
if err != nil {
252+
hostname = ""
253+
}
254+
248255
// JSON-encode and write the MANIFEST
249256
bm := &xtraBackupManifest{
250257
// Common base fields
@@ -255,6 +262,7 @@ func (be *XtrabackupEngine) executeFullBackup(ctx context.Context, params Backup
255262
PurgedPosition: replicationPosition,
256263
ServerUUID: serverUUID,
257264
TabletAlias: params.TabletAlias,
265+
Hostname: hostname,
258266
Keyspace: params.Keyspace,
259267
Shard: params.Shard,
260268
BackupTime: FormatRFC3339(params.BackupTime.UTC()),

0 commit comments

Comments
 (0)