0

I need to compile a list of directories for later backup with Restic. I need exactly two directories inside each subdomain to be included in that list. Everything else should not be backed up.

The directory structure is as follows:

subdomain1.domain.tld
|- other_directory1
|- public_html
   |- backup1
   |- backup2
   |- no_backup1
   |- no_backup2
   |- no_backup3
subdomain2.domain.tld
|- other_directory1
|- public_html
   |- backup1
   |- backup2
   |- no_backup1
   |- no_backup2
   |- no_backup3
subdomain3.domain.tld
|- other_directory1
|- public_html
   |- backup1
   |- backup2
   |- no_backup1
   |- no_backup2
   |- no_backup3

At the end I would like my list to look like this:

/path/to/my/subdomains/subdomain1.domain.tld/public_html/backup1
/path/to/my/subdomains/subdomain1.domain.tld/public_html/backup2
/path/to/my/subdomains/subdomain2.domain.tld/public_html/backup1
/path/to/my/subdomains/subdomain2.domain.tld/public_html/backup2
/path/to/my/subdomains/subdomain3.domain.tld/public_html/backup1
/path/to/my/subdomains/subdomain3.domain.tld/public_html/backup2

So far I have this:

find /path/to/my/subdomains -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | sort | xargs readlink -f > list.txt

which gives me a list of all my subdomains, but not public_html/backup1 and public_html/backup1 of each directory. Any advice how to proceed from here? Thanks!

2 Answers 2

2

Look for directories whose name starts with backup, and print their full path:

find /path/to/my/subdomains -type d -name 'backup*'

If you want to explicitly list the full names of all directories to back up:

find /path/to/my/subdomains -type d \( -name backup1 -o -name backup2 \)
0
1

If you want to be more explicit as to where to find those directories, in the zsh shell, you can do:

print -rC1 /path/to/my/subdomains/*/public_html/(backup1|backup2)(N/)

to print them or:

dirs=(
  /path/to/my/subdomains/*/public_html/(backup1|backup2)(N/)
)

to store them in an array to use as (( $#dirs )) && my-backup-cmd $dirs for instance.

But if the point is to print a backup1 and backup2 for each public_html directory, regardless of whether they exist or not, you can do:

print -rC1 /path/to/my/subdomains/*/public_html(N-/e[
  'reply=($REPLY/{backup1,backup2})'])

That is using the evaluation glob qualifier to return those two paths for each public_html directory.

Or:

() {
  print -rC1 $^argv/{backup1,backup2}
} /path/to/my/subdomains/*/public_html(N-/)

This time using an anoymous function that takes those public_html dirs as arguments and appends both /backup1 and /backup2 to them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .