2
2
3
3
This is ~~ a hacky~~ an interesting way to have a Fly app that dumps postgres databases
4
4
that are also on Fly, to AWS S3 buckets.
5
- It uses a dedicated app for the * backup worker * that is _ woken up_ to start the dump.
5
+ It uses a dedicated app for the _ backup worker _ that is _ woken up_ to start the dump.
6
6
When it finishes it is _ scaled_ back to 0, meaning ** it is not billable when idle** ,
7
- you only pay for the backup time (it is close to free, and supper affordable even with
7
+ you only pay for the backup time (it is close to free, and supper affordable even with
8
8
high end machines). It leverages Fly machines to dynamically deploy volumes and servers on demand.
9
9
10
10
@@ -25,6 +25,7 @@ Have a look into [create-resources-utils](./create-resources-utils) for scripts
25
25
requirements in a simple way.
26
26
27
27
1 . In a PG shell inside your Fly Postgres instance, create an user with read permissions:
28
+
28
29
``` sql
29
30
CREATE USER db_backup_worker WITH PASSWORD ' <password>' ;
30
31
GRANT CONNECT ON DATABASE < db_name> TO db_backup_worker;
@@ -43,22 +44,20 @@ requirements in a simple way.
43
44
IAM policy:
44
45
``` json
45
46
{
46
- "Version" : " 2012-10-17" ,
47
- "Statement" : [
48
- {
49
- "Sid" : " WriteDatabaseBackups" ,
50
- "Effect" : " Allow" ,
51
- "Action" : [
52
- " s3:PutObject" ,
53
- " s3:AbortMultipartUpload" ,
54
- " s3:ListMultipartUploadParts"
55
- ],
56
- "Resource" : [
57
- " arn:aws:s3:::your-s3-bucket/backup.tar.gz"
58
- ]
59
- }
60
- ]
61
- }
47
+ "Version" : " 2012-10-17" ,
48
+ "Statement" : [
49
+ {
50
+ "Sid" : " WriteDatabaseBackups" ,
51
+ "Effect" : " Allow" ,
52
+ "Action" : [
53
+ " s3:PutObject" ,
54
+ " s3:AbortMultipartUpload" ,
55
+ " s3:ListMultipartUploadParts"
56
+ ],
57
+ "Resource" : [" arn:aws:s3:::your-s3-bucket/backup.tar.gz" ]
58
+ }
59
+ ]
60
+ }
62
61
```
63
62
64
63
@@ -67,15 +66,17 @@ requirements in a simple way.
67
66
1 . Launch your database backup worker with ` fly apps create --machines `
68
67
69
68
2 . Set the required fly secrets (env vars). Example:
70
- ``` env
71
- AWS_ACCESS_KEY_ID=XXXX
72
- AWS_SECRET_ACCESS_KEY=XXXX
73
- DATABASE_URL=postgresql://username:password@my-fly-db-instance.internal:5432/my_database
74
- S3_DESTINATION=s3://your-s3-bucket/backup.tar.gz
75
- ```
69
+
70
+ ``` env
71
+ AWS_ACCESS_KEY_ID=XXXX
72
+ AWS_SECRET_ACCESS_KEY=XXXX
73
+ DATABASE_URL=postgresql://username:password@my-fly-db-instance.internal:5432/my_database
74
+ S3_DESTINATION=s3://your-s3-bucket/backup.tar.gz
75
+ ```
76
76
77
77
3 . OPTION A: Run ` ./trigger-backup.sh ` whenever you want to start a backup.
78
- - `FLY_APP`: (Required) Your fly application.
78
+
79
+ - ` FLY_APP ` : (Required) Your fly application.
79
80
- ` FLY_API_TOKEN ` : (Required) Fly token (PAT or Deploy token).
80
81
- ` FLY_REGION ` : the region of the volume and consequently the region where the worker will run.
81
82
Choose one close to the db and the AWS bucket region. Defaults to ` cdg ` .
@@ -87,33 +88,32 @@ requirements in a simple way.
87
88
Option to override the default docker image ` ghcr.io/significa/fly-pg-dump-to-s3:3 `
88
89
- ` ENSURE_NO_VOLUMES_LEFT ` : When the backup completes and the volume is deleted, checks if there
89
90
are any volumes still available, and crashes if so. This might be useful to alert that there
90
- are dangling volumes (that you might want to be paying). Defaults to `true`. If you are making
91
- concurrent backups, set it to `false`.
91
+ are dangling volumes (that you might want to be paying for).
92
+ Defaults to ` false ` (warning to stderr only) .
92
93
93
- The volume will be deleted when the backup finishes.
94
-
95
- OPTION B: Optionally you can use the reusable GitHub Actions workflow from found in
94
+ OPTION B: Call the reusable GitHub Actions workflow found in
96
95
` .github/workflows/trigger-backup.yaml ` . Example workflow definition:
97
96
98
- ```yaml
99
- name: Backup databases
100
- on:
101
- workflow_dispatch:
102
- schedule:
103
- # Runs Every day at 5:00am UTC
104
- - cron: "00 5 * * *"
105
-
106
- jobs:
107
- backup-databases:
108
- name: Backup databases
109
- uses: significa/fly-pg-dump-to-s3/.github/workflows/trigger-backup.yaml@v3
110
- with:
111
- fly-app: my-db-backup-worker
112
- volume-size: 3
113
- region: ewr
114
- secrets:
115
- FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
116
- ```
97
+ ``` yaml
98
+ name : Backup databases
99
+ on :
100
+ workflow_dispatch :
101
+ schedule :
102
+ # Runs Every day at 5:00am UTC
103
+ - cron : " 00 5 * * *"
104
+
105
+ jobs :
106
+ backup-databases :
107
+ name : Backup databases
108
+ uses : significa/fly-pg-dump-to-s3/.github/workflows/trigger-backup.yaml@v3
109
+ with :
110
+ fly-app : my-db-backup-worker
111
+ volume-size : 3
112
+ machine-size : shared-cpu-4x
113
+ region : ewr
114
+ secrets :
115
+ FLY_API_TOKEN : ${{ secrets.FLY_API_TOKEN }}
116
+ ` ` `
117
117
118
118
119
119
## Backup history
0 commit comments