Skip to content

Commit fc38fe5

Browse files
doc: Update README.md with instructions on how to use this tool
1 parent 39cadd8 commit fc38fe5

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Dbdump
2+
3+
This tool is a wrapper for PostgreSQL's native `pg_dump` and `pg_restore` commands (in the future, others DB engines will
4+
be added) and basically add the option to upload a DB dump to an S3 bucket.
5+
6+
The **main goal** of this tool, is to allow Developers or whoever need it, to be able to generate a DB dump in a remote
7+
system, which does have a working connection to the Internet network, but, users are denied to download/upload files from it
8+
to their local machines directly.
9+
10+
The secondary goal is to have a standard dump format (a custom compressed archive) for everyone. You can not change
11+
(add/remove) parameters.
12+
13+
We use `pg_dump` command here to perform the dump. Followin is a list and meaning of the parameters used:
14+
- `-h` -> database server host or socket directory
15+
- `-p` -> database server port number
16+
- `-U` -> connect as specified database user
17+
- `-d` -> database to dump
18+
- `-O` -> prevents `ALTER OWNER` commands in the dump file.
19+
- `-f` -> output file or directory name
20+
- `-F c` -> output file format (custom, directory, tar, plain text(default)). We are using the custom format here.
21+
- `-c` -> clean(drop) database objects before recreating
22+
23+
The third goal, is to execute the dump once and have it at disposal for others in AWS S3.
24+
25+
## Download the tool and install on your local machine or the remote server
26+
27+
Go on the release page of the repository: https://github.com/ManyDesigns/dbdump/releases and select the correct architecture
28+
for your Operating System.
29+
30+
Download it, decompress and save it in your Path.
31+
32+
## How to use this cli
33+
34+
### DUMP
35+
36+
To create a new dump you have to execute the following:
37+
38+
1. Create a new environment variable `export AWS_BUCKET=<name-of-the-bucket>` where the dumps will be uploaded.
39+
2. The default AWS Region, if not specified is set to `eu-south-1`. So if the bucket has been created in another AWS
40+
region, you have to create a new env variable: `export AWS_REGION=<your-region>`
41+
3. Launch the command:
42+
43+
```bash
44+
dbdump dump -W <your db password> \
45+
-U <your db user> \
46+
-h <your DB server hostname/IP>
47+
-p <your DB server port>
48+
-d <the db name you want to dump>
49+
```
50+
For more options have a look at the help menu `dbdump dump --help`:
51+
52+
```bash
53+
dbdump dump --help
54+
Usage of dump:
55+
-U string
56+
PostgreSQL user (default "postgres")
57+
-W string
58+
PostgreSQL password
59+
-a Back up all non-template databases
60+
-d value
61+
Specify a database to back up (can be used multiple times)
62+
-e string
63+
Specify the target environment (e.g. prod|staging)getenv) (default "staging")
64+
-h string
65+
PostgreSQL host (default "127.0.0.1")
66+
-l Avoid uploading the dump to a S3 bucket. Default is 'false'
67+
-p int
68+
PostgreSQL port (default 5432)
69+
-t string
70+
The type of database to back up (e.g., postgres) (default "postgres")
71+
```
72+
73+
### Restore
74+
75+
The `restore` sub-command works both using an S3 URI or a local file path
76+
77+
It works the same way as the `dump` sub-command but it has an option to speed-up the restore passing the number of CPU
78+
cores you want to use.
79+
80+
```bash
81+
dbdump restore --help
82+
Usage of restore:
83+
-U string
84+
PostgreSQL user (default "postgres")
85+
-W string
86+
PostgreSQL password
87+
-d string
88+
Name of the DB to restore (default "eclaim")
89+
-f string
90+
The absolute path of the dump file to restore the DB from or the S3 URI
91+
-h string
92+
PostgreSQL host (default "127.0.0.1")
93+
-n int
94+
Number of parallel processes (1 per CPU Core) to use (default 2)
95+
-p int
96+
PostgreSQL port (default 5432)
97+
-s Download the dump from AWS S3 (default true)
98+
-t string
99+
The type of database to restore (postgres,mysql,etc...) (default "postgres")
100+
```

0 commit comments

Comments
 (0)