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

Enhancements to the tar.gz #38

Closed
danielmbrown603 opened this issue Dec 17, 2021 · 11 comments · Fixed by #39
Closed

Enhancements to the tar.gz #38

danielmbrown603 opened this issue Dec 17, 2021 · 11 comments · Fixed by #39
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@danielmbrown603
Copy link

danielmbrown603 commented Dec 17, 2021

One issue and one ask.

Ask - Is there a way to reference the docker server hostname in the backup file? E.g.
BACKUP_FILENAME="backup-%Y-%m-%dT%H-%M-%S.tar.gz"
BACKUP_FILENAME="{hostname}%Y-%m-%dT%H-%M-%S.tar.gz"

Issue - I have a volume mounted for /archive in my docker-composer file like this;
- mnt/backups:/archive
When I run a backup and check the folder on the docker server, the files look like this _PNSM6~H. If I look at the /archive folder from within the container, the tar.gz is named appropriately. How can I access the tar.gz files outside of the container?

Thank you

@m90
Copy link
Member

m90 commented Dec 17, 2021

About your issue: I'm not sure where that is coming from. the filenames should be the same inside and outside the container. I am using the image like this for a very long time and have never seen something similar. Could I ask you for more details about your setup (compose file, OS, etc) so it might be possible for me to reproduce this?

About your request: it would probably make sense to do this in the same way that Docker itself allows you to pass (Go) templates to commands for formatting (e.g. {{ .Host }}%Y-%m-%dT%H-%M-%S.tar.gz). Then again it's pretty odd to start mixing strftime placeholders and Docker ones. Always using "Docker format" would be the most elegant option but also a breaking change. I need to think about this a little further.

@danielmbrown603
Copy link
Author

Ubuntu 20.04.3 LTS
PERSIST= home directory for default dockerapps
Composer file - https://pastebin.com/hzxf1CV2

backup.env only has
BACKUP_FILENAME="backup-%Y-%m-%dT%H-%M-%S.tar.gz"

Thanks again!

@m90
Copy link
Member

m90 commented Dec 17, 2021

This looks ok on first glance. Would you mind also sharing the log output of a backup run?

@danielmbrown603
Copy link
Author

time="2021-12-17T14:54:15-05:00" level=info msg="Created backup of /backup at /tmp/\"backup-2021-12-17T14-53-40.tar.gz\"."
time="2021-12-17T14:54:15-05:00" level=info msg="Stored copy of backup /tmp/\"backup-2021-12-17T14-53-40.tar.gz\" in local archive /archive."
time="2021-12-17T14:54:15-05:00" level=info msg="Removed tar file /tmp/\"backup-2021-12-17T14-53-40.tar.gz\"."
time="2021-12-17T14:54:15-05:00" level=info msg="Finished running backup tasks."

@m90
Copy link
Member

m90 commented Dec 17, 2021

It's slightly surprising your filename is quoted inside the path: /tmp/\"backup-2021-12-17T14-53-40.tar.gz\"

Could it be that your Docker version is slightly outdated and you are running into this issue: docker/compose#2854 which would mean your access keys are inadvertently quoted? You can test this easily by defining it like this:

BACKUP_FILENAME=SOMETHINGSOMETHING

instead of:

BACKUP_FILENAME="SOMETHINGSOMETHING"

See: #6 (comment)

@danielmbrown603
Copy link
Author

Well nevermind. It was an issue with SMB and mangled names. I forgot to mention I was viewing the files over a share. Adding mangled names=no to my smb.conf seem to have fixed it. Maybe there is a trailing space somewhere.
http://zderadicka.eu/what-is-this-weird-file-name-in-my-samba-share/

@m90 m90 added the enhancement New feature or request label Dec 17, 2021
@danielmbrown603
Copy link
Author

Client: Docker Engine - Community Version: 20.10.12

I changed it too;
BACKUP_FILENAME=SOMETHINGSOMETHING

And the output became;

time="2021-12-17T15:08:47-05:00" level=info msg="Created backup of /backup at /tmp/backup-2021-12-17T15-08-14.tar.gz."
time="2021-12-17T15:08:48-05:00" level=info msg="Stored copy of backup /tmp/backup-2021-12-17T15-08-14.tar.gz in local archive /archive."
time="2021-12-17T15:08:48-05:00" level=info msg="Removed tar file /tmp/backup-2021-12-17T15-08-14.tar.gz."
time="2021-12-17T15:08:48-05:00" level=info msg="Finished running backup tasks."

That looks a lot better and I don't need the mangled names config either. Thanks!

@m90
Copy link
Member

m90 commented Dec 17, 2021

I guess I'll add a note about this to README considering you're not the first one to have been bitten by this. Good to know it's working for you now.

I'll circle back here once I have made up my mind about that filename template.

@m90 m90 added the documentation Improvements or additions to documentation label Dec 17, 2021
@m90
Copy link
Member

m90 commented Dec 17, 2021

Maybe a very simple solution for enabling more flexible filenames would be expanding env vars in a template just like in POSIX using https://pkg.go.dev/os#ExpandEnv

This would mean you could use

BACKUP_FILENAME="$HOST-%Y-%m-%dT%H-%M-%S.tar.gz"

in case you propagate (if you even want that) your host's $HOST into the container.

@m90
Copy link
Member

m90 commented Dec 18, 2021

The one thing I am still not sure about when implementing expansion of env vars is the following: it cannot be done by simply expanding vars as this is a breaking change (people might have filename patterns that accidentally get expanded with that addition).

To make it an opt-in change I see 3 possibilities:

  • add a flag like BACKUP_FILENAME_EXPAND=true or similar that defaults to false
  • Add a second config value for filename templates of a different name like BACKUP_FILENAME_TEMPLATE that takes precendence over BACKUP_FILENAME when set and that will use expansion
  • Deprecate BACKUP_FILENAME and come up with a new variable name that is the default and will get expanded. Users that have BACKUP_FILENAME set will see a warning message about how the setting is deprecated. Right now, I can't come up with a good name for this.

Maybe the first option would be the most straight-forward and least confusing, even if slightly ugly.

@m90 m90 added help wanted Extra attention is needed and removed documentation Improvements or additions to documentation labels Dec 18, 2021
@m90 m90 closed this as completed in #39 Dec 22, 2021
@m90
Copy link
Member

m90 commented Dec 22, 2021

This is now released in v2.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants