~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/backups/files.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        "sort"
10
10
 
11
11
        "github.com/juju/errors"
 
12
 
 
13
        "github.com/juju/juju/mongo"
12
14
)
13
15
 
14
16
// TODO(ericsnow) lp-1392876
96
98
 
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{}
101
105
 
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.
 
108
        dirs := []string{
104
109
                filepath.Join(dataDir, "init"),
105
 
                dataDir,
106
 
        } {
 
110
                filepath.Join(dataDir, "tools"),
 
111
                filepath.Join(dataDir, "agents"),
 
112
        }
 
113
        if mongoVersion.Major == 2 {
 
114
                dirs = append(dirs, filepath.Join(dataDir, "db"))
 
115
        }
 
116
 
 
117
        for _, replaceable := range dirs {
107
118
                dirStat, err := os.Stat(replaceable)
108
119
                if os.IsNotExist(err) {
109
120
                        continue
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)
129
140
        if err != nil {
130
141
                return errors.Annotate(err, "cannot retrieve the list of folders to be cleaned before restore")
131
142
        }
144
155
                if !fmode.IsDir() {
145
156
                        continue
146
157
                }
 
158
                logger.Debugf("removing dir: %s", toBeRecreated)
147
159
                if err := os.RemoveAll(toBeRecreated); err != nil {
148
160
                        return errors.Trace(err)
149
161
                }