diff --git a/dice/dice_backup.go b/dice/dice_backup.go index b5b10833..4d72d21e 100644 --- a/dice/dice_backup.go +++ b/dice/dice_backup.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "io/fs" "os" "path/filepath" @@ -125,7 +126,8 @@ func (dm *DiceManager) Backup(sel BackupSelection, fromAuto bool) (string, error } backup := func(d *Dice, fn string) { - data, err := os.ReadFile(fn) + file, err := os.Open(fn) + defer file.Close() if err != nil && !strings.Contains(fn, "session.token") { if d != nil { d.Logger.Errorf("备份文件失败: %s, 原因: %s", fn, err.Error()) @@ -145,7 +147,15 @@ func (dm *DiceManager) Backup(sel BackupSelection, fromAuto bool) (string, error } return } - _, _ = fileWriter.Write(data) + + _, err = io.Copy(fileWriter, file) + if err != nil { + if d != nil { + d.Logger.Errorf("备份文件失败: %s, 原因: %s", fn, err.Error()) + } else { + logger.Errorf("备份文件失败: %s, 原因: %s", fn, err.Error()) + } + } } backupDir := func(path string, info fs.FileInfo, _ error) error { diff --git a/go.mod b/go.mod index c2bf0975..f684dfcb 100644 --- a/go.mod +++ b/go.mod @@ -83,9 +83,13 @@ require ( github.com/blevesearch/bleve_index_api v1.1.13 github.com/go-gorm/caches/v4 v4.0.5 github.com/gofrs/flock v0.12.1 + github.com/gonutz/w32/v2 v2.11.1 + github.com/joho/godotenv v1.5.1 github.com/spaolacci/murmur3 v1.1.0 github.com/tidwall/gjson v1.17.0 github.com/tidwall/sjson v1.2.5 + gorm.io/driver/mysql v1.5.7 + gorm.io/driver/postgres v1.5.11 moul.io/zapfilter v1.7.0 ) @@ -145,7 +149,6 @@ require ( github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/joho/godotenv v1.5.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/labstack/gommon v0.4.2 // indirect @@ -192,8 +195,6 @@ require ( gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gorm.io/driver/mysql v1.5.7 // indirect - gorm.io/driver/postgres v1.5.11 // indirect modernc.org/libc v1.37.6 // indirect modernc.org/mathutil v1.6.0 // indirect modernc.org/memory v1.7.2 // indirect diff --git a/go.sum b/go.sum index cf0420ed..8f9459d1 100644 --- a/go.sum +++ b/go.sum @@ -186,6 +186,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/gonutz/w32/v2 v2.11.1 h1:plG738ZY7VIkPGf3adZ6lFeAf2evCKrULKyZT5GrPoc= +github.com/gonutz/w32/v2 v2.11.1/go.mod h1:MgtHx0AScDVNKyB+kjyPder4xIi3XAcHS6LDDU2DmdE= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -229,7 +231,6 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= -github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=