# Dump and Restore
> pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers).
>
> pg_dump only dumps a single database. To back up an entire cluster, or to back up global objects that are common to all databases in a cluster (such as roles and tablespaces), use pg_dumpall.
>
> Dumps can be output in script or archive file formats. Script dumps are plain-text files containing the SQL commands required to reconstruct the database to the state it was in at the time it was saved. To restore from such a script, feed it to psql. Script files can be used to reconstruct the database even on other machines and other architectures; with some modifications, even on other SQL database products.
>
> The alternative archive file formats must be used with pg_restore to rebuild the database. They allow pg_restore to be selective about what is restored, or even to reorder the items prior to being restored. The archive file formats are designed to be portable across architectures.
>
> When used with one of the archive file formats and combined with pg_restore, pg_dump provides a flexible archival and transfer mechanism. pg_dump can be used to backup an entire database, then pg_restore can be used to examine the archive and/or select which parts of the database are to be restored. The most flexible output file formats are the “custom” format (-Fc) and the “directory” format (-Fd). They allow for selection and reordering of all archived items, support parallel restoration, and are compressed by default. The “directory” format is the only format that supports parallel dumps.
>
> While running pg_dump, one should examine the output for any warnings (printed on standard error), especially in light of the limitations listed below**~~
## Dump Examples
### Without public schemas
```bash=
pg_dump -h [host] -d [db_name] --username [db_user] exclude-schema public > [db_name].backup
```
### Public schema only
```bash=
pg_dump --host [host] --username [db_user] --format custom --schema public [db_name] > [db_name].backup
```
### All schemas
```bsh=
pg_dump -h [host] -d [db_name] --username [db_user] > [db_name].backup
```
## Restore Examples
### Using pg_restore
```bash=
pg_restore --no-owner -d [db_name] -v -h [host] -U [db_user] [db_name].backup
```
### Using psql
```bash=
psql -h [host] -d [db_name] --username [db_user] < [db_name].backup
```
#### Create By Romenson_felix (rfelix)
# Flags
DOCKER
-h = host
-d = rodando em background
-v = mapeando volumes
--name = declarando nome do container
-p = mapeando portas
-e = declaração de variáveis
-it = interação com o terminal do container
-U = declaração de usuário