Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive exclude_path can't exclude directories below 2nd level #6857

Closed
1 task done
elburro1887 opened this issue Jul 5, 2023 · 5 comments
Closed
1 task done

archive exclude_path can't exclude directories below 2nd level #6857

elburro1887 opened this issue Jul 5, 2023 · 5 comments
Labels
bug This issue/PR relates to a bug module module

Comments

@elburro1887
Copy link

elburro1887 commented Jul 5, 2023

Summary

When running archive, it is not possible to exclude a directory or files that are below the 2nd level of hierarchy

Backup path

  • /home/user/foldertobackup/*

I want to exclude the folder (and its contents):

  • /home/user/foldertobackup/subdir3/subsubdir4

Issue Type

Bug Report

Component Name

plugins/modules/archive.py

Ansible Version

$ ansible --version
ansible [core 2.15.1]
  config file = /Users/zzz/coding/prs/servertools/backup_ansible/ansible.cfg
  configured module search path = ['/Users/zzz/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/zzz/.pyenv/versions/3.9.16/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/zzz/.pyenv/versions/3.9.16/bin/ansible
  python version = 3.9.16 (main, Jul  4 2023, 14:48:26) [Clang 12.0.0 (clang-1200.0.32.29)] (/Users/zzz/.pyenv/versions/3.9.16/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 7.1.0

Configuration

$ ansible-config dump --only-changed

OS / Environment

Mac OS and Debian Bullseye tested

Steps to Reproduce

 - name: Create backup of files/directories - TEST
      community.general.archive:
        path: 
          - "/home/user/foldertobackup/*"
          - "/home/user/foldertobackup/subdir3/*"
        dest: "/home/user/backup/myarchive.gz"
        format: gz
        mode: 0644
        exclude_path: 
          - "/home/user/foldertobackup/log"
          - "/home/user/foldertobackup/sql"
          - "/home/user/foldertobackup/subdir3/subsubdir4"

Expected Results

The archive should not contain the folder or any files in it:

  • /home/user/foldertobackup/subdir3/subsubdir4

Actual Results

Archive contains the folder (among others)

  • /home/user/foldertobackup/subdir3/subsubdir4

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:
None

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot ansibullbot added the bug This issue/PR relates to a bug label Jul 5, 2023
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

cc @bendoh
click here for bot help

@paradox-lab
Copy link

how about this?

 - name: Create backup of files/directories - TEST
      community.general.archive:
        path: 
          - "/home/user/foldertobackup/*"
          - "/home/user/foldertobackup/subdir3/*"
        dest: "/home/user/backup/myarchive.gz"
        format: gz
        mode: 0644
        exclude_path: 
          - "/home/user/foldertobackup/log"
          - "/home/user/foldertobackup/sql"
          # ​avoid walking the whole path again and reinclude the mentioned subdirectory and its contents
          - "/home/user/foldertobackup/subdir3"
          - "/home/user/foldertobackup/subdir3/subsubdir4"

@elburro1887
Copy link
Author

elburro1887 commented Jul 6, 2023

Yes like that it actually works, thanks!

I think I have finally wrapped my head around it -> adding the /subdir3 again to exclude_path removes only that exclude_path line from the expanded_paths, but keeps the files that are in /subdir3 folder in expanded_paths, so we include the files, but don't walk the whole directory again when archiving (thereby not including /subdir3/subsubdir4).

BUT to be honest, this is not really the most intuitive way of specifying exclusion paths IMHO!

Here is the output of my test in case anyone is interested:

"archived": [
  "/home/user/foldertobackup/subdir3/tes321132.txt",
  "/home/user/foldertobackup/subdir3/test564.txt",
  "/home/user/foldertobackup/subdir3/test8966.txt",
  "/home/user/foldertobackup/test1.txt",
  "/home/user/foldertobackup/test2.txt"
],
"expanded_exclude_paths": [
  "/home/user/foldertobackup/log",
  "/home/user/foldertobackup/sql",
  "/home/user/foldertobackup/subdir3",
  "/home/user/foldertobackup/subdir3/subsubdir4"
],
"expanded_paths": [
  "/home/user/foldertobackup/subdir3",
  "/home/user/foldertobackup/test2.txt",
  "/home/user/foldertobackup/sql",
  "/home/user/foldertobackup/test1.txt",
  "/home/user/foldertobackup/log",
  "/home/user/foldertobackup/subdir3/test564.txt",
  "/home/user/foldertobackup/subdir3/tes321132.txt",
  "/home/user/foldertobackup/subdir3/test8966.txt",
  "/home/user/foldertobackup/subdir3/subsubdir4"
]

EDIT: see #593 (comment) for a working example using exclusion_patterns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module
Projects
None yet
Development

No branches or pull requests

3 participants