Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
🔨 refactor backup
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Jun 12, 2018
1 parent 7bc1733 commit fee3c08
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 122 deletions.
56 changes: 15 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,29 @@ tale命令行帮助程序 🌟

## 安装

**linux_64位**

```bash
cd tale
wget http://static.biezhi.me/tale-cli
chmod +x tale-cli
```
目前二进制文件存储在仓库 `bin` 目录,等发布版本后会提供一个在线下载地址。

## 帮助

```bash
# tale-cli

NAME:
tale - tale的命令行帮助程序
» ./tale-cli

USAGE:
tale-cli [global options] command [command options] [arguments...]
Tale 博客程序帮助工具

VERSION:
0.0.2
Github: https://github.com/otale/tale

AUTHOR:
https://github.com/biezhi <[email protected]>
Usage:
tale-cli command [arguments]

COMMANDS:
start 启动tale
stop 停止当前tale实例
reload 重新启动当前tale实例
log 查看当前tale日志
status 查看当前tale状态
upgrade 升级当前的tale版本
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```

## 操作指令

```bash
./tale-cli start : 启动tale
./tale-cli stop : 停止tale实例
./tale-cli reload : 重启tale实例
./tale-cli log : 查看当前tale日志
./tale-cli status : 查看当前tale运行状态
./tale-cli upgrade: 升级tale版本,会自动帮你备份
Available commands:
backup 备份 Tale 博客
log 查看 Tale 博客日志
restart 重启 Tale 博客
start 启动 Tale 博客
status 查看 Tale 博客运行状态
stop 停止 Tale 博客
upgrade 升级 Tale 博客
```

> 备份的文件在当前目录下形如 `tale_backup_201709109281.zip`
> 备份的文件在当前目录下形如 `backup_201709109281.zip`
Binary file modified bin/linux_64/tale-cli
Binary file not shown.
Binary file modified bin/macOSX_64/tale-cli
Binary file not shown.
30 changes: 21 additions & 9 deletions cmds/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmds

import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
Expand All @@ -11,6 +12,7 @@ import (
"strings"
"time"

"github.com/biezhi/moe"
"github.com/mholt/archiver"
)

Expand Down Expand Up @@ -170,14 +172,15 @@ func UpgradeAction() error {
}
}

moe := moe.New("下载最新版本信息").Start()
var version Version
body := GetRequestBody(statusURL)
moe.Stop()
if err := json.Unmarshal(body, &version); err != nil {
log.Println("解析JSON失败")
return err
}
log.Println(version)


if ver != "" {
verInt, _ := strconv.Atoi(ver)
leteatVer, _ := strconv.Atoi(version.PublishTime)
Expand All @@ -193,10 +196,8 @@ func UpgradeAction() error {
newZipName := DownloadFile(version.DownloadURL, "./")

// 备份
datetime := time.Now().Format("20060102_150405") + ".zip"
err := archiver.Zip.Make(datetime, []string{"resources", "lib", "tale-least.jar"})
err := BackupAction()
if err != nil {
log.Println("备份失败")
return err
}
// 删除旧文件
Expand All @@ -223,12 +224,23 @@ func UpgradeAction() error {

// BackupAction 备份博客,SQL和当前全部状态
func BackupAction() error {
// 备份 SQL
_, _, _, err := StartCmd("sqlite3 tale.db .dump > tale.sql")
// 备份目录
zipFile := fmt.Sprintf("backup_%s.zip", time.Now().Format("20060102_150405"))
files := []string{"resources", "lib"}

if _, err := os.Stat("tale-least.jar"); err == nil {
files = append(files, "tale-least.jar")
}

if _, err := os.Stat("tale-latest.jar"); err == nil {
files = append(files, "tale-latest.jar")
}

err := archiver.Zip.Make(zipFile, files)
if err != nil {
log.Println("备份失败")
return err
}
// 备份目录

log.Println("备份成功:", zipFile)
return nil
}
71 changes: 0 additions & 71 deletions d/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mkdir -p bin/linux_64
mkdir -p bin/macOSX_64

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o bin/linux_64/tale-cli && upx bin/linux_64/tale-cli
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags '-w -s' -o bin/macOSX_64/tale-cli && upx bin/macOSX_64/tale-cli
CGO_ENABLED=0 go build -ldflags '-w -s' -o bin/macOSX_64/tale-cli && upx bin/macOSX_64/tale-cli

0 comments on commit fee3c08

Please sign in to comment.