tschifftner.duplicity

Ansible 角色:安装和配置 duplicity

构建状态

该角色从源代码安装 duplicity,并在 Debian/Ubuntu Linux 服务器上处理备份任务。

需求

ansible 2.0+

依赖

无。

安装

$ ansible-galaxy install tschifftner.duplicity

示例剧本

可用的变量如下所列,以及默认值(见 defaults/main.yml):

    - hosts: webservers
      vars:
        # duplicity
        duplicity_known_hosts:
          - host: 'example.org'
            key: 'example.org ssh-rsa AAAAB3NzaC...+PwAK+MPw=='
            state: present
    
        duplicity_config_vars:
          FTP_SERVER: 'sftp://[email protected]/my/folder/'
          FTP_PASSWORD: '*******'
          DEFAULT_PARAMS: '--verbosity info --exclude-device-files --exclude-other-filesystems --exclude-if-present .duplicity-ignore'
    
        duplicity_cronjobs:
          - name: '清理超过 2 个月的备份'
            user: root
            group: root
            source: /etc/duplicity/duplicity.conf
            hour: 4
            minute: 10
            command: >
              duplicity remove-older-than 2M --force --extra-clean $FTP_SERVER;
              duplicity cleanup --force $FTP_SERVER
    
          - name: '备份 /var/www'
            user: root
            group: root
            hour: 5
            minute: 21
            source: /etc/duplicity/duplicity.conf
            command: duplicity $DEFAULT_PARAMS --include /var/www --full-if-older-than 1M --exclude '**' / $FTP_SERVER

      roles:
             - { role: tschifftner.duplicity }

建议将所有变量放在外部文件中。

    - hosts: webservers
      vars_files:
        - duplicity-settings.yml
    
      roles:
         - { role: tschifftner.duplicity }

小贴士

  • 使用 ssh-keyscan -t rsa example.org 获取服务器的 ssh 密钥(用于 duplicity_known_hosts 变量中)
  • 可以将 cron 作业写成多行,但这会导致重复执行失败!例如:
 command: >
   duplicity remove-older-than 2M --force --extra-clean $FTP_SERVER;
   duplicity cleanup --force $FTP_SERVER

这将始终导致状态改变!

Duplicity 变量

duplicity_config_vars:
  SERVER: 'ftp://[email protected]/backups/'
  PASSPHRASE: 'YourSecretPassphrase'
  FTP_PASSWORD: '*******'
  PARAMS: '--verbosity info --exclude-device-files --exclude-other-filesystems --exclude-if-present .duplicity-ignore --exclude-filelist /etc/duplicity/exclude.list'
  INCLUDES: '/root /home /var/www /var/backup'

GPG 加密

此角色不支持 GPG 加密。您需要手动安装它。

生成 GPG 密钥对

要生成 GPG 密钥,请使用以下代码:

gpg --batch --gen-key <<EOF
%echo 生成 GPG 密钥
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Subkey-Length: 4096
Name-Real: Duplicity Backup
Name-Comment: 用于备份加密
Name-Email: duplicity@localhost
Expire-Date: 0
Passphrase: 这应该是您个人独特的密码
%commit
%echo 完成
EOF

导出公钥

gpg --output FB37DF3B.public.asc --armor --export FB37DF3B

导出所有者信任

gpg --export-ownertrust > ownertrust.txt

导出私钥

gpg --output FB37DF3B.private.asc --armor --export-secret-key FB37DF3B

已知主机

要将主机标记为已知主机

duplicity_known_hosts:
  - host: 'ftp.example.com'
    key: 'ftp.example.com ssh-rsa AAAAB3NzaC1yc2[...]+MPw=='
    state: 'present'

如果您确定您的系统支持,可以使用 ecdsa 和 ed25519 密钥。

ssh-keyscan -t ecdsa ftp.example.com
ssh-keyscan -t ed25519 ftp.example.com

Duptools

Duptools 是一个帮助管理备份的脚本。默认安装,但可以通过 duplicity_install_duptools: false 禁用。

运行 duptools

只需在命令行中输入 duptools 以获取可用选项:

    duptools - 管理 duplicity 备份

    用法:

    duptools backup
    duptools list
    duptools status
    duptools restore file [time] dest
    duptools remove [time]

    [time]
    a) now
    b) 2002-01-25T07:00:00+02:00
    c) D=天, W=周, M=月, Y=年, h=小时, m=分钟, s=秒

支持的操作系统

  • Debian 9 (Stretch)
  • Debian 8 (Jessie)
  • Ubuntu 18.04 (Bionic Beaver)
  • Ubuntu 16.04 (Xenial Xerus)

所需 ansible 版本

Ansible 2.5+

许可证

MIT 许可证

作者信息

TODO

  • 修复重新安装和安装其他版本的问题,现在没有覆盖文件 /usr/local/bin/duplicity,也没有删除 pip 卸载 duplicity。
关于项目

Installs duplicity from source and handles backup tasks on Debian/Ubuntu linux servers.

安装
ansible-galaxy install tschifftner.duplicity
许可证
mit
下载
90
拥有者
Kubernetes Software Architekt, Magento Certified Developer und Full-Stack Entwickler