2020-04-03 19:54:53 +08:00
|
|
|
# grsync
|
|
|
|
|
2021-07-12 18:27:37 +08:00
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"grsync"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
task := grsync.NewTask(
|
|
|
|
"username@server.com:/source/folder",
|
|
|
|
"/home/user/destination",
|
|
|
|
grsync.RsyncOptions{},
|
|
|
|
)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
state := task.State()
|
|
|
|
fmt.Printf(
|
|
|
|
"progress: %.2f / rem. %d / tot. %d / sp. %s \n",
|
|
|
|
state.Progress,
|
|
|
|
state.Remain,
|
|
|
|
state.Total,
|
|
|
|
state.Speed,
|
|
|
|
)
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err := task.Run(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("well done")
|
|
|
|
fmt.Println(task.Log())
|
|
|
|
}
|
|
|
|
```
|