@@ -116,7 +116,8 @@ func (u *SnapshotService) SnapshotReCreate(id uint) error {
116116
117117func handleSnapshot (req dto.SnapshotCreate , taskItem * task.Task , jobID uint ) error {
118118 rootDir := path .Join (global .Dir .TmpDir , "system" , req .Name )
119- itemHelper := snapHelper {SnapID : req .ID , Task : * taskItem , FileOp : files .NewFileOp (), Ctx : context .Background ()}
119+ openrestyDir , _ := settingRepo .GetValueByKey ("WEBSITE_DIR" )
120+ itemHelper := snapHelper {SnapID : req .ID , Task : * taskItem , FileOp : files .NewFileOp (), Ctx : context .Background (), OpenrestyDir : openrestyDir }
120121 baseDir := path .Join (rootDir , "base" )
121122 _ = os .MkdirAll (baseDir , os .ModePerm )
122123
@@ -168,7 +169,7 @@ func handleSnapshot(req dto.SnapshotCreate, taskItem *task.Task, jobID uint) err
168169 req .InterruptStep = ""
169170 }
170171
171- taskItem .AddSubTask (
172+ taskItem .AddSubTaskWithAlias (
172173 "SnapCloseDBConn" ,
173174 func (t * task.Task ) error {
174175 taskItem .Log ("---------------------- 6 / 8 ----------------------" )
@@ -214,6 +215,8 @@ type snapHelper struct {
214215 FileOp files.FileOp
215216 Wg * sync.WaitGroup
216217 Task task.Task
218+
219+ OpenrestyDir string
217220}
218221
219222func loadDbConn (snap * snapHelper , targetDir string , req dto.SnapshotCreate ) error {
@@ -247,6 +250,12 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro
247250 return err
248251 }
249252 }
253+ if ! req .WithTaskLog {
254+ err = os .Remove (path .Join (targetDir , "db/task.db" ))
255+ if err != nil {
256+ return err
257+ }
258+ }
250259 if ! req .WithOperationLog {
251260 err = snap .snapCoreDB .Exec ("DELETE FROM operation_logs" ).Error
252261 snap .Task .LogWithStatus (i18n .GetMsgByKey ("SnapDeleteOperationLog" ), err )
@@ -312,6 +321,7 @@ func snapBaseData(snap snapHelper, targetDir string) error {
312321
313322 remarkInfo , _ := json .MarshalIndent (SnapshotJson {
314323 BaseDir : global .Dir .BaseDir ,
324+ OperestyDir : snap .OpenrestyDir ,
315325 BackupDataDir : global .Dir .LocalBackupDir ,
316326 }, "" , "\t " )
317327 err = os .WriteFile (path .Join (targetDir , "snapshot.json" ), remarkInfo , 0640 )
@@ -327,13 +337,22 @@ func snapAppImage(snap snapHelper, req dto.SnapshotCreate, targetDir string) err
327337 snap .Task .Log ("---------------------- 3 / 8 ----------------------" )
328338 snap .Task .LogStart (i18n .GetMsgByKey ("SnapInstallApp" ))
329339
340+ var appInstalls []model.AppInstall
341+ _ = snap .snapAgentDB .Where ("1 = 1" ).Find (& appInstalls ).Error
342+ for _ , item := range appInstalls {
343+ _ = snap .snapAgentDB .Where ("id = ?" , item .ID ).Updates (map [string ]interface {}{"status" : constant .StatusWaitingRestart }).Error
344+ }
345+
330346 var imageList []string
331347 existStr , _ := cmd .Exec ("docker images | awk '{print $1\" :\" $2}' | grep -v REPOSITORY:TAG" )
332348 existImages := strings .Split (existStr , "\n " )
333349 for _ , app := range req .AppData {
334350 for _ , item := range app .Children {
335351 if item .Label == "appImage" && item .IsCheck {
336352 for _ , existImage := range existImages {
353+ if len (existImage ) == 0 {
354+ continue
355+ }
337356 if existImage == item .Name {
338357 imageList = append (imageList , item .Name )
339358 }
@@ -342,10 +361,10 @@ func snapAppImage(snap snapHelper, req dto.SnapshotCreate, targetDir string) err
342361 }
343362 }
344363
364+ snap .Task .Log (strings .Join (imageList , " " ))
345365 if len (imageList ) != 0 {
346366 snap .Task .Logf ("docker save %s | gzip -c > %s" , strings .Join (imageList , " " ), path .Join (targetDir , "images.tar.gz" ))
347367 std , err := cmd .Execf ("docker save %s | gzip -c > %s" , strings .Join (imageList , " " ), path .Join (targetDir , "images.tar.gz" ))
348- snap .Task .LogWithStatus (i18n .GetMsgByKey ("SnapDockerSave" ), errors .New (std ))
349368 if err != nil {
350369 snap .Task .LogFailedWithErr (i18n .GetMsgByKey ("SnapDockerSave" ), errors .New (std ))
351370 return errors .New (std )
@@ -421,25 +440,32 @@ func snapPanelData(snap snapHelper, req dto.SnapshotCreate, targetDir string) er
421440 }
422441 }
423442 }
424- excludes = append (excludes , "./tmp" )
425443 excludes = append (excludes , "./cache" )
426- excludes = append (excludes , "./uploads" )
427444 excludes = append (excludes , "./db" )
428- excludes = append (excludes , "./resource " )
445+ excludes = append (excludes , "./tmp " )
429446 if ! req .WithSystemLog {
430447 excludes = append (excludes , "./log/1Panel*" )
431448 }
432449 if ! req .WithTaskLog {
433- excludes = append (excludes , "./log/App" )
434- excludes = append (excludes , "./log/Snapshot" )
450+ excludes = append (excludes , "./log/AI" )
435451 excludes = append (excludes , "./log/AppStore" )
452+ excludes = append (excludes , "./log/Cronjob" )
453+ excludes = append (excludes , "./log/Image" )
454+ excludes = append (excludes , "./log/Compose" )
455+ excludes = append (excludes , "./log/Database" )
456+ excludes = append (excludes , "./log/RuntimeExtension" )
436457 excludes = append (excludes , "./log/Website" )
458+ excludes = append (excludes , "./log/App" )
459+ excludes = append (excludes , "./log/Snapshot" )
437460 }
438461
439462 rootDir := global .Dir .DataDir
440463 if strings .Contains (global .Dir .LocalBackupDir , rootDir ) {
441464 excludes = append (excludes , "." + strings .ReplaceAll (global .Dir .LocalBackupDir , rootDir , "" ))
442465 }
466+ if len (snap .OpenrestyDir ) != 0 && strings .Contains (snap .OpenrestyDir , rootDir ) {
467+ excludes = append (excludes , "." + strings .ReplaceAll (snap .OpenrestyDir , rootDir , "" ))
468+ }
443469 ignoreVal , _ := settingRepo .Get (settingRepo .WithByKey ("SnapshotIgnore" ))
444470 rules := strings .Split (ignoreVal .Value , "," )
445471 for _ , ignore := range rules {
@@ -450,6 +476,16 @@ func snapPanelData(snap snapHelper, req dto.SnapshotCreate, targetDir string) er
450476 }
451477 err := snap .FileOp .TarGzCompressPro (false , rootDir , path .Join (targetDir , "1panel_data.tar.gz" ), "" , strings .Join (excludes , ";" ))
452478 snap .Task .LogWithStatus (i18n .GetMsgByKey ("SnapCompressPanel" ), err )
479+ if err != nil {
480+ return err
481+ }
482+ if len (snap .OpenrestyDir ) != 0 {
483+ err := snap .FileOp .TarGzCompressPro (false , snap .OpenrestyDir , path .Join (targetDir , "website.tar.gz" ), "" , "" )
484+ snap .Task .LogWithStatus (i18n .GetMsgByKey ("SnapWebsite" ), err )
485+ if err != nil {
486+ return err
487+ }
488+ }
453489
454490 return err
455491}
0 commit comments