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

Simple script for moving to target backup by year and month #326

Open
Doctorf opened this issue Jul 15, 2024 · 6 comments
Open

Simple script for moving to target backup by year and month #326

Doctorf opened this issue Jul 15, 2024 · 6 comments

Comments

@Doctorf
Copy link

Doctorf commented Jul 15, 2024

Hi team. Here is a simple script for moving target backup to a new directory by year and month:

File /scripts.d/target.sh:

#!/bin/bash
#  Debug mode
if [[ -n "$DB_DUMP_DEBUG" ]]; then
  set -x
fi
YEAR=$(date '+%Y')
MONTH=$(date '+%m')
new_name=$(date -u +"%Y-%m-%dT%H_%M_%SZ")

# Create new directory and return new name
mkdir -p ${DB_DUMP_TARGET}/${YEAR}/${MONTH}
echo -n "${YEAR}/${MONTH}/df_api_backup_${new_name}.tar.gz"

Could you please check this script and add to repo as sample and to docker hub page?
It's a simple solution, but I can't find this example. Maybe it will be helpful.

@deitch
Copy link
Collaborator

deitch commented Jul 15, 2024

It is rather simple and elegant. I would be happy to add it. I have a few questions:

  • Have you tried it with one of the 1.0.0 release candidates, to be sure it works with those? It should, but always worth checking before publishing.
  • How do you use DB_DUMP_TARGET? You could set a target that way, but it is not necessarily set that way. Of course, we could add it, set for each target, which is a pretty good way to pass it.

@deitch
Copy link
Collaborator

deitch commented Jul 15, 2024

Also, have you looked at the Custom backup file name option?

@Doctorf
Copy link
Author

Doctorf commented Jul 15, 2024

Hi @deitch

  1. I'm using next image in docker image: databack/mysql-backup:latest and it's related to https://hub.docker.com/layers/databack/mysql-backup/latest/images/sha256-fb35135e01f1746ea46dbabb6ee2f85cc1f0b42cb3c79c8718e8d87288bf288d?context=explore
    I'm trying to use master, but I have a problem with post scripts. Now all changes moved to target.sh script and can be working on master. But I don't test it.
  2. Thanks for clarification. Yes, In my version, I need to set up only one dump target and it's local mounted directory. Script can be working with it. But it's possible to check variable or split variable for multiple targets.
  3. This env variable not described in docker hub page and I see, that variable not working in mysql-backup:latest image. I will try to use, but new directory not created, Maybe need time for recheck.

@deitch
Copy link
Collaborator

deitch commented Jul 15, 2024

but I have a problem with post scripts

Yes, I know. That fix just went through a few hours ago. Try the most recent, either pull master again or tag d6dc847c1df98a32936ff29b2007fcfa8640fb4f.

that variable not working

Yes, that probably is it. I will get a fix in the next day or so.

@deitch
Copy link
Collaborator

deitch commented Jul 16, 2024

Did you try the custom backup filename option?

@deitch
Copy link
Collaborator

deitch commented Jul 16, 2024

The more I think about it, the less I understand how to use the example.

There are two renaming options: source and target. The process is:

  1. Dump from database to some temp source file
  2. Upload temp source file contents to the target using the name "target name"

Source

Source renaming lets you change the name of the temporary file, i.e. the output from the actual dump. That file is temporary, and has no meaning beyond the current dump. The name - default or what you change it to - will be ignored. The only real value it has is if you want to append some data to the file, encrypt it, change it somehow. From mysqlbackup's perspective, it doesn't know or care. It just sees those 2 stages - dump and upload - and lets you change the value of it in the middle.

Target

Target doesn't do anything, ignores any local activity. The only thing it does is change what the remote name would be. So if it was "foo.tgz" by default and you want it to be "bar.tgz", mysqlbackup says, "ok, sure, I will call it that name when I push it in stage 2."

I am not convinced a script is necessary for it, but even if it is, how does knowing the target help? More to the point, making directories and such will not do anything.

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

2 participants