MCPcopy
hub / github.com/wal-g/wal-g / getDatabasesToRestore

Function getDatabasesToRestore

internal/databases/sqlserver/sqlserver.go:108–135  ·  view source on GitHub ↗
(sentinel *SentinelDto, dbnames []string, fromnames []string)

Source from the content-addressed store, hash-verified

106}
107
108func getDatabasesToRestore(sentinel *SentinelDto, dbnames []string, fromnames []string) ([]string, []string, error) {
109 switch {
110 case len(dbnames) == 0:
111 if len(fromnames) != 0 {
112 return nil, nil, fmt.Errorf("--from param should be omitted when --databases is empty")
113 }
114 dbnames = exclude(sentinel.Databases, SystemDbnames)
115 fromnames = dbnames
116 case len(dbnames) == 1 && dbnames[0] == AllDatabases:
117 if len(fromnames) != 0 {
118 return nil, nil, fmt.Errorf("--from param should be omitted when --databases %s", AllDatabases)
119 }
120 dbnames = sentinel.Databases
121 fromnames = dbnames
122 default:
123 if len(fromnames) == 0 {
124 fromnames = dbnames
125 }
126 if len(fromnames) != len(dbnames) {
127 return nil, nil, fmt.Errorf("--from list length should match --databases list length")
128 }
129 missing := exclude(fromnames, sentinel.Databases)
130 if len(missing) > 0 {
131 return nil, nil, fmt.Errorf("databases %v were not found in backup", missing)
132 }
133 }
134 return dbnames, fromnames, nil
135}
136
137func listDatabases(db *sql.DB) ([]string, error) {
138 rows, err := db.Query("SELECT name FROM sys.databases WHERE name != 'tempdb'")

Callers 2

HandleBackupRestoreFunction · 0.85
HandleLogRestoreFunction · 0.85

Calls 2

excludeFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected