Skip to content

Commit

Permalink
refactor: structure improvement, use YAML to replace TOML as configur…
Browse files Browse the repository at this point in the history
…ation file
  • Loading branch information
AlisaAkiron committed Mar 7, 2024
1 parent c4069e4 commit e958d8b
Show file tree
Hide file tree
Showing 35 changed files with 660 additions and 606 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/target
.idea
*.dev.toml
*.dev.yaml

desktop.ini
.DS_Store
Expand Down
69 changes: 18 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ edition = "2021"

[dependencies]
aws-sdk-s3 = "1.17.0"
confy = "0.6.1"
confy = { version = "0.6.1", default_features = false, features = [
"yaml_conf",
] }
env_logger = "0.11.3"
log = { version = "0.4.21", features = ["serde"] }
once_cell = "1.19.0"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ VOLUME [ "/app/config"]
VOLUME [ "/var/lib/pg-auto-backup" ]

ENTRYPOINT [ "/app/pg-auto-backup" ]
CMD [ "-c", "/app/config/config.toml" ]
CMD [ "-c", "/app/config/config.yaml" ]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Backup PostgreSQL databases by running `pg_dump` and save the output to local fi

### Binary

Copy and modify the [default configuration file](./example/default.toml)
Copy and modify the [default configuration file](./example/default.yaml)

You can pass the configuration file path as an argument or set the `PG_AUTO_BACKUP_CONFIG` environment variable.

```sh
PG_AUTO_BACKUP_CONFIG=/path/to/config.toml ./pg-auto-backup # set in environment variable
./pg-auto-backup -c /path/to/config.toml # pass as argument
PG_AUTO_BACKUP_CONFIG=/path/to/config.yaml ./pg-auto-backup # set in environment variable
./pg-auto-backup -c /path/to/config.yaml # pass as argument
```

If none of the above is set, the program will create a default configuration file at the default location set by the [ProjectDirs.config_dir()](https://docs.rs/directories/latest/directories/struct.ProjectDirs.html#method.config_dir)
Expand All @@ -23,7 +23,7 @@ If none of the above is set, the program will create a default configuration fil

Mount the flowwing volumes:

- `/app/config/config.toml` - the configuration file
- `/app/config/config.yaml` - the configuration file
- `/var/lib/pg-auto-backup` - the backup files if using local storage

The prebuilt image contains PostgreSQL 14/15/16 client tools.
Expand All @@ -35,7 +35,7 @@ The prebuilt image contains PostgreSQL 14/15/16 client tools.
- `/usr/libexec/postgresql16/pg_dump` for PostgreSQL 16

```sh
docker run -v /path/to/config.toml:/app/config/config.toml -v /path/to/backup:/var/lib/pg-auto-backup ghcr.io/liamsho/pg-auto-backup:latest
docker run -v /path/to/config.yaml:/app/config/config.yaml -v /path/to/backup:/var/lib/pg-auto-backup ghcr.io/liamsho/pg-auto-backup:latest
```

## License
Expand Down
147 changes: 147 additions & 0 deletions example/database/postgresql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
postgresql:
connection:
# Database host
host: "localhost"

# Database port
port: 5432

# Database user
# Note that the user must have the necessary permissions to perform the backup
user: "postgres"

# Database user password
password: "password"

client:
# Path to pg_dump binary
binary_path: "/usr/bin/pg_dump"

# Format of the backup (Plain, Custom, Tar)
# Can be overridden by database specific settings
# Note that the directory type is not supported
# --format={} option in pg_dump
format: "Plain"

# Section to include in the backup (PreData, Data, PostData)
# --section={} option in pg_dump
sections:
- "PreData"
- "Data"
- "PostData"

# Whether to create the database before restoring
# Can be omitted
# Can be overridden by database specific settings
# --create option in pg_dump
## create: false

# Whether to drop the database before restoring
# Can be omitted
# Can be overridden by database specific settings
# --clean option in pg_dump
## clean: false

# Do not save the corresponding data
# Can be omitted
# Can be overridden by database specific settings
# Available values:
# LargeObjects, Owner, Privileges, Comments,
# Publications, SecurityLabels, Subscriptions,
# TableAccessMethod, Tablespace, ToastCompression,
# UnloggedTableData
# --no-{} option in pg_dump
## do_not_save: []

# Disable something
# Can be omitted
# Can be overridden by database specific settings
# Available values:
# DollarQuoting, Triggers
# --disable={} option in pg_dump
## disable: []

# Extra arguments for pg_dump
# Can be omitted
# Can be overridden by database specific settings
## extra_args: []

# The databases that need to be backed up
databases:
# Database name with other options omitted
- "db-1"
# Detailed database configuration
- # Database name
name: "my_database"

# Format of the backup (Plain, Custom, Tar)
# Can be omitted
# Will override the pg_dump.format option
# Note that the directory type is not supported
# --format={} option in pg_dump
## format: "Plain"

# Tables to include in the backup, empty for all
# Can be omitted
# --table={} option in pg_dump
## include_tables: []

# Tables to exclude from the backup
# Can be omitted
# --exclude-table={} option in pg_dump
## exclude_tables: []

# Schemas to include in the backup, empty for all
# Can be omitted
# --schema={} option in pg_dump
## include_schema: []

# Schemas to exclude from the backup
# Can be omitted
# --exclude-schema={} option in pg_dump
## exclude_schema: []

# Section to include in the backup (PreData, Data, PostData)
# Can be omitted
# Will override the pg_dump.sections option
# --section={} option in pg_dump
## sections:
## - "PreData"
## - "Data"
## - "PostData"

# Whether to create the database before restoring
# Can be omitted
# Will override the pg_dump.create option
# --create option in pg_dump
## create: false

# Whether to drop the database before restoring
# Can be omitted
# Will override the pg_dump.clean option
# --clean option in pg_dump
## clean: false

# Do not save the corresponding data
# Can be omitted
# Will override the pg_dump.do_not_save option
# Available values:
# LargeObjects, Owner, Privileges, Comments,
# Publications, SecurityLabels, Subscriptions,
# TableAccessMethod, Tablespace, ToastCompression,
# UnloggedTableData
# --no-{} option in pg_dump
## do_not_save: []

# Disable something
# Can be omitted
# Will override the pg_dump.disable option
# Available values:
# DollarQuoting, Triggers
# --disable={} option in pg_dump
## disable: []

# Extra arguments for pg_dump
# Can be omitted
# Will override the pg_dump.extra_args option
## extra_args: []
Loading

0 comments on commit e958d8b

Please sign in to comment.