首页
/ Tarsnapper 使用与技术文档

Tarsnapper 使用与技术文档

2024-12-17 02:13:54作者:卓炯娓

本文档将详细介绍如何安装、使用以及API调用Tarsnapper项目,帮助用户更好地理解和操作该备份工具。

1. 安装指南

Tarsnapper可以通过pip进行安装:

pip install tarsnapper

确保在安装之前系统已经正确安装了tarsnap,并且tarsnap的配置文件(tarsnap.conf)已经设置好,包括密钥文件路径等。

2. 项目的使用说明

2.1 不使用配置文件的单次备份

可以通过以下命令进行单次备份:

tarsnapper --target "foobar-\$date" --sources /etc/  --deltas 6h 7d 31d - make

这里需要注意以下几点:

  • 需要为过期操作提供$date占位符,并在shell中转义美元符号。
  • 列表中的时间增量(deltas)应以-字符结束。
  • tarsnap需要正确设置,以便能够通过tarsnap.conf找到密钥文件等。

2.2 使用配置文件

Tarsnapper也支持使用配置文件,这允许定义多个备份任务,并具有更多特性,如任务前后的命令。配置文件看起来是这样的:

# 全局设置,对所有任务有效,除非被覆盖:
deltas: 1d 7d 30d
delta-names:
  super-important: 1h 1d 30d 90d 360d
target: /localmachine/$name-$date
include-jobs: /usr/local/etc/tarsnapper/*.yml

jobs:
  images:
    source: /var/lib/mysql
    exclude: /var/lib/mysql/temp
    exec_before: service mysql stop
    exec_after: service mysql start
    alias: img

  some-other-job:
    sources:
      - /var/dir/1
      - /etc/google
    excludes:
      - /etc/google/cache
    target: /custom-target-$date.zip
    deltas: 1h 6h 1d 7d 24d 180d

使用配置文件创建备份:

tarsnapper -c myconfigfile make

或者进行过期操作:

tarsnapper -c myconfigfile expire

如果要传递参数给tarsnap,可以使用以下方式:

tarsnapper -o configfile tarsnap.conf -o v -c tarsnapper.conf make

使用include-jobs选项,可以在其他文件中插入一个或多个任务,例如:

yet-another-job:
  source: /var/dir/2
  deltas: 1h 1d 30d

an-important-job:
  source: /var/something-important
  delta: super-important

3. 项目API使用文档

目前Tarsnapper项目没有公开的API文档。用户主要通过命令行接口与项目交互。

4. 项目安装方式

Tarsnapper的安装方式如上述安装指南中所述,通过pip命令进行安装。确保在执行安装前,系统已经安装了tarsnap并且配置正确。


以上是Tarsnapper项目的使用与技术文档,希望能帮助用户更好地理解和使用该工具。

登录后查看全文