README.md 21.7 KB
Newer Older
M
mstmdev 已提交
1 2
# gofs

3
[![Build](https://img.shields.io/github/actions/workflow/status/no-src/gofs/go.yml?branch=main)](https://github.com/no-src/gofs/actions)
M
mstmdev 已提交
4 5
[![License](https://img.shields.io/github/license/no-src/gofs)](https://github.com/no-src/gofs/blob/main/LICENSE)
[![Go Reference](https://pkg.go.dev/badge/github.com/no-src/gofs.svg)](https://pkg.go.dev/github.com/no-src/gofs)
M
mstmdev 已提交
6
[![Go Report Card](https://goreportcard.com/badge/github.com/no-src/gofs)](https://goreportcard.com/report/github.com/no-src/gofs)
M
mstmdev 已提交
7
[![codecov](https://codecov.io/gh/no-src/gofs/branch/main/graph/badge.svg?token=U5K9HV78P0)](https://codecov.io/gh/no-src/gofs)
M
mstmdev 已提交
8
[![Release](https://img.shields.io/github/v/release/no-src/gofs)](https://github.com/no-src/gofs/releases)
M
mstmdev 已提交
9
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
M
mstmdev 已提交
10

M
mstmdev 已提交
11 12
English | [简体中文](README-CN.md)

13
A cross-platform real-time file synchronization tool out of the box based on Golang.
M
mstmdev 已提交
14

M
mstmdev 已提交
15 16
## Installation

M
mstmdev 已提交
17
The first need [Go](https://go.dev/doc/install) installed (**version 1.20+ is required**), then you can use the below
18 19
command to install `gofs`.

M
mstmdev 已提交
20 21 22 23
```bash
go install github.com/no-src/gofs/...@latest
```

24 25
### Run In Docker

M
mstmdev 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38
You can use the [build-docker.sh](/scripts/build-docker.sh) script to build the docker image and you should clone this
repository and `cd` to the root path of the repository first.

```bash
$ ./scripts/build-docker.sh
```

Or pull the docker image directly from [DockerHub](https://hub.docker.com/r/nosrc/gofs) with the command below.

```bash
$ docker pull nosrc/gofs
```

M
mstmdev 已提交
39
For more scripts about release and docker, see the [scripts](/scripts) directory.
M
mstmdev 已提交
40

M
mstmdev 已提交
41
### Run In the Background
M
mstmdev 已提交
42

M
mstmdev 已提交
43
You can install a program run in the background using the following command on Windows.
44

45
```bash
46 47 48
go install -ldflags="-H windowsgui" github.com/no-src/gofs/...@latest
```

M
mstmdev 已提交
49 50
## Quick Start

M
mstmdev 已提交
51 52
### Prerequisites

M
mstmdev 已提交
53
Please ensure the source directory and dest directory exists first, replace the following path with your real path.
M
mstmdev 已提交
54 55

```bash
M
mstmdev 已提交
56
$ mkdir source dest
M
mstmdev 已提交
57 58 59 60 61 62 63 64 65 66 67
```

Generate the TLS cert file and key file for testing purposes.

The TLS cert and key files are just used by [File Server](#file-server) and [Remote Disk Server](#remote-disk-server).

```bash
$ go run $GOROOT/src/crypto/tls/generate_cert.go --host 127.0.0.1
2021/12/30 17:21:54 wrote cert.pem
2021/12/30 17:21:54 wrote key.pem
```
M
mstmdev 已提交
68

M
mstmdev 已提交
69
Look up our workspace.
M
mstmdev 已提交
70 71

```bash
M
mstmdev 已提交
72
$ ls
M
mstmdev 已提交
73
cert.pem  key.pem  source  dest
M
mstmdev 已提交
74 75
```

76 77 78 79 80 81
### Usage

#### Between Disks

Synchronize files between disks by [Local Disk](#local-disk).

82 83 84 85 86 87 88 89 90 91 92 93 94
```mermaid
sequenceDiagram
    participant DA as DiskA
    participant C as Client
    participant DB as DiskB

    autonumber

    C ->> DA: monitor disk
    DA ->> C: notify change
    C ->> DA: read file
    DA ->> C: return file
    C ->> DB: write file
95 96 97 98 99 100 101
```

#### From Server

Synchronize files from server by [Remote Disk Server](#remote-disk-server)
and [Remote Disk Client](#remote-disk-client).

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
```mermaid
sequenceDiagram
    participant SD as Server Disk
    participant S as Server
    participant C as Client
    participant CD as Client Disk

    autonumber

    S ->> SD: monitor disk
    C ->> S: connect and auth
    SD ->> S: notify change
    S ->> C: notify change
    C ->> S: pull file
    S ->> SD: read file
    SD ->> S: return file
    S ->> C: send file
    C ->> CD: write file
120 121 122 123 124 125
```

#### To Server

Synchronize files to server by [Remote Push Server](#remote-push-server) and [Remote Push Client](#remote-push-client).

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
```mermaid
sequenceDiagram
    participant CD as Client Disk
    participant C as Client
    participant S as Server
    participant SD as Server Disk

    autonumber

    C ->> CD: monitor disk
    CD ->> C: notify change
    C ->> CD: read file
    CD ->> C: return file
    C ->> S: push file
    S ->> SD: write file
141 142 143 144 145 146
```

#### From SFTP Server

Synchronize files from SFTP server by [SFTP Pull Client](#sftp-pull-client).

147 148 149 150 151 152 153 154 155 156 157 158 159 160
```mermaid
sequenceDiagram
    participant CD as Client Disk
    participant C as Client
    participant SS as SFTP Server
    participant SSD as SFTP Server Disk

    autonumber

    C ->> SS: pull file
    SS ->> SSD: read file
    SSD ->> SS: return file
    SS ->> C: send file
    C ->> CD: write file
161 162 163 164 165 166
```

#### To SFTP Server

Synchronize files to SFTP server by [SFTP Push Client](#sftp-push-client).

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
```mermaid
sequenceDiagram
    participant CD as Client Disk
    participant C as Client
    participant SS as SFTP Server
    participant SSD as SFTP Server Disk

    autonumber

    C ->> CD: monitor disk
    CD ->> C: notify change
    C ->> CD: read file
    CD ->> C: return file
    C ->> SS: push file
    SS ->> SSD: write file
182 183 184 185 186 187
```

#### From MinIO Server

Synchronize files from MinIO server by [MinIO Pull Client](#minio-pull-client).

188 189 190 191 192 193 194 195 196 197 198 199 200 201
```mermaid
sequenceDiagram
    participant CD as Client Disk
    participant C as Client
    participant MS as MinIO Server
    participant MSD as MinIO Server Disk

    autonumber

    C ->> MS: pull file
    MS ->> MSD: read file
    MSD ->> MS: return file
    MS ->> C: send file
    C ->> CD: write file
202 203 204 205 206 207
```

#### To MinIO Server

Synchronize files to MinIO server by [MinIO Push Client](#minio-push-client).

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
```mermaid
sequenceDiagram
    participant CD as Client Disk
    participant C as Client
    participant MS as MinIO Server
    participant MSD as MinIO Server Disk

    autonumber

    C ->> CD: monitor disk
    CD ->> C: notify change
    C ->> CD: read file
    CD ->> C: return file
    C ->> MS: push file
    MS ->> MSD: write file
223 224
```

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
#### Task Mode

Start a [Task Client](#task-client) to subscribe to the [Task Server](#task-server), then acquire the task and execute
it, take the [From Server](#from-server) for example.

```mermaid
sequenceDiagram
    participant A as Admin
    participant TS as Task Server
    participant SD as Server Disk
    participant S as Server
    participant TC as Task Client
    participant CW as Client Worker
    participant CD as Client Disk
    participant TQ as Task Queue

    autonumber

    S ->> SD: monitor disk
    S ->> TS: start task server
    A ->> TS: create task
    TC ->> TS: subscribe task
    TS ->> TC: distribute task
    TC ->> CW: start worker
    CW ->> TQ: add to task queue
    TQ ->> CW: execute task
    activate CW
    CW ->> S: connect and auth
    loop
        SD ->> S: notify change
        S ->> CW: notify change
        CW ->> S: pull file
        S ->> SD: read file
        SD ->> S: return file
        S ->> CW: send file
        CW ->> CD: write file
    end
    deactivate CW
```

265 266
## Features

M
mstmdev 已提交
267
### Local Disk
M
mstmdev 已提交
268

M
mstmdev 已提交
269
Monitor source directory and sync change files to dest directory.
M
mstmdev 已提交
270

M
mstmdev 已提交
271 272
You can use the `logically_delete` flag to enable the logically delete and avoid deleting files by mistake.

273 274 275 276 277 278
Set the `checkpoint_count` flag to use the checkpoint in the file to reduce transfer unmodified file chunks, by
default `checkpoint_count=10`, which means it has `10+2` checkpoints at most. There are two additional checkpoints at
the head and tail. The first checkpoint is equal to the `chunk_size`, it is optional. The last checkpoint is equal to
the file size, it is required. The checkpoint offset set by the `checkpoint_count` is always more than `chunk_size`,
unless the file size is less than or equal to `chunk_size`, then the `checkpoint_count` will be zero, so it is optional.

279 280 281 282
By default, if the file size and file modification time of the source file is equal to the destination file, then ignore
the current file transfer. You can use the `force_checksum` flag to force enable the checksum to compare whether the
file is equal or not.

283 284 285 286
The default checksum hash algorithm is `md5`, you can use the `checksum_algorithm` flag to change the default hash
algorithm, current supported algorithms: `md5`, `sha1`, `sha256`, `sha512`, `crc32`, `crc64`, `adler32`, `fnv-1-32`
, `fnv-1a-32`, `fnv-1-64`, `fnv-1a-64`, `fnv-1-128`, `fnv-1a-128`.

287 288 289 290
If you want to reduce the frequency of synchronization, you can use the `sync_delay` flag to enable sync delay, start
sync when the event count is equal or greater than `sync_delay_events`, or wait for `sync_delay_time` interval time
since the last sync.

291 292
And you can use the `progress` flag to print the file sync progress bar.

M
mstmdev 已提交
293
```bash
M
mstmdev 已提交
294
$ gofs -source=./source -dest=./dest
295 296
```

297 298 299 300 301 302
### Encryption

You can use `encrypt` flag to enable encryption and specify a directory as an encryption workspace by `encrypt_path`
flag. All files in the directory will be encrypted then sync to the destination path.

```bash
M
mstmdev 已提交
303
$ gofs -source=./source -dest=./dest -encrypt -encrypt_path=./source/encrypt -encrypt_secret=mysecret_16bytes
304 305 306 307 308 309 310
```

### Decryption

You can use the `decrypt` flag to decrypt the encryption files to a specified path.

```bash
M
mstmdev 已提交
311
$ gofs -decrypt -decrypt_path=./dest/encrypt -decrypt_secret=mysecret_16bytes -decrypt_out=./decrypt_out
312 313
```

314
### Sync Once
M
mstmdev 已提交
315

M
mstmdev 已提交
316
Sync the whole path immediately from source directory to dest directory.
M
mstmdev 已提交
317 318

```bash
M
mstmdev 已提交
319
$ gofs -source=./source -dest=./dest -sync_once
M
mstmdev 已提交
320 321
```

322 323
### Sync Cron

M
mstmdev 已提交
324
Sync the whole path from source directory to dest directory with cron.
325 326

```bash
M
mstmdev 已提交
327 328
# Per 30 seconds sync the whole path from source directory to dest directory
$ gofs -source=./source -dest=./dest -sync_cron="*/30 * * * * *"
329 330
```

M
mstmdev 已提交
331 332
### Daemon Mode

333 334 335
Start a daemon to create subprocess to work, and record pid info to pid file.

```bash
M
mstmdev 已提交
336
$ gofs -source=./source -dest=./dest -daemon -daemon_pid
337 338
```

M
mstmdev 已提交
339 340
### File Server

M
mstmdev 已提交
341
Start a file server for source directory and dest directory.
M
mstmdev 已提交
342

343 344
The file server is use HTTPS default, set the `tls_cert_file` and `tls_key_file` flags to customize the cert file and
key file.
M
mstmdev 已提交
345

346
You can disable the HTTPS by set the `tls` flag to `false` if you don't need it.
M
mstmdev 已提交
347

348 349
If you set the `tls` to `true`, the file server default port is `443`, otherwise it is `80`, and you can customize the
default port with the `server_addr` flag, like `-server_addr=":443"`.
M
mstmdev 已提交
350

351 352
If you enable the `tls` flag on the server side, you can control whether a client skip verifies the server's certificate
chain and host name by the `tls_insecure_skip_verify` flag, default is `true`.
353

354 355
If you already enable the `tls` flag, then you can use the `http3` flag to enable the HTTP3 protocol in the server and
client sides.
356

357 358
You should set the `rand_user_count` flag to auto generate some random users or set the `users` flag to customize server
users for security reasons.
M
mstmdev 已提交
359

360
The server users will output to log if you set the `rand_user_count` flag greater than zero.
361

362
If you need to compress the files, add the `server_compress` flag to enable gzip compression for response, but it is not
M
mstmdev 已提交
363
fast now, and may reduce transmission efficiency in the LAN.
M
mstmdev 已提交
364

365 366 367
You can switch the session store mode for the file server by `session_connection` flag,
currently supports memory and redis, default is memory.
If you want to use the redis as the session store, here is an example for redis session connection string:
368 369
`redis://127.0.0.1:6379?password=redis_password&db=10&max_idle=10&secret=redis_secret`.

370
```bash
M
mstmdev 已提交
371 372
# Start a file server and create three random users
# Replace the `tls_cert_file` and `tls_key_file` flags with your real cert files in the production environment
M
mstmdev 已提交
373
$ gofs -source=./source -dest=./dest -server -tls_cert_file=cert.pem -tls_key_file=key.pem -rand_user_count=3
374 375
```

376 377 378 379 380 381 382 383 384 385 386
### Rate Limit

Use the `max_tran_rate` flag to limit the max transmission rate in the server and client sides,
and this is an expected value, not an absolute one.

For example, limit the max transmission rate to 1048576 bytes, means 1MB.

```bash
$ gofs -source=./source -dest=./dest -max_tran_rate=1048576
```

M
mstmdev 已提交
387 388
### Remote Disk Server

389 390
Start a remote disk server as a remote file source.

M
mstmdev 已提交
391
The `source` flag detail see [Remote Server Source Protocol](#remote-server-source-protocol).
392

393 394
Pay attention to that remote disk server users must have read permission at least, for
example, `-users="gofs|password|r"`.
395

396
You can use the `checkpoint_count` and `sync_delay` flags like the [Local Disk](#local-disk).
397

398
```bash
M
mstmdev 已提交
399 400 401
# Start a remote disk server
# Replace the `tls_cert_file` and `tls_key_file` flags with your real cert files in the production environment
# Replace the `users` flag with complex username and password for security
M
mstmdev 已提交
402
$ gofs -source="rs://127.0.0.1:8105?mode=server&local_sync_disabled=true&path=./source&fs_server=https://127.0.0.1" -dest=./dest -users="gofs|password|r" -tls_cert_file=cert.pem -tls_key_file=key.pem -token_secret=mysecret_16bytes
M
mstmdev 已提交
403 404 405 406 407 408
```

### Remote Disk Client

Start a remote disk client to sync change files from remote disk server.

409 410
The `source` flag detail see [Remote Server Source Protocol](#remote-server-source-protocol).

411 412
Use the `sync_once` flag to sync the whole path immediately from remote disk server to local dest directory,
like [Sync Once](#sync-once).
413

414 415
Use the `sync_cron` flag to sync the whole path from remote disk server to local dest directory with cron,
like [Sync Cron](#sync-cron).
M
mstmdev 已提交
416

417 418 419
Use the `force_checksum` flag to force enable the checksum to compare whether the file is equal or not,
like [Local Disk](#local-disk).

420
You can use the `sync_delay` flag like the [Local Disk](#local-disk).
421

M
mstmdev 已提交
422 423 424
```bash
# Start a remote disk client
# Replace the `users` flag with your real username and password
M
mstmdev 已提交
425
$ gofs -source="rs://127.0.0.1:8105" -dest=./dest -users="gofs|password" -tls_cert_file=cert.pem
426 427 428 429
```

### Remote Push Server

430 431
Start a [Remote Disk Server](#remote-disk-server) as a remote file source, then enable the remote push server with
the `push_server` flag.
432

433 434
Pay attention to that remote push server users must have read and write permission at least, for
example, `-users="gofs|password|rw"`.
435 436 437 438 439

```bash
# Start a remote disk server and enable the remote push server
# Replace the `tls_cert_file` and `tls_key_file` flags with your real cert files in the production environment
# Replace the `users` flag with complex username and password for security
M
mstmdev 已提交
440
$ gofs -source="rs://127.0.0.1:8105?mode=server&local_sync_disabled=true&path=./source&fs_server=https://127.0.0.1" -dest=./dest -users="gofs|password|rw" -tls_cert_file=cert.pem -tls_key_file=key.pem -push_server -token_secret=mysecret_16bytes
441 442 443 444 445 446
```

### Remote Push Client

Start a remote push client to sync change files to the [Remote Push Server](#remote-push-server).

447 448
Use the `chunk_size` flag to set the chunk size of the big file to upload. The default value of `chunk_size`
is `1048576`, which means `1MB`.
449

450
You can use the `checkpoint_count` and `sync_delay` flags like the [Local Disk](#local-disk).
451

452 453 454 455 456
More flag usage see [Remote Disk Client](#remote-disk-client).

```bash
# Start a remote push client and enable local disk sync, sync the file changes from source path to the local dest path and the remote push server
# Replace the `users` flag with your real username and password
M
mstmdev 已提交
457
$ gofs -source="./source" -dest="rs://127.0.0.1:8105?local_sync_disabled=false&path=./dest" -users="gofs|password" -tls_cert_file=cert.pem
458 459
```

460
### SFTP Push Client
461

462
Start a SFTP push client to sync change files to the SFTP server.
463 464 465 466 467

```bash
$ gofs -source="./source" -dest="sftp://127.0.0.1:22?local_sync_disabled=false&path=./dest&remote_path=/gofs_sftp_server" -users="sftp_user|sftp_pwd"
```

468 469 470 471 472 473 474 475
### SFTP Pull Client

Start a SFTP pull client to pull the files from the SFTP server to the local destination path.

```bash
$ gofs -source="sftp://127.0.0.1:22?remote_path=/gofs_sftp_server" -dest="./dest" -users="sftp_user|sftp_pwd" -sync_once
```

476 477 478 479 480
### MinIO Push Client

Start a MinIO push client to sync change files to the MinIO server.

```bash
481
$ gofs -source="./source" -dest="minio://127.0.0.1:9000?secure=false&local_sync_disabled=false&path=./dest&remote_path=minio-bucket" -users="minio_user|minio_pwd"
482 483 484 485 486 487 488
```

### MinIO Pull Client

Start a MinIO pull client to pull the files from the MinIO server to the local destination path.

```bash
489
$ gofs -source="minio://127.0.0.1:9000?secure=false&remote_path=minio-bucket" -dest="./dest" -users="minio_user|minio_pwd" -sync_once
490 491
```

492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
### Task Server

Start a task server to distribute the tasks to clients.

Take the [Remote Disk Server](#remote-disk-server) for example, create a task manifest config file like
the [remote-disk-task.yaml](/integration/testdata/conf/task/remote-disk-task.yaml) file first.
Here defined a task that synchronizes files from server.

Then create the task content config
file [run-gofs-remote-disk-client.yaml](/integration/testdata/conf/run-gofs-remote-disk-client.yaml) that defined in the
above manifest config file, and it will be executed by client.

Finally, start the remote disk server with the `task_conf` flag.

Here use `conf` to simplify the command and reuse the integration test config files.

```bash
$ cd integration
$ mkdir -p rs/source rs/dest
$ gofs -conf=./testdata/conf/run-gofs-remote-disk-server.yaml
```

### Task Client

Start a task client to subscribe to the task server, then acquire the task and execute it.

Use the `task_client` flag to start the task client, and the `task_client_max_worker` flag will limit the max
concurrent workers in the task client side.

And you can use the `task_client_labels` flag to define the labels of the task client that use to match the task in the
task server side.

Here use `conf` to simplify the command and reuse the integration test config files.

```bash
$ cd integration
$ mkdir -p rc/source rc/dest
$ gofs -conf=./testdata/conf/run-gofs-task-client.yaml
```

M
mstmdev 已提交
532 533 534 535 536
### Relay

If you need to synchronize files between two devices that are unable to establish a direct connection, you can use a
reverse proxy as a relay server. In more detail, see also [Relay](/relay/README.md).

537 538 539 540 541 542 543 544 545 546
### Remote Server Source Protocol

The remote server source protocol is based on URI, see [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986.html).

#### Scheme

The scheme name is `rs`.

#### Host

547 548
The remote server source uses `0.0.0.0` or other local ip address as host in [Remote Disk Server](#remote-disk-server)
mode, and use ip address or domain name as host in [Remote Disk Client](#remote-disk-client) mode.
549 550 551 552 553 554 555 556 557

#### Port

The remote server source port, default is `8105`.

#### Parameter

Use the following parameters in [Remote Disk Server](#remote-disk-server) mode only.

M
mstmdev 已提交
558
- `path` the [Remote Disk Server](#remote-disk-server) actual local source directory
559 560
- `mode` running mode, in [Remote Disk Server](#remote-disk-server) mode is `server`, default is running
  in [Remote Disk Client](#remote-disk-client) mode
561
- `fs_server` [File Server](#file-server) address, like `https://127.0.0.1`
562 563
- `local_sync_disabled` disabled [Remote Disk Server](#remote-disk-server) sync changes to its local dest path, `true`
  or `false`, default is `false`
564 565 566 567 568 569

#### Example

For example, in [Remote Disk Server](#remote-disk-server) mode.

```text
M
mstmdev 已提交
570 571
 rs://127.0.0.1:8105?mode=server&local_sync_disabled=true&path=./source&fs_server=https://127.0.0.1
 \_/  \_______/ \__/ \____________________________________________________________________________/
572 573
  |       |       |                                      |
scheme   host    port                                parameter
M
mstmdev 已提交
574 575
```

576
### Manage API
M
mstmdev 已提交
577

578
Enable manage api base on [File Server](#file-server) by using the `manage` flag.
M
mstmdev 已提交
579

580
By default, allow to access manage api by private address and loopback address only.
M
mstmdev 已提交
581

582
You can disable it by setting the `manage_private` flag to `false`.
M
mstmdev 已提交
583 584

```bash
585
$ gofs -source=./source -dest=./dest -server -tls_cert_file=cert.pem -tls_key_file=key.pem -rand_user_count=3 -manage
M
mstmdev 已提交
586 587
```

588
#### Profiling API
589

M
mstmdev 已提交
590 591
The pprof url address like this

M
mstmdev 已提交
592
```text
593 594 595
https://127.0.0.1/manage/pprof/
```

596
#### Config API
597 598 599 600 601 602 603 604 605 606 607 608

Reading the program config, default return the config with `json` format, and support `json` and `yaml` format
currently.

```text
https://127.0.0.1/manage/config
```

Or use the `format` parameter to specific the config format.

```text
https://127.0.0.1/manage/config?format=yaml
M
mstmdev 已提交
609 610
```

611 612 613 614 615 616 617 618 619 620 621
#### Report API

Use the `report` flag to enable report api route, and start to collect the report data, need to enable the `manage` flag
first.

The details of the report api see [Report API](/server/README.md#report-api).

```text
https://127.0.0.1/manage/report
```

622 623
### Logger

624 625
Enable the file logger and console logger by default, and you can disable the file logger by setting the `log_file` flag
to `false`.
626 627 628 629 630 631 632 633 634 635 636

Use the `log_level` flag to set the log level, default is `INFO`, (`DEBUG=0` `INFO=1` `WARN=2` `ERROR=3`).

Use the `log_dir` flag to set the directory of the log file, default is `./logs/`.

Use the `log_flush` flag to enable auto flush log with interval, default is `true`.

Use the `log_flush_interval` flag to set the log flush interval duration, default is `3s`.

Use the `log_event` flag to enable the event log, write to file, default is `false`.

637 638 639
Use the `log_sample_rate` flag to set the sample rate for the sample logger, and the value ranges from 0 to 1, default
is `1`.

640 641
Use the `log_format` flag to set the log output format, current support `text` and `json`, default is `text`.

642 643
Use the `log_split_date` flag to split log file by date, default is `false`.

644 645
```bash
# set the logger config in "Local Disk" mode
M
mstmdev 已提交
646
$ gofs -source=./source -dest=./dest -log_file -log_level=0 -log_dir="./logs/" -log_flush -log_flush_interval=3s -log_event
647 648
```

649 650 651 652 653 654 655 656 657 658 659
### Use Configuration File

If you want, you can use a configuration file to replace all the flags.It supports `json` and `yaml` format currently.

All the configuration fields are the same as the flags, you can refer to the [Configuration Example](/conf/example)
or the response of [Config API](#config-api).

```bash
$ gofs -conf=./gofs.yaml
```

660 661 662 663
### Checksum

You can use the `checksum` flag to calculate the file checksum and print the result.

664 665
The `chunk_size`, `checkpoint_count` and `checksum_algorithm` flags are effective here the same as in
the [Local Disk](#local-disk).
666 667 668 669 670

```bash
$ gofs -source=./gofs -checksum
```

M
mstmdev 已提交
671 672 673 674 675
## For More Information

### Help Info

```bash
M
mstmdev 已提交
676
$ gofs -h
677 678
```

M
mstmdev 已提交
679
### Version Info
680 681

```bash
M
mstmdev 已提交
682
$ gofs -v
M
mstmdev 已提交
683 684 685 686 687 688
```

### About Info

```bash
$ gofs -about
689 690 691 692 693 694
```

### Web UI

The [gofs-webui](https://github.com/no-src/gofs-webui) is a web UI tool for `gofs`, and it allows you to generate the
config file of `gofs` through the web UI, making the use of gofs easier.