首页 > 解决方案 > Ansible `archive` 模块无需压缩即可存档

问题描述

我必须归档一堆文件,并希望避免压缩以节省时间。这是归档 1 TB 数据并将其写入不同驱动器的日常操作,因此“时间至关重要”。查看Ansible 归档模块文档,不清楚如何在不压缩的情况下构建目标文件。目前,我的 Ansible 任务如下所示:

- name: Create snapshot tarball
  become: true
  archive:
    path: "{{ snapshots_path.stdout_lines }}"
    dest: "{{backup_location}}{{short_date.stdout}}_snapshot.tgz"
    owner: "{{backup_user}}"
    group: "{{backup_group}}"

是否可以通过告诉模块不要压缩来加快这个过程?如果是,如何?

标签: ansible

解决方案


另一方面,基于superuser上的其他答案,tar默认情况下不压缩文件gz这是默认formatarchive

所以你可以尝试通过:

- name: Create snapshot tarball
  become: true
  archive:
    path: "{{ snapshots_path.stdout_lines }}"
    dest: "{{backup_location}}{{short_date.stdout}}_snapshot.tar"
    format: tar
    owner: "{{backup_user}}"
    group: "{{backup_group}}"

这也得到了以下手册页的支持tar

DESCRIPTION         
      GNU tar is an archiving program designed to store multiple files in a
      single file (an archive), and to manipulate such archives.  The
      archive can be either a regular file or a device (e.g. a tape drive,
      hence the name of the program, which stands for tape archiver), which
      can be located either on the local or on a remote machine.

推荐阅读