66 "fmt"
77 "os"
88 "path"
9+ "path/filepath"
910 "strings"
1011 "sync"
1112 "time"
@@ -55,6 +56,7 @@ func (u *SnapshotService) SnapshotCreate(parentTask *task.Task, req dto.Snapshot
5556 WithOperationLog : req .WithOperationLog ,
5657 WithTaskLog : req .WithTaskLog ,
5758 WithSystemLog : req .WithSystemLog ,
59+ IgnoreFiles : strings .Join (req .IgnoreFiles , "," ),
5860
5961 Version : versionItem .Value ,
6062 Status : constant .StatusWaiting ,
@@ -398,6 +400,7 @@ func snapBackupData(snap snapHelper, req dto.SnapshotCreate, targetDir string) e
398400 snap .Task .LogStart (i18n .GetMsgByKey ("SnapLocalBackup" ))
399401
400402 excludes := loadBackupExcludes (snap , req .BackupData )
403+ excludes = append (excludes , req .IgnoreFiles ... )
401404 excludes = append (excludes , "./system_snapshot" )
402405 for _ , item := range req .AppData {
403406 for _ , itemApp := range item .Children {
@@ -421,7 +424,8 @@ func loadBackupExcludes(snap snapHelper, req []dto.DataTree) []string {
421424 if err := snap .snapAgentDB .Where ("file_dir = ? AND file_name = ?" , strings .TrimPrefix (path .Dir (item .Path ), global .Dir .LocalBackupDir + "/" ), path .Base (item .Path )).Delete (& model.BackupRecord {}).Error ; err != nil {
422425 snap .Task .LogWithStatus ("delete backup file from database" , err )
423426 }
424- excludes = append (excludes , "." + strings .TrimPrefix (item .Path , global .Dir .LocalBackupDir ))
427+ itemDir , _ := filepath .Rel (item .Path , global .Dir .LocalBackupDir )
428+ excludes = append (excludes , itemDir )
425429 } else {
426430 excludes = append (excludes , loadBackupExcludes (snap , item .Children )... )
427431 }
@@ -433,7 +437,8 @@ func loadAppBackupExcludes(req []dto.DataTree) []string {
433437 for _ , item := range req {
434438 if len (item .Children ) == 0 {
435439 if ! item .IsCheck {
436- excludes = append (excludes , "." + strings .TrimPrefix (item .Path , path .Join (global .Dir .LocalBackupDir )))
440+ itemDir , _ := filepath .Rel (item .Path , global .Dir .LocalBackupDir )
441+ excludes = append (excludes , itemDir )
437442 }
438443 } else {
439444 excludes = append (excludes , loadAppBackupExcludes (item .Children )... )
@@ -466,26 +471,21 @@ func snapPanelData(snap snapHelper, req dto.SnapshotCreate, targetDir string) er
466471
467472 rootDir := global .Dir .DataDir
468473 if strings .Contains (global .Dir .LocalBackupDir , rootDir ) {
469- excludes = append (excludes , "." + strings .ReplaceAll (global .Dir .LocalBackupDir , rootDir , "" ))
474+ itemDir , _ := filepath .Rel (rootDir , global .Dir .LocalBackupDir )
475+ excludes = append (excludes , itemDir )
470476 }
471477 if len (snap .OpenrestyDir ) != 0 && strings .Contains (snap .OpenrestyDir , rootDir ) {
472- excludes = append (excludes , "." + strings .ReplaceAll (snap .OpenrestyDir , rootDir , "" ))
473- }
474- ignoreVal , _ := settingRepo .Get (settingRepo .WithByKey ("SnapshotIgnore" ))
475- rules := strings .Split (ignoreVal .Value , "," )
476- for _ , ignore := range rules {
477- if len (ignore ) == 0 || cmd .CheckIllegal (ignore ) {
478- continue
479- }
480- excludes = append (excludes , "." + strings .ReplaceAll (ignore , rootDir , "" ))
478+ itemDir , _ := filepath .Rel (rootDir , snap .OpenrestyDir )
479+ excludes = append (excludes , itemDir )
481480 }
481+ excludes = append (excludes , req .IgnoreFiles ... )
482482 err := snap .FileOp .TarGzCompressPro (false , rootDir , path .Join (targetDir , "1panel_data.tar.gz" ), "" , strings .Join (excludes , "," ))
483483 snap .Task .LogWithStatus (i18n .GetMsgByKey ("SnapCompressPanel" ), err )
484484 if err != nil {
485485 return err
486486 }
487487 if len (snap .OpenrestyDir ) != 0 {
488- err := snap .FileOp .TarGzCompressPro (false , snap .OpenrestyDir , path .Join (targetDir , "website.tar.gz" ), "" , "" )
488+ err := snap .FileOp .TarGzCompressPro (false , snap .OpenrestyDir , path .Join (targetDir , "website.tar.gz" ), "" , strings . Join ( req . IgnoreFiles , "," ) )
489489 snap .Task .LogWithStatus (i18n .GetMsgByKey ("SnapWebsite" ), err )
490490 if err != nil {
491491 return err
@@ -499,7 +499,8 @@ func loadPanelExcludes(req []dto.DataTree) []string {
499499 for _ , item := range req {
500500 if len (item .Children ) == 0 {
501501 if ! item .IsCheck {
502- excludes = append (excludes , "." + strings .TrimPrefix (item .Path , path .Join (global .Dir .BaseDir , "1panel" )))
502+ itemDir , _ := filepath .Rel (item .Path , path .Join (global .Dir .BaseDir , "1panel" ))
503+ excludes = append (excludes , itemDir )
503504 }
504505 } else {
505506 excludes = append (excludes , loadPanelExcludes (item .Children )... )
0 commit comments