ops_backups 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -110
- data/app/controllers/ops_backups/application_controller.rb +4 -0
- data/app/helpers/{ops → ops_backups}/application_helper.rb +1 -1
- data/app/jobs/ops_backups/application_job.rb +4 -0
- data/app/jobs/{ops/backups → ops_backups}/backup_db_job.rb +1 -1
- data/app/jobs/{ops/backups → ops_backups}/cleanup_limit_job.rb +1 -1
- data/app/jobs/{ops/backups → ops_backups}/cleanup_tiered_job.rb +1 -1
- data/app/mailers/ops_backups/application_mailer.rb +6 -0
- data/app/models/ops_backups/application_record.rb +5 -0
- data/app/models/{ops/backups → ops_backups}/backup.rb +4 -5
- data/app/views/layouts/{ops → ops_backups}/application.html.erb +2 -2
- data/config/routes.rb +1 -1
- data/lib/generators/ops_backups/install/USAGE +8 -0
- data/lib/generators/ops_backups/install/install_generator.rb +51 -0
- data/lib/ops_backups/engine.rb +11 -0
- data/lib/ops_backups/version.rb +3 -0
- data/lib/ops_backups.rb +6 -0
- data/lib/tasks/{ops_tasks.rake → ops_backups_tasks.rake} +1 -1
- metadata +18 -15
- data/app/controllers/ops/backups/application_controller.rb +0 -6
- data/app/jobs/ops/backups/application_job.rb +0 -6
- data/app/models/ops/backups/application_record.rb +0 -8
- data/lib/ops/backups/backups.rb +0 -8
- data/lib/ops/backups/engine.rb +0 -7
- data/lib/ops/backups/version.rb +0 -5
- /data/app/assets/stylesheets/{ops → ops_backups}/application.css +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f1ef117c4c1f91b7ca59eba0f0a27d2387b2f69c7d9f5022d1306c145d19eb
|
4
|
+
data.tar.gz: 1c479131ca94764b617a99cb8ea9896596ceda64aadc7a3281acbbca86286471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8da64fbec202205ff7771d222b26b4c1513467e2001f4d4997bc7f7f18e66390743ade3a68b253e684a67fcb58233d3c58c34e824e1ab528ade2260a0b9c252
|
7
|
+
data.tar.gz: 5246ea35123d5b4aa7748362b1ee89915450d56a433cfa1f62df9089081c62d63a8551ce6361d103d761096eb5564eb053ed8fcb15d9b96a7aa45b283e816fca
|
data/README.md
CHANGED
@@ -1,117 +1,14 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
## Description
|
4
|
-
Ops is a Ruby gem designed to enhance and to backup your PostgreSQL database.
|
1
|
+
# OpsBackups
|
2
|
+
Short description and motivation.
|
5
3
|
|
6
4
|
## Usage
|
7
|
-
|
8
|
-
### Configuration
|
9
|
-
|
10
|
-
To configure the Ops gem, you need to set up the following environment variables:
|
11
|
-
- `DATABASE_URL`: The URL of the PostgreSQL database to backup.
|
12
|
-
|
13
|
-
Set up Active Storage for backups (e.g., Amazon S3 for production). We expect a service named `:backup_storage` to be configured.
|
14
|
-
|
15
|
-
```yaml
|
16
|
-
backup_storage:
|
17
|
-
service: S3
|
18
|
-
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
|
19
|
-
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
20
|
-
region: <%= ENV['AWS_REGION'] %>
|
21
|
-
bucket: backups
|
22
|
-
```
|
23
|
-
### Backup Method
|
24
|
-
|
25
|
-
The `Ops::Backup` class provides a method to perform a PostgreSQL database backup:
|
26
|
-
|
27
|
-
- `db_pg_backup(exclude_tables: [], tag: nil)`: This method performs a full backup of the database, optionally excluding specified tables. The backup is tagged and saved as an attachment.
|
28
|
-
|
29
|
-
example:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
Ops::Backup.new.db_pg_backup(exclude_tables: ["versions"], tag: "db_pg_unveresioned")
|
33
|
-
```
|
34
|
-
|
35
|
-
### Backup Retention Strategies
|
36
|
-
|
37
|
-
Ops gem provides two backup retention strategies:
|
38
|
-
|
39
|
-
1. **Tiered Cleanup Policy**:
|
40
|
-
- Keeps all backups from the last day.
|
41
|
-
- Keeps the last backup of each day from the last week (except the last day).
|
42
|
-
- Keeps the last backup of each week from the last month (except the last week).
|
43
|
-
- Keeps the last backup of each month before the last month.
|
44
|
-
|
45
|
-
example:
|
46
|
-
```ruby
|
47
|
-
Ops::CleanupTiered.new.cleanup("db_pg_unversioned")
|
48
|
-
```
|
49
|
-
|
50
|
-
This policy can be applied using the `Ops::CleanupTieredJob`.
|
51
|
-
|
52
|
-
2. **Limit Cleanup Policy**:
|
53
|
-
- Keeps the last N backups, where N is specified by the `limit` parameter.
|
54
|
-
|
55
|
-
example:
|
56
|
-
```ruby
|
57
|
-
Ops::CleanupLimit.new.cleanup("db_pg_unversioned", limit: 14)
|
58
|
-
```
|
59
|
-
|
60
|
-
This policy can be applied using the `Ops::CleanupLimitJob`.
|
61
|
-
|
62
|
-
### Using SolidQueue Schedule
|
63
|
-
|
64
|
-
1. Schedule the backup job using SolidQueue:
|
65
|
-
```ruby
|
66
|
-
SolidQueue.schedule(Ops::BackupDbJob.new, cron: '0 0 * * *', args: { tag: "db_pg_full", exclude_tables: [], cleanup: "retain_last_limit" }) # This schedules the backup job to run daily at midnight
|
67
|
-
```
|
68
|
-
|
69
|
-
2. Schedule the cleanup job with a tiered policy:
|
70
|
-
```ruby
|
71
|
-
SolidQueue.schedule(Ops::CleanupTieredJob.new, cron: '0 1 * * *', args: { tag: "db_pg_full" }) # This schedules the tiered cleanup job to run daily at 1 AM
|
72
|
-
```
|
73
|
-
|
74
|
-
3. Schedule the cleanup job with a limit policy:
|
75
|
-
```ruby
|
76
|
-
SolidQueue.schedule(Ops::CleanupLimitJob.new, cron: '0 2 * * *', args: { tag: "db_pg_full", limit: 14 }) # This schedules the limit cleanup job to run daily at 2 AM
|
77
|
-
```
|
78
|
-
|
79
|
-
### Using `recurring.yml` from SolidQueue
|
80
|
-
|
81
|
-
Alternatively, you can configure recurring tasks using `recurring.yml` in your SolidQueue configuration:
|
82
|
-
|
83
|
-
1. Create or update the `recurring.yml` file in your application's config directory:
|
84
|
-
```yaml
|
85
|
-
# filepath: config/recurring.yml
|
86
|
-
backup_db_job:
|
87
|
-
cron: "0 0 * * *"
|
88
|
-
class: "Ops::BackupDbJob"
|
89
|
-
args:
|
90
|
-
tag: "db_pg_full"
|
91
|
-
exclude_tables: []
|
92
|
-
cleanup: "retain_last_limit"
|
93
|
-
|
94
|
-
cleanup_tiered_job:
|
95
|
-
cron: "0 1 * * *"
|
96
|
-
class: "Ops::CleanupTieredJob"
|
97
|
-
args:
|
98
|
-
tag: "db_pg_full"
|
99
|
-
|
100
|
-
cleanup_limit_job:
|
101
|
-
cron: "0 2 * * *"
|
102
|
-
class: "Ops::CleanupLimitJob"
|
103
|
-
args:
|
104
|
-
tag: "db_pg_full"
|
105
|
-
limit: 14
|
106
|
-
```
|
107
|
-
|
108
|
-
|
5
|
+
How to use my plugin.
|
109
6
|
|
110
7
|
## Installation
|
111
8
|
Add this line to your application's Gemfile:
|
112
9
|
|
113
10
|
```ruby
|
114
|
-
gem "
|
11
|
+
gem "ops_backups"
|
115
12
|
```
|
116
13
|
|
117
14
|
And then execute:
|
@@ -121,12 +18,11 @@ $ bundle
|
|
121
18
|
|
122
19
|
Or install it yourself as:
|
123
20
|
```bash
|
124
|
-
$ gem install
|
21
|
+
$ gem install ops_backups
|
125
22
|
```
|
126
23
|
|
127
24
|
## Contributing
|
128
|
-
|
129
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/koenhandekyn/ops.
|
25
|
+
Contribution directions go here.
|
130
26
|
|
131
27
|
## License
|
132
28
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,9 +1,8 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
class Ops::Backups::Backup < ApplicationRecord
|
1
|
+
module OpsBackups
|
2
|
+
class Backup < ApplicationRecord
|
5
3
|
# has_one_attached :backup_file, service: :backup_storage
|
6
|
-
has_one_attached :backup_file
|
4
|
+
has_one_attached :backup_file, service: :backups
|
5
|
+
self.table_name = "ops_backups"
|
7
6
|
|
8
7
|
default_scope { order(updated_at: :desc) }
|
9
8
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title>Ops</title>
|
4
|
+
<title>Ops backups</title>
|
5
5
|
<%= csrf_meta_tags %>
|
6
6
|
<%= csp_meta_tag %>
|
7
7
|
|
8
8
|
<%= yield :head %>
|
9
9
|
|
10
|
-
<%= stylesheet_link_tag
|
10
|
+
<%= stylesheet_link_tag "ops_backups/application", media: "all" %>
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
|
data/config/routes.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
OpsBackups::Engine.routes.draw do
|
2
2
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class OpsBackups::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path("templates", __dir__)
|
3
|
+
|
4
|
+
desc "Copies migrations and adds a storage service configuration to storage.yml"
|
5
|
+
|
6
|
+
def copy_migrations
|
7
|
+
rake "railties:install:migrations FROM=ops_backups"
|
8
|
+
say "Migrations copied to your application.", :green
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_storage_service
|
12
|
+
storage_file = Rails.root.join("config", "storage.yml")
|
13
|
+
|
14
|
+
if File.exist?(storage_file)
|
15
|
+
service_config = <<~YAML
|
16
|
+
|
17
|
+
backups:
|
18
|
+
service: Disk
|
19
|
+
root: <%= Rails.root.join("storage") %>
|
20
|
+
# service: S3
|
21
|
+
# access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
|
22
|
+
# secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
23
|
+
# region: <%= ENV['AWS_REGION'] %>
|
24
|
+
# bucket: allcrux-backups
|
25
|
+
YAML
|
26
|
+
|
27
|
+
append_to_file storage_file, service_config
|
28
|
+
say "Added 'backups' service to storage.yml.", :green
|
29
|
+
else
|
30
|
+
say "config/storage.yml not found. Please create it and re-run this generator.", :red
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_recurring_jobs
|
35
|
+
recurring_file = Rails.root.join("config", "recurring.yml")
|
36
|
+
|
37
|
+
if File.exist?(recurring_file)
|
38
|
+
recurring_config = <<~YAML.lines.map { |line| "\t#{line}" }.join
|
39
|
+
backup_db:
|
40
|
+
class: OpsBackups::BackupDbJob
|
41
|
+
args: [tag: "db_pg_backup", cleanup: "retain_tiered_cleanup_policy"]
|
42
|
+
schedule: every hour
|
43
|
+
YAML
|
44
|
+
|
45
|
+
append_to_file recurring_file, recurring_config
|
46
|
+
say "Added 'recurring' jobs to recurring.yml.", :green
|
47
|
+
else
|
48
|
+
say "config/recurring.yml not found. Please create it and re-run this generator.", :red
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module OpsBackups
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace OpsBackups
|
4
|
+
|
5
|
+
initializer :append_migrations do |app|
|
6
|
+
unless app.root.to_s.match? root.to_s
|
7
|
+
app.config.paths["db/migrate"].concat(config.paths["db/migrate"].expanded)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/ops_backups.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ops_backups
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koen Handekyn
|
@@ -35,22 +35,25 @@ files:
|
|
35
35
|
- MIT-LICENSE
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
|
-
- app/assets/stylesheets/
|
39
|
-
- app/controllers/
|
40
|
-
- app/helpers/
|
41
|
-
- app/jobs/
|
42
|
-
- app/jobs/
|
43
|
-
- app/jobs/
|
44
|
-
- app/jobs/
|
45
|
-
- app/
|
46
|
-
- app/models/
|
47
|
-
- app/
|
38
|
+
- app/assets/stylesheets/ops_backups/application.css
|
39
|
+
- app/controllers/ops_backups/application_controller.rb
|
40
|
+
- app/helpers/ops_backups/application_helper.rb
|
41
|
+
- app/jobs/ops_backups/application_job.rb
|
42
|
+
- app/jobs/ops_backups/backup_db_job.rb
|
43
|
+
- app/jobs/ops_backups/cleanup_limit_job.rb
|
44
|
+
- app/jobs/ops_backups/cleanup_tiered_job.rb
|
45
|
+
- app/mailers/ops_backups/application_mailer.rb
|
46
|
+
- app/models/ops_backups/application_record.rb
|
47
|
+
- app/models/ops_backups/backup.rb
|
48
|
+
- app/views/layouts/ops_backups/application.html.erb
|
48
49
|
- config/routes.rb
|
49
50
|
- db/migrate/20241114173612_create_ops_backups.rb
|
50
|
-
- lib/
|
51
|
-
- lib/
|
52
|
-
- lib/
|
53
|
-
- lib/
|
51
|
+
- lib/generators/ops_backups/install/USAGE
|
52
|
+
- lib/generators/ops_backups/install/install_generator.rb
|
53
|
+
- lib/ops_backups.rb
|
54
|
+
- lib/ops_backups/engine.rb
|
55
|
+
- lib/ops_backups/version.rb
|
56
|
+
- lib/tasks/ops_backups_tasks.rake
|
54
57
|
homepage: https://github.com/koenhandekyn/ops-backups
|
55
58
|
licenses:
|
56
59
|
- MIT
|
data/lib/ops/backups/backups.rb
DELETED
data/lib/ops/backups/engine.rb
DELETED
data/lib/ops/backups/version.rb
DELETED
File without changes
|