Skip to content

Commit 2b7562f

Browse files
authored
feat: Add snapshot restore timeout duration (#11660)
1 parent e7f4e31 commit 2b7562f

2 files changed

Lines changed: 33 additions & 30 deletions

File tree

agent/app/service/snapshot_recover.go

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
101101
}()
102102

103103
if req.IsNew || snap.InterruptStep == "RecoverDownload" || req.ReDownload {
104-
taskItem.AddSubTaskWithAlias(
104+
taskItem.AddSubTaskWithAliasAndOps(
105105
"RecoverDownload",
106106
func(t *task.Task) error { return handleDownloadSnapshot(&itemHelper, snap, rootDir) },
107-
nil,
107+
nil, 0, 90*time.Minute,
108108
)
109109
req.IsNew = true
110110
}
111111
if req.IsNew || snap.InterruptStep == "RecoverDecompress" {
112-
taskItem.AddSubTaskWithAlias(
112+
taskItem.AddSubTaskWithAliasAndOps(
113113
"RecoverDecompress",
114114
func(t *task.Task) error {
115115
itemHelper.Task.Log("---------------------- 2 / 11 ----------------------")
@@ -118,54 +118,54 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
118118
itemHelper.Task.LogWithStatus(i18n.GetMsgByKey("Decompress"), err)
119119
return err
120120
},
121-
nil,
121+
nil, 0, 90*time.Minute,
122122
)
123123
req.IsNew = true
124124
}
125125
if req.IsNew || snap.InterruptStep == "BackupBeforeRecover" {
126-
taskItem.AddSubTaskWithAlias(
126+
taskItem.AddSubTaskWithAliasAndOps(
127127
"BackupBeforeRecover",
128128
func(t *task.Task) error { return backupBeforeRecover(snap.Name, &itemHelper) },
129-
nil,
129+
nil, 0, 90*time.Minute,
130130
)
131131
req.IsNew = true
132132
}
133133

134134
var snapJson SnapshotJson
135-
taskItem.AddSubTaskWithAlias(
135+
taskItem.AddSubTaskWithAliasAndOps(
136136
"Readjson",
137137
func(t *task.Task) error {
138138
snapJson, err = readFromJson(path.Join(rootDir, snap.Name), &itemHelper)
139139
return err
140140
},
141-
nil,
141+
nil, 0, 90*time.Minute,
142142
)
143143
if req.IsNew || snap.InterruptStep == "RecoverApp" {
144-
taskItem.AddSubTaskWithAlias(
144+
taskItem.AddSubTaskWithAliasAndOps(
145145
"RecoverApp",
146146
func(t *task.Task) error { return recoverAppData(path.Join(rootDir, snap.Name), &itemHelper) },
147-
nil,
147+
nil, 0, 90*time.Minute,
148148
)
149149
req.IsNew = true
150150
}
151151
if req.IsNew || snap.InterruptStep == "RecoverBaseData" {
152-
taskItem.AddSubTaskWithAlias(
152+
taskItem.AddSubTaskWithAliasAndOps(
153153
"RecoverBaseData",
154154
func(t *task.Task) error { return recoverBaseData(path.Join(rootDir, snap.Name, "base"), &itemHelper) },
155-
nil,
155+
nil, 0, 90*time.Minute,
156156
)
157157
req.IsNew = true
158158
}
159159
if req.IsNew || snap.InterruptStep == "RecoverDBData" {
160-
taskItem.AddSubTaskWithAlias(
160+
taskItem.AddSubTaskWithAliasAndOps(
161161
"RecoverDBData",
162162
func(t *task.Task) error { return recoverDBData(path.Join(rootDir, snap.Name, "db"), &itemHelper) },
163-
nil,
163+
nil, 0, 90*time.Minute,
164164
)
165165
req.IsNew = true
166166
}
167167
if req.IsNew || snap.InterruptStep == "RecoverBackups" {
168-
taskItem.AddSubTaskWithAlias(
168+
taskItem.AddSubTaskWithAliasAndOps(
169169
"RecoverBackups",
170170
func(t *task.Task) error {
171171
itemHelper.Task.Log("---------------------- 8 / 11 ----------------------")
@@ -174,12 +174,12 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
174174
itemHelper.Task.LogWithStatus(i18n.GetMsgByKey("Decompress"), err)
175175
return err
176176
},
177-
nil,
177+
nil, 0, 90*time.Minute,
178178
)
179179
req.IsNew = true
180180
}
181181
if req.IsNew || snap.InterruptStep == "RecoverWebsite" {
182-
taskItem.AddSubTaskWithAlias(
182+
taskItem.AddSubTaskWithAliasAndOps(
183183
"RecoverWebsite",
184184
func(t *task.Task) error {
185185
itemHelper.Task.Log("---------------------- 9 / 11 ----------------------")
@@ -193,12 +193,12 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
193193
itemHelper.Task.LogWithStatus(i18n.GetMsgByKey("Decompress"), err)
194194
return err
195195
},
196-
nil,
196+
nil, 0, 90*time.Minute,
197197
)
198198
req.IsNew = true
199199
}
200200
if req.IsNew || snap.InterruptStep == "RecoverPanelData" {
201-
taskItem.AddSubTaskWithAlias(
201+
taskItem.AddSubTaskWithAliasAndOps(
202202
"RecoverPanelData",
203203
func(t *task.Task) error {
204204
itemHelper.Task.Log("---------------------- 10 / 11 ----------------------")
@@ -218,16 +218,16 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
218218
}
219219
return err
220220
},
221-
nil,
221+
nil, 0, 90*time.Minute,
222222
)
223223
req.IsNew = true
224224
}
225-
taskItem.AddSubTaskWithAlias(
225+
taskItem.AddSubTaskWithAliasAndOps(
226226
"RecoverDBData",
227227
func(t *task.Task) error {
228228
return restartCompose(path.Join(snapJson.BaseDir, "1panel/docker/compose"), &itemHelper)
229229
},
230-
nil,
230+
nil, 0, 90*time.Minute,
231231
)
232232

233233
if err := taskItem.Execute(); err != nil {
@@ -277,24 +277,26 @@ func backupBeforeRecover(name string, itemHelper *snapRecoverHelper) error {
277277
return err
278278
}
279279
}
280-
err := itemHelper.FileOp.CopyDirWithExclude(global.Dir.DataDir, rootDir, []string{"cache", "tmp"})
281-
itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", global.Dir.DataDir), err)
280+
dataDir := global.Dir.DataDir
281+
err := itemHelper.FileOp.CopyDirWithExclude(dataDir, rootDir, []string{"cache", "tmp", "backup"})
282+
itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", dataDir), err)
282283
if err != nil {
283284
return err
284285
}
285286

286287
openrestyDir, _ := settingRepo.GetValueByKey("WEBSITE_DIR")
287-
if len(openrestyDir) != 0 && !strings.Contains(openrestyDir, global.Dir.DataDir) {
288+
if len(openrestyDir) != 0 && !strings.Contains(openrestyDir, dataDir) {
288289
err := itemHelper.FileOp.CopyDirWithExclude(openrestyDir, rootDir, nil)
289290
itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", openrestyDir), err)
290291
if err != nil {
291292
return err
292293
}
293294
}
294295

295-
if len(global.Dir.LocalBackupDir) != 0 && !strings.Contains(global.Dir.LocalBackupDir, global.Dir.DataDir) {
296-
err = itemHelper.FileOp.CopyDirWithExclude(global.Dir.LocalBackupDir, rootDir, []string{"system_snapshot"})
297-
itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", global.Dir.LocalBackupDir), err)
296+
backupDir := global.Dir.LocalBackupDir
297+
if len(backupDir) != 0 && (backupDir == dataDir+"/backup" || !strings.HasPrefix(backupDir, dataDir)) {
298+
err = itemHelper.FileOp.CopyDirWithExclude(backupDir, rootDir, []string{"system_snapshot", "tmp"})
299+
itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", backupDir), err)
298300
if err != nil {
299301
return err
300302
}

agent/app/service/snapshot_rollback.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path"
7+
"strings"
78

89
"github.com/1Panel-dev/1Panel/agent/app/repo"
910

@@ -88,7 +89,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
8889
taskItem.AddSubTask(
8990
i18n.GetWithName("SnapCopy", global.Dir.LocalBackupDir),
9091
func(t *task.Task) error {
91-
return FileOp.CopyDir(path.Join(rootDir, "backup"), global.Dir.LocalBackupDir)
92+
return FileOp.CopyDir(path.Join(rootDir, "backup"), strings.TrimSuffix(global.Dir.LocalBackupDir, "/backup"))
9293
},
9394
nil,
9495
)
@@ -97,7 +98,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
9798
taskItem.AddSubTask(
9899
i18n.GetWithName("SnapCopy", openrestyDir),
99100
func(t *task.Task) error {
100-
return FileOp.CopyDir(path.Join(rootDir, "www"), openrestyDir)
101+
return FileOp.CopyDir(path.Join(rootDir, "www"), strings.TrimSuffix(openrestyDir, "/www"))
101102
},
102103
nil,
103104
)

0 commit comments

Comments
 (0)