diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go
index 2b858c189..ddbd2e52a 100644
--- a/backend/app/service/cronjob_helper.go
+++ b/backend/app/service/cronjob_helper.go
@@ -16,6 +16,7 @@ import (
"github.com/1Panel-dev/1Panel/backend/utils/cloud_storage"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
"github.com/1Panel-dev/1Panel/backend/utils/files"
+ "github.com/1Panel-dev/1Panel/backend/utils/ntp"
"github.com/pkg/errors"
)
@@ -39,6 +40,9 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) {
}
message, err = u.handleShell(cronjob.Type, cronjob.Name, fmt.Sprintf("curl '%s'", cronjob.URL))
u.HandleRmExpired("LOCAL", "", cronjob, nil)
+ case "ntp":
+ err = u.handleNtpSync()
+ u.HandleRmExpired("LOCAL", "", cronjob, nil)
case "website":
record.File, err = u.handleBackup(cronjob, record.StartTime)
case "database":
@@ -92,6 +96,21 @@ func (u *CronjobService) handleShell(cronType, cornName, script string) ([]byte,
return []byte(stdout), nil
}
+func (u *CronjobService) handleNtpSync() error {
+ ntpServer, err := settingRepo.Get(settingRepo.WithByKey("NtpSite"))
+ if err != nil {
+ return err
+ }
+ ntime, err := ntp.GetRemoteTime(ntpServer.Value)
+ if err != nil {
+ return err
+ }
+ if err := ntp.UpdateSystemTime(ntime.Format("2006-01-02 15:04:05")); err != nil {
+ return err
+ }
+ return nil
+}
+
func (u *CronjobService) handleBackup(cronjob *model.Cronjob, startTime time.Time) (string, error) {
backup, err := backupRepo.Get(commonRepo.WithByID(uint(cronjob.TargetDirID)))
if err != nil {
@@ -150,15 +169,17 @@ func (u *CronjobService) HandleRmExpired(backType, localDir string, cronjob *mod
records, _ := cronjobRepo.ListRecord(cronjobRepo.WithByJobID(int(cronjob.ID)), commonRepo.WithOrderBy("created_at desc"))
if len(records) > int(cronjob.RetainCopies) {
for i := int(cronjob.RetainCopies); i < len(records); i++ {
- files := strings.Split(records[i].File, ",")
- for _, file := range files {
- if backType != "LOCAL" {
- _, _ = backClient.Delete(strings.ReplaceAll(file, localDir+"/", ""))
- _ = os.Remove(file)
- } else {
- _ = os.Remove(file)
+ if len(records[i].File) != 0 {
+ files := strings.Split(records[i].File, ",")
+ for _, file := range files {
+ if backType != "LOCAL" {
+ _, _ = backClient.Delete(strings.ReplaceAll(file, localDir+"/", ""))
+ _ = os.Remove(file)
+ } else {
+ _ = os.Remove(file)
+ }
+ _ = backupRepo.DeleteRecord(context.TODO(), backupRepo.WithByFileName(path.Base(file)))
}
- _ = backupRepo.DeleteRecord(context.TODO(), backupRepo.WithByFileName(path.Base(file)))
}
_ = cronjobRepo.DeleteRecord(commonRepo.WithByID(uint(records[i].ID)))
diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts
index 73229d108..82fceee3a 100644
--- a/frontend/src/lang/modules/en.ts
+++ b/frontend/src/lang/modules/en.ts
@@ -616,6 +616,7 @@ const message = {
taskType: 'Task type',
record: 'Records',
shell: 'Shell script',
+ ntp: 'Time synchronization',
website: 'Backup website',
rulesHelper: 'Compression exclusion rules (with; Is a delimiter), for example: \n*.log; *.sql',
lastRecrodTime: 'Last execution time',
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index 1241c2a52..319ef4066 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -627,6 +627,7 @@ const message = {
taskType: '任务类型',
record: '报告',
shell: 'Shell 脚本',
+ ntp: '时间同步',
website: '备份网站',
rulesHelper: '压缩排除规则(以 ; 号为分隔符),例: \n*.log;*.sql',
lastRecrodTime: '上次执行时间',
diff --git a/frontend/src/views/cronjob/operate/index.vue b/frontend/src/views/cronjob/operate/index.vue
index 9fe70cc0e..ede3800ca 100644
--- a/frontend/src/views/cronjob/operate/index.vue
+++ b/frontend/src/views/cronjob/operate/index.vue
@@ -18,6 +18,7 @@
+
{{ dialogData.rowData!.type }}
diff --git a/go.mod b/go.mod
index 9a043ef1d..e3ab8907a 100644
--- a/go.mod
+++ b/go.mod
@@ -50,6 +50,7 @@ require (
golang.org/x/crypto v0.5.0
golang.org/x/net v0.7.0
golang.org/x/text v0.7.0
+ gopkg.in/ini.v1 v1.67.0
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/sqlite v1.4.4
@@ -244,7 +245,6 @@ require (
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
- gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.26.3 // indirect
k8s.io/apimachinery v0.26.3 // indirect
diff --git a/go.sum b/go.sum
index 0fc677068..b119412f8 100644
--- a/go.sum
+++ b/go.sum
@@ -199,8 +199,6 @@ github.com/docker/cli v23.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvM
github.com/docker/compose/v2 v2.17.2 h1:MP0wtvPifrh3Ikq6XfyO3cOhya5ubTXOYn70G+ojnek=
github.com/docker/compose/v2 v2.17.2/go.mod h1:h5uld3t0RsL5h8rtkRaJtrFLJ3TJ9GOKdbxa4i1M1dY=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
-github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
-github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v23.0.3+incompatible h1:9GhVsShNWz1hO//9BNg/dpMnZW25KydO4wtVxWAIbho=