docker-backup-database icon indicating copy to clipboard operation
docker-backup-database copied to clipboard

MySQL backup archive is missing (no such file or directory)

Open lermontex opened this issue 10 months ago • 6 comments

Hi!

I have a Docker Compose config that looks something like this:

services:
  mysql:
    image: mysql:8
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE:-app}
      MYSQL_RANDOM_ROOT_PASSWORD: true
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password}
      MYSQL_USER: ${MYSQL_USER:-app}
    volumes:
      - mysql_data:/var/lib/mysql
    hostname: mysql.local

  mysql_backup:
    image: appleboy/docker-backup-database:mysql8
    environment:
      STORAGE_DRIVER: disk
      STORAGE_BUCKET: mysql
      TIME_SCHEDULE: * * * * *
      DATABASE_DRIVER: mysql
      DATABASE_HOST: mysql.local
      DATABASE_USERNAME: ${MYSQL_USER:-app}
      DATABASE_PASSWORD: ${MYSQL_PASSWORD:-password}
      DATABASE_NAME: ${MYSQL_DATABASE:-app}
      DATABASE_OPTS: "--no-tablespaces"
    volumes:
      - mysql_data_backup:/backup/mysql

volumes:
  mysql_data:
  mysql_data_backup:

When trying to perform a backup, an error occurs:

mysql_backup-1  | 2025/01/29 18:20:00 INFO start backup database now schedule="* * * * *"
mysql_backup-1  | ׆xaLH󠮋¿䗛ª	ʺ[ 
                                          ¥^r[AuH]𐆮󤵵¤BewH]ވ¹¡ч45¤؊4ڴ
                                                                    L烬
                                                                       s疃¿󀶚⸿­ť@󡢠mysqldump --version
mysql_backup-1  | mysqldump  Ver 8.4.4 for Linux on x86_64 (MySQL Community Server - GPL)
mysql_backup-1  | $ mysqldump -h mysql.local -P 3306 -u app app
mysql_backup-1  | $ gzip
mysql_backup-1  |ܚmsنþ\~Ƶq
mysql_backup-1  | qŵų& )϶𝓙¹Zo
                                  ±ÿ}O�1-cψԮߞ߳쟄`þ¼󻮝󿿳𣷮ـ댱ĸ�H
W¯ÿ׫a!,Wº,Hǫl(4QEE¦W²,Lċτİjኻଣ~s<ǃ¥ ;E©Ȣ2U¤Cp*¬ߞܕ
                             񢬬AសqqʼU 

                                    𩣔jv]΅;㹋e8~ڛʢ甀ծL?e¾{«ṙ~¾䗊P!ɕDΕY¸ϴr²󿿳Yª󿾿'񍇶«°P
mysql_prod_backup-1  | 川[²¢
¯C¹ݬ¡|뤭$󛑾nz<´úҼ¨[~Ɛp| ̄Xt[c'X«hc`@)hÿ~4¶֐
W5¨颰}𗃏qO鸆򽸩!̧/"򤰎{怐ߋ«¢eٳ·`&¼Px4·芓촯¼&b¥}(l֢񤾢=f®ꅸřF¿¢*¤󾶰hٙ¸¾ѥц´ ³+¹0okB½½HMί+Ǣ׾aa·£￷EћF|?Sȃ蜍溄
ں8°Fh؉½<X7/򩸄Ğ闵                                                                               닣b/砫1¾񟟽CꖨSz8¡F'k¶ea-ڻ{¼
               gǂԢAᙝ饾©Lc岰4>䄃ƍ󿶄^|ӏw峩_"
                                         C{´g$[ҞϹ 
                                                 󕚠fFؗĞ񄖲ٷ"±Lۑշ}d$°[Ŗ¶t
mysql_backup-1  | º܌6܅DﳼSǙ
                               Y6R¶.¥lɓ_`}&񼵨I
mysql_backup-1  |  
                       ¶ⷣ񴸽اh®<©¦(ܽª"ࠇ¦⺡a´+㝬¯UrZdb%z¡-¥}¸eeY󜰃©뱑Œ𒗰᠞<#k¨؂̤󒌣
mysql_backup-1  | R/̀'9[0ԮH¨ܭ{¬¬¬3·.ߢ`	̼*eUa%£򴌐樔"¿愣<9{6ᐽQYO㈍󤘸 
mysql_backup-1  | GI&m³²£塏
                                s®}󷓯ZᄹX쓌Il
mysql_backup-1  | 2025/01/29 18:20:00 ERROR can't backup database err="can't open the gzip file: open dump.sql.gz: no such file or directory"

Image

It seems the error is related to the file being displayed on the screen instead of being saved to disk?

Note: Rolling back to 1.0.1 version solves this issue

lermontex avatar Feb 03 '25 00:02 lermontex

I have the same error.

2025-02-11 16:30:00 2025/02/11 09:30:00 ERROR can't backup database err="can't open the gzip file: open dump.sql.gz: no such file or directory"

anhntcv avatar Feb 11 '25 09:02 anhntcv

I will take it.

appleboy avatar Mar 04 '25 03:03 appleboy

I have encountered similar problem and here is there problem

  1. The gzip output is sent to os.stdout rather than a file here https://github.com/appleboy/docker-backup-database/blob/a6ae8491202a3bbbe8affb267f39bc8ca2ed29c3/pkg/dbdump/mysql/mysql.go#L77

  2. If above was fixed, the gzip will mostly be empty since the mysqldump output is sent to os.stdout https://github.com/appleboy/docker-backup-database/blob/a6ae8491202a3bbbe8affb267f39bc8ca2ed29c3/pkg/dbdump/mysql/mysql.go#L39

0xMurage avatar Sep 05 '25 21:09 0xMurage

Unfortunately, this is also a problem with PostgreSQL, just like with the MySQL dump code.

The problem can be fixed by either:

  1. Manually creating the dump file and redirecting the dump command to the file pointer.

  2. Using the native dump flags, such as -Fc -f${d.DumpName} for PostgreSQL and --compress --result-file=${d.DumpName} for MySQL.

I'm happy to contribute a fix, depending on which of the above methods is preferred.

0xMurage avatar Sep 05 '25 21:09 0xMurage

I think https://github.com/appleboy/docker-backup-database/pull/21 would fix this

trim21 avatar Oct 05 '25 17:10 trim21

I have a working fork https://github.com/trim21/docker-backup-database/tree/master if you need it now, I'm trying to submit these changes to here.

trim21 avatar Oct 05 '25 18:10 trim21