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

How to tar exclude relative to source directory? #338

Open
atrandafir opened this issue Apr 25, 2023 · 1 comment
Open

How to tar exclude relative to source directory? #338

atrandafir opened this issue Apr 25, 2023 · 1 comment

Comments

@atrandafir
Copy link

atrandafir commented Apr 25, 2023

First of all thanks for creating this awesome tool for handling backups! :-)

Now back to the issue:

I am trying to make a tar backup and specify the paths to exclude.

The problem is I do not know how to make it exclude those paths just from the root of the source directory, not if a directory with same name is found in a subdirectory of the source.

I have tried:

<source type="tar">
	  <option name="path" value="../crm"/>
	  <option name="exclude" value="assets,img,uploads/propertyExporter,uploads/resize,uploads/properties,protected/runtime,protected/private/mails,protected/private/attachments,protected/private/uploads"/>
  </source>

Produces:

"/bin/tar" --exclude='assets' --exclude='img' --exclude='uploads/propertyExporter' --exclude='uploads/resize' --exclude='uploads/properties' --exclude='protected/runtime' --exclude='protected/private/mails' --exclude='protected/private/attachments' --exclude='protected/private/uploads' -cf '/var/www/vhosts/example.com/phpbu/../backup/files/crm-20230425-0843.tar' -C '/var/www/vhosts/example.com/phpbu/..' 'crm'

But if I untar the file and check with "git status", I can see the backup also excluded paths like these, that should not have been excluded:

#       deleted:    themes/oicrm/views/layouts/zechat/plugins/smiley/assets/png/2b1c.png
#       deleted:    themes/oicrm/views/layouts/zechat/plugins/uploader/jquery.plupload.queue/img/backgroun

Also tried:

<source type="tar">
	  <option name="path" value="/var/www/vhosts/example.com/crm"/>
	  <option name="exclude" value="/var/www/vhosts/example.com/crm/assets,/var/www/vhosts/example.com/crm/img,/var/www/vhosts/example.com/crm/uploads/propertyExporter,/var/www/vhosts/example.com/crm/uploads/resize,/var/www/vhosts/example.com/crm/uploads/properties,/var/www/vhosts/example.com/crm/protected/runtime,/var/www/vhosts/example.com/crm/protected/private/mails,/var/www/vhosts/example.com/crm/protected/private/attachments,/var/www/vhosts/example.com/crm/protected/private/uploads"/>
  </source>

Produces:

"/bin/tar" --exclude='/var/www/vhosts/example.com/crm/assets' --exclude='/var/www/vhosts/example.com/crm/img' --exclude='/var/www/vhosts/example.com/crm/uploads/propertyExporter' --exclude='/var/www/vhosts/example.com/crm/uploads/resize' --exclude='/var/www/vhosts/example.com/crm/uploads/properties' --exclude='/var/www/vhosts/example.com/crm/protected/runtime' --exclude='/var/www/vhosts/example.com/crm/protected/private/mails' --exclude='/var/www/vhosts/example.com/crm/protected/private/attachments' --exclude='/var/www/vhosts/example.com/crm/protected/private/uploads' -cf '/var/www/vhosts/example.com/phpbu/../backup/files/crm-20230425-0840.tar' -C '/var/www/vhosts/example.com' 'crm'

And doesn't exclude a thing.

I think I also tried with adding dot and shash, example: ./assets and it still did not work.

Before using phpbu I had this bash script:

#!/bin/bash

DATE=`date +%Y%m%d`

TODAYDIR=/var/backup/files/daily/$DATE
mkdir $TODAYDIR

tar \
  --exclude='/var/www/vhosts/example.com/crm/assets' \
  --exclude='/var/www/vhosts/example.com/crm/img' \
  --exclude='/var/www/vhosts/example.com/crm/uploads/propertyExporter' \
  --exclude='/var/www/vhosts/example.com/crm/uploads/resize' \
  --exclude='/var/www/vhosts/example.com/crm/uploads/properties' \
  --exclude='/var/www/vhosts/example.com/crm/protected/runtime' \
  --exclude='/var/www/vhosts/example.com/crm/protected/private/mails' \
  --exclude='/var/www/vhosts/example.com/crm/protected/private/attachments'                                                                      \
  --exclude='/var/www/vhosts/example.com/crm/protected/private/uploads' \
  -cvf "$TODAYDIR/crm.tar" /var/www/vhosts/example.com/crm/
@atrandafir
Copy link
Author

atrandafir commented Apr 25, 2023

Update: I have found a workaround..

<source type="tar">
  <option name="path" value="../crm"/>
  <option name="exclude" value="crm/assets,crm/img,crm/uploads/propertyExporter,crm/uploads/resize,crm/uploads/properties,crm/protected/runtime,crm/protected/private/mails,crm/protected/private/attachments,crm/protected/private/uploads"/>
</source>

With the syntax above it looks like, at least in this case, we can get the expected result.

After checking the tar command phpbu generates, we can see that it uses the -C argument to move to a specific working directory, and from there, it specifies the directory crm to be included in the backup:

-C '/var/www/vhosts/oibarcelona.com/phpbu/..' 'crm'

That means that the working directory is, one directory above of the specified source directory. So you can specify <source_dir>/exclude_path, as in this case crm/assets.

It is not the perfect solution but it works, while I won't have any subdirectory named crm/assets that I want to include in the backup that could get excluded by mistake.

Also if anyone needs to test, you can use these arguments when running the command:

--debug --verbose --simulate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant