Skip to content

Commit

Permalink
feat: project supports enabled or disabled (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessy2 authored Jul 19, 2022
1 parent 40ebcb6 commit 842f16a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
9 changes: 7 additions & 2 deletions client/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ func RunLoop() {
continue
}

if backupConf.Enabled != 0 {
log.Println(backupConf.ProjectName + " 项目被停用")
continue
}

if !backupConf.CheckPeriod() {
log.Println(backupConf.ProjectName + "的周期值不正确")
log.Println(backupConf.ProjectName + " 项目的周期值不正确")
continue
}

Expand Down Expand Up @@ -88,7 +93,7 @@ func RunOnce() {

// run
func run(conf entity.Config, backupConf entity.BackupConfig) {
if backupConf.NotEmptyProject() {
if backupConf.NotEmptyProject() && backupConf.Enabled == 0 {
err := prepare(backupConf)
if err != nil {
log.Println(err)
Expand Down
1 change: 1 addition & 0 deletions entity/config_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type BackupConfig struct {
Period int // 间隔周期(分钟)
Pwd string // 密码
BackupType int // 备份类型 0 数据库备份 1 文件同步
Enabled int // 是否启用 0 启用 1 停用
}

// GetProjectPath 获得项目路径
Expand Down
2 changes: 2 additions & 0 deletions web/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func Save(writer http.ResponseWriter, request *http.Request) {
startTime, _ := strconv.Atoi(forms["StartTime"][index])
period, _ := strconv.Atoi(forms["Period"][index])
backupType, _ := strconv.Atoi(forms["BackupType"][index])
enabled, _ := strconv.Atoi(forms["Enabled"][index])
conf.BackupConfig = append(
conf.BackupConfig,
entity.BackupConfig{
Expand All @@ -59,6 +60,7 @@ func Save(writer http.ResponseWriter, request *http.Request) {
Period: period,
Pwd: forms["Pwd"][index],
BackupType: backupType,
Enabled: enabled,
},
)
}
Expand Down
26 changes: 16 additions & 10 deletions web/writing.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,33 @@ <h5 class="portlet__head">备份设置</h5>
<div class="col-sm-10">
<textarea class="form-control" name="Command" id="Command_{{$i}}" rows="3" aria-describedby="Command_help">{{$v.Command}}</textarea>
<small id="Command_help" class="form-text text-muted">
日期变量 #{DATE} ,下方的密码变量 #{PWD} ,下方的对象存储变量: #{Endpoint} #{AccessKey} #{SecretKey} #{BucketName}
日期变量 #{DATE} ,密码变量 #{PWD} ,对象存储变量: #{Endpoint} #{AccessKey} #{SecretKey} #{BucketName}
<br/>例: mysqldump -h192.168.1.11 -uroot -p#{PWD} db-name > #{DATE}.sql <a target="blank" href="https://github.com/jeessy2/backup-x#备份脚本参考">备份脚本参考</a>
</small>
</div>
</div>

<div class="form-group row">
<label for="BackupType_{{$i}}" class="col-sm-2">备份类型</label>
<label for="Pwd_{{$i}}" class="col-sm-2 col-form-label">密码变量</label>
<div class="col-sm-10">
<select class="form-control" name="BackupType" id="BackupType_{{$i}}" value="{{$v.BackupType}}">
<option value="0" {{if eq $v.BackupType 0}}selected{{end}}>备份数据库</option>
<option value="1" {{if eq $v.BackupType 1}}selected{{end}}>同步文件</option>
</select>
<small id="BackupType_help" class="form-text text-muted">如果没有输出文件, 请选择同步文件</small>
<input type="password" class="form-control" name="Pwd" id="Pwd_{{$i}}" value="{{$v.Pwd}}">
</div>
</div>

<div class="form-group row">
<label for="Pwd_{{$i}}" class="col-sm-2 col-form-label">密码变量</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="Pwd" id="Pwd_{{$i}}" value="{{$v.Pwd}}">
<label for="Enabled_{{$i}}" class="col-sm-2">是否启用</label>
<div class="col-sm-4">
<select class="form-control" name="Enabled" id="Enabled_{{$i}}" value="{{$v.Enabled}}">
<option value="0" {{if eq $v.Enabled 0}}selected{{end}}>启用</option>
<option value="1" {{if eq $v.Enabled 1}}selected{{end}}>停用</option>
</select>
</div>
<label for="BackupType_{{$i}}" class="col-sm-2">备份类型</label>
<div class="col-sm-4">
<select class="form-control" name="BackupType" id="BackupType_{{$i}}" value="{{$v.BackupType}}">
<option value="0" {{if eq $v.BackupType 0}}selected{{end}}>备份数据库</option>
<option value="1" {{if eq $v.BackupType 1}}selected{{end}}>同步文件</option>
</select>
</div>
</div>

Expand Down

0 comments on commit 842f16a

Please sign in to comment.