#git-repository #github #git #backup #command-line-tool

app gitout

一款用于从 GitHub 或任何地方自动备份 Git 仓库的命令行工具

2 个不稳定版本

0.2.0 2020年5月24日
0.1.0 2020年5月20日
0.0.1 2020年5月18日

命令行工具 中排名第 2963

MIT 许可协议

770KB
33K SLoC

GraphQL 33K SLoC Rust 308 SLoC // 0.1% comments Shell 56 SLoC // 0.3% comments

Git Out

一款用于从 GitHub 或任何地方自动备份 Git 仓库的命令行工具。

gitout 工具将从 GitHub 或其他任何 Git 托管服务克隆 git 仓库。如果仓库已被克隆,它将获取任何更新以保持本地副本同步。

当您添加 GitHub 用户名和令牌时,gitout 将发现您拥有的所有仓库并自动同步它们。您还可以选择同步您已标记或关注的仓库。

克隆的仓库是 裸仓库。换句话说,没有文件的工作副本供您交互。如果您需要访问文件,您可以运行 git clone /path/to/bare/repo

安装

Rust

如果您已安装 Rust,可以通过运行 cargo install gitout 安装二进制文件。

Latest version

Docker

二进制文件可在 jakewharton/gitout Docker 容器中找到,您可以用作 cron 作业运行它。

Docker Image Version Docker Image Size

挂载一个 /data 卷,这是存储仓库的位置。挂载包含 config.toml/config 文件夹,或者直接挂载 /config/config.toml 文件。指定一个 CRON 环境变量,其中包含 cron 指定器,以指定工具运行的时间表。

$ docker run -d \
    -v /path/to/data:/data \
    -v /path/to/config.toml:/config/config.toml \
    -e "CRON=0 * * * *" \
    jakewharton/gitout

有关创建有效 cron 指定器的帮助,请访问 cron.help

要通知同步失败,请访问 https://healthchecks.io,创建一个检查,并使用 HEALTHCHECK_ID 环境变量指定容器的 ID(例如,-e "HEALTHCHECK_ID=...")。

要作为特定用户写入数据,可以将 PUIDPGID 环境变量分别设置为您的用户 ID 和组 ID。

如果您使用 Docker Compose,示例设置如下;

services:
  gitout:
    image: jakewharton/gitout:latest
    restart: unless-stopped
    volumes:
      - /path/to/data:/data
      - /path/to/config:/config
    environment:
      - "CRON=0 * * * *"
      #Optional:
      - "HEALTHCHECK_ID=..."
      - "PUID=..."
      - "PGID=..."

注意:您可能希望指定一个明确的版本,而不是 最新。请参阅 https://hub.docker.com/r/jakewharton/gitout/tagsCHANGELOG.md 以获取可用的版本。

二进制文件

TODO GitHub 发布下载二进制文件 https://github.com/JakeWharton/gitout/issues/8

使用方法

$ gitout --help
gitout 0.1.0

USAGE:
    gitout [FLAGS] <config> <destination>

FLAGS:
        --dry-run    Print actions instead of performing them
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --verbose    Enable verbose logging

ARGS:
    <config>         Configuration file
    <destination>    Backup directory

配置规范

直到工具的 1.0 版本,TOML 版本设置为 0,并且可能在不兼容的方式在 0.x 版本之间发生变化。您可以在 CHANGELOG.md 文件中找到迁移信息。

version = 0

[github]
user = "example"
token = "abcd1234efgh5678ij90"

[github.clone]
starred = true  # Optional, default false
watched = true  # Optional, default false
# Extra repos to synchronize that are not owned, starred, or watched by you.
repos = [
  "JakeWharton/gitout",
]

# Repos not on GitHub to synchronize.
[git.repos]
asm = "https://gitlab.ow2.org/asm/asm.git"

创建 GitHub 令牌

  1. 访问 https://github.com/settings/tokens
  2. 点击 "生成新令牌"
  3. 在名称字段中输入 "gitout"
  4. 选择 "repo" 和 "read:user" 范围
    • repo:需要克隆私有仓库(如果您只有公共仓库,则只需 public_repo 也将工作)
    • read::user:需要遍历您拥有的、标记的和关注的仓库列表
  5. 选择 "生成令牌"
  6. 将值复制到您的 config.toml 中,因为它将不再显示

开发

如果您已安装 Rust,可以使用 cargo build 构建 debug 二进制文件,并使用 cargo build --release 构建 release 二进制文件。二进制文件将分别位于 target/debug/gitouttarget/release/gitout。使用 cargo test 运行所有测试。使用 cargo fmt 格式化代码。使用 cargo clippy 运行 Clippy 工具。

如果您有 Docker 但没有 Rust,请运行 docker build .,它将做所有事情。这是 CI 上运行的版本。

许可证

MIT。请参阅 LICENSE.txt

Copyright 2020 Jake Wharton

依赖项

~13–18MB
~412K SLoC