Database Backup with Docker Compose

I am unable to backup my databases from my self hosted instance built using Docker Compose.

I started by following the instructions here to “Backup Your Baserow DB”
https://baserow.io/docs/installation%2Finstall-with-docker-compose

I’m not sure if the instructions are out of date or if I’m just using a different version of Docker, but the command to actually execute the backup doesn’t work.

docker-compose run -v ~/baserow_backups:/baserow/backups backend backup -f /baserow/backups/baserow_backup.tar.gz

First, I’m not running that version of docker-compose, then it needs to specify the service before backend, and then backend isn’t actually a command in the --help documentation, it’s backend-cmd. After all that tweaking I eventually get to

docker compose run -v ~/baserow_backups:/baserow/backups baserow backend-cmd backup -f /baserow/backups/baserow_backup.tar.gz

But that runs me into an error that the connection to the server was refused (even though I’m doing all this on the local machine). I’ve played around with the port, using -p 3333 and -p 3334 to match my compose file, but all return identical results with the exception of which port the connection is being refused on. I’ve also triple checked that all the ports in question are open and allowed in ufw.

Not sure where I’m going wrong but any help would be appreciated.

Docker Compose file:

services:
  baserow:
    container_name: baserow
    image: baserow/baserow:1.23.2
    environment:
      BASEROW_PUBLIC_URL: 'REDACTED'
      WEB_FRONTEND_PORT: 3333
      WEB_FRONTEND_SSL_PORT: 3334
    ports:
      - "3333:80"
      - "3334:443"
    restart: unless-stopped
    volumes:
      - baserow_data:/baserow/data
volumes:
  baserow_data:

Backup command output:

[+] Building 0.0s (0/0)                                                              docker:default
[+] Building 0.0s (0/0)                                                              docker:default
 [STARTUP][2024-05-01 22:34:43] No DATABASE_HOST or DATABASE_URL provided, using embedded postgres.  
 [STARTUP][2024-05-01 22:34:43] Using embedded baserow redis as no REDIS_HOST or REDIS_URL provided.                                                                                                    
 [STARTUP][2024-05-01 22:34:43] Importing REDIS_PASSWORD secret from /baserow/data/.redispass  
 [STARTUP][2024-05-01 22:34:43] Importing SECRET_KEY secret from /baserow/data/.secret  
 [STARTUP][2024-05-01 22:34:43] Importing BASEROW_JWT_SIGNING_KEY secret from /baserow/data/.jwt_signing_key                                                                                            
 [STARTUP][2024-05-01 22:34:43] Importing DATABASE_PASSWORD secret from /baserow/data/.pgpass  
OTEL_RESOURCE_ATTRIBUTES=service.namespace=Baserow,service.version=1.23.2,deployment.environment=unknown
pg_dump --host=localhost --dbname=baserow --port=5432 --username=baserow -Fd --jobs=1 -w --exclude-table=database_multiplecollaborators_* --exclude-table=database_multipleselect_* --exclude-table=database_table_* --exclude-table=database_relation_* --file=/dev/shm/tmpkfh8yf4k/everything_but_user_tables/
pg_dump: [archiver (db)] connection to database "baserow" failed: connection to server at "localhost" (::1), port 3334 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 3334 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
CommandError: The back-up failed because of the failure of the following sub-command, please read the output of the failed command above to see what went wrong.                                        
The sub-command which failed was:                                                                   
pg_dump --host=localhost --dbname=baserow --port=3334 --username=baserow -Fd --jobs=1 -w --exclude-table=database_multiplecollaborators_* --exclude-table=database_multipleselect_* --exclude-table=database_table_* --exclude-table=database_relation_* --file=/dev/shm/tmpkfh8yf4k/everything_but_user_tables/                                                                                                
It failed with a return code of: 1               

Hi @Manny, the docker-compose run -v ~/baserow_backups:/baserow/backups backend backup -f /baserow/backups/baserow_backup.tar.gz command only works if you’re running Baserow in multi service mode as described from this section Install with Docker compose // Baserow.

Because you’re using the all-in-one image (baserow/baserow) in a docker-compose setup, the second command looks more like what you’re looking for. You would, however, need to run that command with backend-cmd-with-db to start your embedded PostgreSQL database to make the backup from.

docker compose run -v ~/baserow_backups:/baserow/backups baserow backend-cmd-with-db backup -f /baserow/backups/baserow_backup.tar.gz

That sure does it! I hadn’t spotted the backend-cmd-with-db option. Thank you for your help.