docker run --rm -v /home/app/_backups/{backup_id}:/backup postgres:15 sh -c "pg_dump --no-privileges --no-owner --no-acl <postgres_url> | gzip > /backup/<export_filename>"
Here's what each part of the command does:
docker run
: This starts a new Docker container.
--rm
: This tells Docker to remove the container automatically after it exits.
-v /home/app/_backups/{backup_id}:/backup
: This mounts a directory on the host machine (/home/app/_backups/{backup_id}
) as a volume inside the container (/backup
). The backup_id
is a variable that should be replaced with a specific ID value that corresponds to the backup directory.
postgres:15
: This specifies the Docker image to use for the container. In this case, it's the official PostgreSQL 15 image.
sh -c
: This starts a shell in the container and executes the command that follows.
"pg_dump --no-privileges --no-owner --no-acl <postgres_url> | gzip > /backup/<export_filename>"
: This is the command that's executed inside the container. It runs the pg_dump
command with the specified options and pipes the output to the gzip
command, which compresses it. The compressed output is then saved to a file in the /backup
directory inside the container. <postgres_url>
and <export_filename>
are variables that should be replaced with the actual URL of the PostgreSQL server and the desired filename for the export file, respectively.
how to restore postgres database from backup file
In order to restore a postgres database from a file you need to download the backup file, uncompress it and import to the database.
For example we have a file called 23-database-starttest1-2023-04-18_21-51-01.gz
. Then to uncomress it we use this command:
gunzip 23-database-starttest1-2023-04-18_21-51-01.gz
We will see 23-database-starttest1-2023-04-18_21-51-01
file.
Use psql command to load it to the database:
psql <new_postgresql_url> < 23-database-starttest1-2023-04-18_21-51-01
Try our application deployment tool that allows you to set up servers automatically, deploy
from git, manage Postgres backups and cron tasks.
Use a server from any cloud provider
Setup is done automatically
Deploy Django, Flask, FastAPI, Node apps
Unlimited number of databases
Custom domains and HTTPS
Focus on apps, we take care of deployments
As developers ourselves, we hated wasting time writing configuration files for web servers,
pipelines and managing apps via SSH – so we built the system that we always wanted.
Appliku takes care of everything you need to deploy, run and manage your apps, while you can
still
do customized configuration if you choose to.
Try it with a free plan and see for yourself.
Start Free
Simple 5-minute setup – No credit card required