Score:0

Tar backup command for exclude backup files & cache & include only httpdocs subdirectories

ls flag

I am looking for a tar command that meets the following requirements:

I want to exclude all files ending with: backwpup & .zip (in between and before can be any e.g. uploads/123backwpup-123.zip) I want to exclude all folders in the area /media/backup/ & /application/cache/

I start at a level that looks like this:

  • example.com
  • example.de
  • example.org

With subdirectories for each:

  1. /etc/
  2. /httpdocs/
  3. /lib/
  4. ...

Only the content of /httpdocs/ needs to be saved.

I tried it with command:

tar --exclude={"*backwpup*.zip", "*/media/backup/*", "*/application/cache/*"} -czvf backup.tar.gz **/httpdocs

But unfortunately backups with path wp-content/uploads/backwpup-4578-backups/2022-10-31_12-22-31_IKXUCSLD01.zip are still included.

Score:0
fo flag

You can try using the following tar command:

tar --exclude='backwpup.zip' --exclude='/media/backup/' --exclude='/application/cache/' -czvf backup.tar.gz example.com/httpdocs example.de/httpdocs example.org/httpdocs

This command excludes all files ending with "backwpup" or ".zip", as well as folders in the specified locations. It also only includes the "httpdocs" sub-directories in each domain directory

Mike avatar
ls flag
Unfortunately there are too many domains to specify everything individually. Ideal would be a regex based rule or similar. Then there are also subdomains like sub.example.com below example.com again with a httpdocs folder. Not so easy. But not unimportant for a complete filedump of the webserver data excl. backup and caching files.
Score:0
ls flag

Perhaps this way?

find * -type d \( -path '*/media/backup/*' -o -path '*/application/cache/*' \) -prune -o -path '*/httpdocs/*' -type f ! -name '*backwpup*.zip' -print0 | tar -czvf backup.tar.gz --null -T -
Score:0
se flag

Assuming you are using GNU tar, please see the documentation on how to exclude files: https://www.gnu.org/software/tar/manual/html_node/exclude.html This details the pattern matching: https://man7.org/linux/man-pages/man7/glob.7.html

Assuming you use GNU BASH you could loop through the directories using a for loop: https://www.gnu.org/software/bash/manual/html_node/Looping-Constructs.html using filename expansion (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)

At the end of this page are good examples: https://linuxize.com/post/bash-for-loop/

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.