(sentinel *SentinelDto, dbnames []string, fromnames []string)
| 106 | } |
| 107 | |
| 108 | func 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 | |
| 137 | func listDatabases(db *sql.DB) ([]string, error) { |
| 138 | rows, err := db.Query("SELECT name FROM sys.databases WHERE name != 'tempdb'") |
no test coverage detected