{"id":22437266,"url":"https://github.com/ustclug/rb-backup","last_synced_at":"2026-03-05T22:33:35.691Z","repository":{"id":29374916,"uuid":"32909716","full_name":"ustclug/rb-backup","owner":"ustclug","description":"基于 rsync 和 ssh 的远程备份脚本，利用 btrfs snapshot 实现增量备份……","archived":false,"fork":false,"pushed_at":"2018-03-20T05:01:02.000Z","size":128,"stargazers_count":29,"open_issues_count":1,"forks_count":12,"subscribers_count":11,"default_branch":"master","last_synced_at":"2023-08-31T09:06:59.493Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ustclug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-26T05:41:38.000Z","updated_at":"2023-08-05T22:10:27.000Z","dependencies_parsed_at":"2022-09-05T21:00:36.642Z","dependency_job_id":null,"html_url":"https://github.com/ustclug/rb-backup","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustclug%2Frb-backup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustclug%2Frb-backup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustclug%2Frb-backup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustclug%2Frb-backup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ustclug","download_url":"https://codeload.github.com/ustclug/rb-backup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228389156,"owners_count":17912189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T00:12:19.789Z","updated_at":"2026-03-05T22:33:30.661Z","avatar_url":"https://github.com/ustclug.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rb-backup\n\n一个简单的远程机器增量备份脚本。大概思路是这样的（运行这个脚本并存储备份文件的机器叫 Server，待备份的机器叫 Client）：\n* Server 通过 rsync over SSH 从 Client 抓要备份的文件，存储到一个 btrfs subvolume 中。\n* 备份后，Server 为存放备份文件的 subvolume 创建一个 snapshot，这样就可以记录历史备份了。\n\n## Client 配置\n\n创建一个备份用的用户，该用户至少要对待备份文件有读权限。配置 SSH，使得我们可以从 Server 上用密钥登录该用户并执行 rsync。\n\n## Server 配置\n\n`common.conf` 是应用到所有 profile 的全局配置文件。\n\n`profiles/\u003cprofiles name\u003e.conf` 是每个 profile 单独的配置文件。\n\n配置文件格式可以看看例子：一行设置一个变量，`变量名=值` 这样。不是用 Bash 解析的，所以不要在值周围添加多余的引号。路径有空格也不需要转义。\n\n配置文件中有用的变量有：\n* `SERVER`: 必需，Client 的地址或域名\n* `USER`: 必需，SSH 登录 Client 的用户名\n* `SRC`: 必需，Client 上要备份文件的路径，可以重复设置多次，以设置同步多个路径\n* `STORAGE`: 必需，建议放在全局配置中，Server 上存放备份文件的本地文件夹，必须在 btrfs 分区上，且执行该脚本的用户可以读写\n* `LOG_DIR`: 存放日志的目录（默认是 `log/\u003cprofile name\u003e` ）\n* `SSH_KEY`: SSH 登录用的私钥（默认是 `keys/${USER}@${SERVER}`），该文件必须存在\n* `KEEP_DAYS`: 短期备份的保留天数（默认为 30）\n* `KEEP_LONG_COUNT`: 最多保留多少长期备份（默认为 4）\n* `RSYNC_OPTS`: RSYNC 同步参数（默认值为 `-aHAX --timeout 3600 --delete`）\n\n备份时，执行：\n```\n./backup \u003cprofile name\u003e\n```\n\n要定期执行的话，放进 crontab 即可。\n\n### Server 对备份文件的存放\n\n该脚本会在 `${STORAGE}/\u003cprofile name\u003e/` 文件夹中存放每个 profile 的备份文件。\n\n第一次使用时，脚本会在上述文件夹下创建名为 `current` 的 btrfs subvolume。以后每次执行同步，脚本都会用 rsync 把最新的备份文件同步进这个 subvolume。\n\n每次成功执行完 rsync 后，脚本就会为 `current` 目录创建一个只读的 snapshot，名为 `L_\u003cepoch\u003e` 或 `S_\u003cepoch\u003e`，其中 `\u003cepoch\u003e` 代表备份文件时的 UNIX 时间。\n* `S_\u003cepoch\u003e` 是一个短期备份，过了 `${KEEP_DAYS}` 天就会被删除。\n* `L_\u003cepoch\u003e` 是一个长期备份，每隔 `${KEEP_DAYS}` 会创建一个。同时会保留 `${KEEP_LONG_COUNT}` 个长期备份，旧的会被删除。\n\n注意，btrfs 默认挂载参数不允许普通用户删除 subvolume。必须加上 `user_subvol_rm_allowed` 参数才行。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustclug%2Frb-backup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fustclug%2Frb-backup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustclug%2Frb-backup/lists"}