Skip to content

Commit fc1fb0d

Browse files
feat: add restore command
1 parent 3038a52 commit fc1fb0d

17 files changed

Lines changed: 787 additions & 108 deletions

File tree

.golangci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ linters:
7575
settings:
7676
cyclop:
7777
max-complexity: 30
78-
package-average: 10
78+
package-average: 11
7979
depguard:
8080
rules:
8181
deprecated:
@@ -216,6 +216,9 @@ linters:
216216
- noctx
217217
- wrapcheck
218218
path: _test\.go
219+
- linters:
220+
- gochecknoinits
221+
path: cmd/.+\.go
219222
- path: (.+)\.go$
220223
text: 'shadow: declaration of .err. shadows declaration'
221224
- path: (.+)\.go$

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,50 @@
44

55
Postgres-backup backup postgres database to local or remote storage.
66
# usage
7-
## docker
7+
## backup
8+
### docker
89
```shell
910
docker run -v ./config.hcl:/etc/postgres_backup/config.hcl ghcr.io/deltalaboratory/postgres-backup:latest
1011
```
11-
## docker compose
12+
### docker compose
1213
```yaml
1314
backup:
1415
image: ghcr.io/deltalaboratory/postgres-backup:latest
1516
volumes:
1617
- ./postgres-backup.hcl:/etc/postgres_backup/config.hcl
1718
restart: unless-stopped
1819
```
20+
21+
## restore
22+
The restore command allows you to restore PostgreSQL databases from backups stored in S3 or local storage.
23+
24+
### examples
25+
```shell
26+
# List available backups from all configured storage backends
27+
postgres-backup restore --list
28+
29+
# Restore the latest backup to the configured database
30+
postgres-backup restore --latest
31+
32+
# Restore a specific backup by timestamp/filename
33+
postgres-backup restore --backup 2024-01-15T10:30:00
34+
35+
# Restore to a different database
36+
postgres-backup restore --latest --to-database mydb_restored
37+
38+
# Restore from specific storage backend only
39+
postgres-backup restore --list --storage s3
40+
postgres-backup restore --latest --storage local
41+
```
42+
43+
### docker restore
44+
```shell
45+
# List backups
46+
docker run -v ./config.hcl:/etc/postgres_backup/config.hcl ghcr.io/deltalaboratory/postgres-backup:latest restore --list
47+
48+
# Restore latest backup
49+
docker run -v ./config.hcl:/etc/postgres_backup/config.hcl ghcr.io/deltalaboratory/postgres-backup:latest restore --latest
50+
```
1951
# configuration
2052
this project uses [HCL](https://github.com/hashicorp/hcl) for configuration file.
2153
default configuration find path is "/etc/postgres_backup/config.hcl". this can be overridden by environment variable `CONFIG_PATH`.
@@ -105,7 +137,7 @@ verbose = false
105137
- [ ] Support multiple database backup
106138
- [ ] Support notification
107139
- [X] Support backup retention
108-
- [ ] Support backup restore
140+
- [X] Support backup restore
109141
- [ ] Support streaming compress/upload backup
110142
- [ ] Support backup encryption
111143
- [ ] Support backup status dashboard?

cmd/backup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ var backupCmd = &cobra.Command{
1111
Use: "backup",
1212
Short: "Backup a PostgreSQL database",
1313
Long: `Backup a PostgreSQL database one and now`,
14-
Run: func(cmd *cobra.Command, args []string) {
15-
internal.Backup()
14+
Run: func(cmd *cobra.Command, _ []string) {
15+
internal.Backup(cmd.Context())
1616
},
1717
}
1818

0 commit comments

Comments
 (0)