97
99
// replaceableFoldersFunc will return a map with the folders that need to
98
100
// be replaced so they can be deleted prior to a restore.
99
func replaceableFoldersFunc() (map[string]os.FileMode, error) {
101
// Mongo 2.4 requires that the database directory be removed, while
102
// Mongo 3.2 requires that it not be removed
103
func replaceableFoldersFunc(dataDir string, mongoVersion mongo.Version) (map[string]os.FileMode, error) {
100
104
replaceables := map[string]os.FileMode{}
102
for _, replaceable := range []string{
103
filepath.Join(dataDir, "db"),
106
// NOTE: never put dataDir in here directly as that will unconditionally
107
// remove the database.
104
109
filepath.Join(dataDir, "init"),
110
filepath.Join(dataDir, "tools"),
111
filepath.Join(dataDir, "agents"),
113
if mongoVersion.Major == 2 {
114
dirs = append(dirs, filepath.Join(dataDir, "db"))
117
for _, replaceable := range dirs {
107
118
dirStat, err := os.Stat(replaceable)
108
119
if os.IsNotExist(err) {
124
135
// directories that are to contain new files; this is to avoid
125
136
// possible mixup from new/old files that lead to an inconsistent
126
137
// restored state machine.
127
func PrepareMachineForRestore() error {
128
replaceFolders, err := replaceableFolders()
138
func PrepareMachineForRestore(mongoVersion mongo.Version) error {
139
replaceFolders, err := replaceableFolders(dataDir, mongoVersion)
130
141
return errors.Annotate(err, "cannot retrieve the list of folders to be cleaned before restore")