databacker / mysql-backup

image to enable automated backups of mysql databases in containers
636 stars 178 forks source link

New schemas not backed up #214

Open bansalvinay opened 1 year ago

bansalvinay commented 1 year ago

I'm using Ubuntu Mysql image. The backup runs fine for the databases which are created before this container is started. It runs for these databases continuously on cron as expected. But when there are new databases created, these are not backed up until this container is restarted.

Here's my composer code for mysql-backup :

db-backup:
    image: databack/mysql-backup:latest
    restart: 'always'
    container_name: 'smartsites-db-backup'
    depends_on: 
      - database
    volumes:
      - ${DB_BACKUP_DIR}:/db
      - ${DB_BACKUP_TEMP_DIR}:/tmp
    user: root
    environment:
      DB_SERVER: database
      DB_PORT: 3306
      DB_USER: root
      COMPRESSION: gzip
      DB_DUMP_BY_SCHEMA: "true"
      DB_PASS: ${MYSQL_ROOT_PASSWORD}
      DB_DUMP_CRON: "* * * * *"
      DB_DUMP_DEBUG: "true"
      DB_DUMP_TARGET: /db
deitch commented 1 year ago

I recommend running it with DB_DUMP_DEBUG=true and then putting output here (please scrub sensitive data first). However, I strongly suspect it is because DB_NAMES is a global var and is set here, and so it is preset the next loop. It should be a simple fix. Care to open a PR for it?

pcrt commented 1 year ago

That's right, the problem is relative to the global var DB_NAMES which is not reset if already set previously. This also causes an error in the execution if the DB_DUMP_BY_SCHEMA flag is set and one or more databases are deleted after the first run of the script, because it continue to backup a schema that previously removed .

I think the simple way to do that fix is to remove the control between these line here, in that way the script reload the list every time is running .

Maybe one day i can make highlight line selection more precise when github decide to implement this feature 😆

If you want, I can do the PR.

deitch commented 1 year ago

I think the simple way to do that fix is to remove the control between these line here, in that way the script reload the list every time is running

Well, almost. If the user explicitly passed DB_NAMES, then it restricts it to those, so it will require a little reworking to capture command-line-passed and only check each time if that was not passed.

I would appreciate the PR, indeed.