litebackup 1.3.0-x86_64-darwin
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +109 -0
- data/lib/litebackup/bin/litebackup +4 -0
- data/lib/litebackup/binary.rb +108 -0
- data/lib/litebackup/client.rb +520 -0
- data/lib/litebackup/credential.rb +65 -0
- data/lib/litebackup/errors.rb +132 -0
- data/lib/litebackup/failover.rb +416 -0
- data/lib/litebackup/foreground.rb +185 -0
- data/lib/litebackup/generated/error_codes.rb +38 -0
- data/lib/litebackup/generated/models.rb +724 -0
- data/lib/litebackup/integrations/rails.rb +142 -0
- data/lib/litebackup/integrations/sqlite3.rb +55 -0
- data/lib/litebackup/integrations/sqlite_file.rb +81 -0
- data/lib/litebackup/launch.rb +146 -0
- data/lib/litebackup/paths.rb +86 -0
- data/lib/litebackup/pool.rb +790 -0
- data/lib/litebackup/release.rb +98 -0
- data/lib/litebackup/transport.rb +352 -0
- data/lib/litebackup/umask.rb +53 -0
- data/lib/litebackup/version.rb +8 -0
- data/lib/litebackup/wire.rb +436 -0
- data/lib/litebackup/wire_model.rb +55 -0
- data/lib/litebackup.rb +61 -0
- metadata +66 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6643b644b8e0c739048364fd1ad0544ac38d28000bda72a5e6938f9c8fb71f30
|
|
4
|
+
data.tar.gz: edcd5bb684fc46fee31af2bfd3780c5c0e53c2196f5b31abae6be6d57e2d0234
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 49f09c15bb7c24be2e4f163520f0af9972603cc7559ba023a232da9971e59fd977c08609ed676fd9723f269b583a6a20ce88a7bdc4de5eb946450b9868c41634
|
|
7
|
+
data.tar.gz: 5c64753d3139d250160b2b5e4a2241d5ad512c44ea448243c13eb85d4e9e2ceb672701b7e6661f1fa5ed54666ede3d350087870d81cf933bf980d33bbd94a0bc
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Litebackup
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Litebackup for Ruby
|
|
2
|
+
|
|
3
|
+
Back up, replicate, and restore SQLite databases with your Litebackup server
|
|
4
|
+
and bucket, from Ruby and Rails. Ruby 3.2 or later on Linux or macOS. The gem
|
|
5
|
+
has no runtime dependencies; the sqlite3 adapter and the Rails integration
|
|
6
|
+
load those gems when you require them.
|
|
7
|
+
|
|
8
|
+
Install the gem from RubyGems, or add it to your `Gemfile`:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
gem install litebackup
|
|
12
|
+
export LITEBACKUP_API_KEY='JOIN_TOKEN@your-instance.litebackup.cloud'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`LITEBACKUP_API_KEY` is the value from **Machines → Add machine**, or an API
|
|
16
|
+
key followed by @ and your server address. RubyGems and Bundler install the
|
|
17
|
+
platform gem for Linux (glibc and musl) or macOS, on x64 or arm64, which
|
|
18
|
+
carries the `litebackup` command without putting it on `PATH`. Elsewhere the
|
|
19
|
+
plain gem uses an installed `litebackup` command: install it with
|
|
20
|
+
`curl -fsSL https://litebackup.com/cli.sh | bash`, or set `LITEBACKUP_PATH`.
|
|
21
|
+
|
|
22
|
+
## Back up an app's database
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require "litebackup"
|
|
26
|
+
require "litebackup/integrations/sqlite3"
|
|
27
|
+
|
|
28
|
+
FileUtils.mkdir_p("data")
|
|
29
|
+
database = SQLite3::Database.new("data/app.sqlite")
|
|
30
|
+
Litebackup::Client.open do |litebackup|
|
|
31
|
+
rule = litebackup.backups.start(Litebackup::Integrations::SQLite3.database_path(database))
|
|
32
|
+
puts "#{rule.id} #{rule.name}"
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`backups.start` returns the saved rule when the same path was registered
|
|
37
|
+
with the same settings, so call it on every start. Different settings for a
|
|
38
|
+
saved path raise `rule_exists`, with the saved rule in `error.details["rule"]`.
|
|
39
|
+
|
|
40
|
+
## Rails
|
|
41
|
+
|
|
42
|
+
Name the databases to back up in `config/application.rb`. Each is a database
|
|
43
|
+
of the environment's `config/database.yml`, the Solid Queue, Cache, and Cable
|
|
44
|
+
databases included:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
require "litebackup/integrations/rails"
|
|
48
|
+
|
|
49
|
+
module App
|
|
50
|
+
class Application < Rails::Application
|
|
51
|
+
config.litebackup.databases = { primary: {}, queue: {}, cache: {}, cable: {} }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The backups are registered after the app initializes, in every process that
|
|
57
|
+
boots it, with the same settings each time. Registration is off in the test
|
|
58
|
+
environment and in Rake tasks such as `assets:precompile` and `db:migrate`;
|
|
59
|
+
set `config.litebackup.enabled` to choose. The [Ruby guide](../docs/sqlite-ruby.md)
|
|
60
|
+
has the options.
|
|
61
|
+
|
|
62
|
+
## Move a database between machines
|
|
63
|
+
|
|
64
|
+
A pool keeps a database open between calls. A lease locks the database for
|
|
65
|
+
this machine, so no other machine writes it, and keeps the lock until the
|
|
66
|
+
pool releases it:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
require "litebackup"
|
|
70
|
+
require "litebackup/integrations/sqlite3"
|
|
71
|
+
|
|
72
|
+
Litebackup::Client.open do |litebackup|
|
|
73
|
+
litebackup.databases.pool(Litebackup::Integrations::SQLite3.adapter) do |pool|
|
|
74
|
+
pool.lease("agents/42.sqlite", path: "data/agents/42.sqlite", durability: "server") do |db|
|
|
75
|
+
db.execute("CREATE TABLE IF NOT EXISTS steps (body TEXT)")
|
|
76
|
+
db.execute("INSERT INTO steps (body) VALUES (?)", ["tests passed"])
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The adapter never commits: SQLite commits each statement outside a
|
|
83
|
+
transaction, and a transaction the block leaves open is rolled back when the
|
|
84
|
+
pool closes the database. A block that raises, or that it leaves with
|
|
85
|
+
`break` or `return`, keeps the lease and never offloads.
|
|
86
|
+
|
|
87
|
+
## Errors
|
|
88
|
+
|
|
89
|
+
Every failure is a `Litebackup::Error` with `code`, `message`, `status`, and
|
|
90
|
+
`details`. `Litebackup::ErrorCode` names the codes worth matching:
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
begin
|
|
94
|
+
litebackup.databases.acquire("agents/42.sqlite", path: "data/agents/42.sqlite")
|
|
95
|
+
rescue Litebackup::Error => e
|
|
96
|
+
raise unless e.code == Litebackup::ErrorCode::LOCK_UNAVAILABLE
|
|
97
|
+
|
|
98
|
+
warn("another machine writes agents/42.sqlite; try again later")
|
|
99
|
+
end
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
`scripts/test` runs the tests and rubocop in `ruby:3.2.11-slim`,
|
|
105
|
+
`ruby:3.3.14-slim`, and `ruby:3.4.13-slim` as the calling user;
|
|
106
|
+
`scripts/test generate` regenerates `lib/litebackup/generated/models.rb` from
|
|
107
|
+
`../client-openapi.yaml`. The [SDK reference](../docs/sdk-reference.md) lists
|
|
108
|
+
every method, and [the contract](../docs/sdk-contract.md) the behavior the
|
|
109
|
+
Go, TypeScript, Python, and Ruby SDKs share.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Litebackup
|
|
4
|
+
BINARY_PATH_ENVIRONMENT = "LITEBACKUP_PATH"
|
|
5
|
+
|
|
6
|
+
# Finding the litebackup binary. Nothing is downloaded at runtime.
|
|
7
|
+
module Binary
|
|
8
|
+
# Where a platform gem carries its binary. The gemspec lists it as a
|
|
9
|
+
# file, not an executable, so gem install writes no wrapper for it.
|
|
10
|
+
BUNDLED_PATH = File.join(__dir__, "bin", "litebackup")
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
# The one line that installs the litebackup command on Linux and macOS for whoever runs it.
|
|
15
|
+
def install_command
|
|
16
|
+
"curl -fsSL https://litebackup.com/cli.sh | bash"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def executable?(path)
|
|
20
|
+
File.file?(path) && File.executable?(path)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# The binary this platform's gem carries, or nil for the plain gem.
|
|
24
|
+
def bundled_binary
|
|
25
|
+
executable?(BUNDLED_PATH) ? BUNDLED_PATH : nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Finds the litebackup binary: the explicit path, then LITEBACKUP_PATH,
|
|
29
|
+
# then the binary the gem bundles, then litebackup on PATH, then
|
|
30
|
+
# ~/.local/bin/litebackup. Raises binary_not_found with the install
|
|
31
|
+
# command when there is none, or when the explicit path or LITEBACKUP_PATH
|
|
32
|
+
# names no file.
|
|
33
|
+
def litebackup_binary(environment = ENV, binary_path = nil)
|
|
34
|
+
override = binary_path.to_s.strip
|
|
35
|
+
override = environment[BINARY_PATH_ENVIRONMENT].to_s.strip if override.empty?
|
|
36
|
+
unless override.empty?
|
|
37
|
+
# An explicit path that names no file never falls back to another
|
|
38
|
+
# binary; a file that cannot run fails later, as launch_failed.
|
|
39
|
+
if missing_path?(override)
|
|
40
|
+
raise Error.new(
|
|
41
|
+
ErrorCode::BINARY_NOT_FOUND,
|
|
42
|
+
"the litebackup binary #{override} does not exist; " \
|
|
43
|
+
"set binary_path or #{BINARY_PATH_ENVIRONMENT} to it, or install it with: #{install_command}"
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
return override
|
|
47
|
+
end
|
|
48
|
+
bundled = bundled_binary
|
|
49
|
+
return bundled unless bundled.nil?
|
|
50
|
+
|
|
51
|
+
found = path_binary(environment["PATH"].to_s)
|
|
52
|
+
return found unless found.nil?
|
|
53
|
+
|
|
54
|
+
home = Wire.supplied?(environment["HOME"]) ? environment["HOME"] : Dir.home
|
|
55
|
+
local = File.join(home, ".local", "bin", "litebackup")
|
|
56
|
+
return local if executable?(local)
|
|
57
|
+
|
|
58
|
+
raise Error.new(
|
|
59
|
+
ErrorCode::BINARY_NOT_FOUND,
|
|
60
|
+
"the litebackup command is not installed; set #{BINARY_PATH_ENVIRONMENT} or install it with: #{install_command}"
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# The first executable litebackup in a PATH value.
|
|
65
|
+
def path_binary(search_path)
|
|
66
|
+
search_path.split(File::PATH_SEPARATOR).reject(&:empty?).each do |directory|
|
|
67
|
+
candidate = File.join(directory, "litebackup")
|
|
68
|
+
return candidate if executable?(candidate)
|
|
69
|
+
end
|
|
70
|
+
nil
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Whether nothing is at path: it, or a directory on its way, does not
|
|
74
|
+
# exist. A path behind a directory this user may not enter is not missing.
|
|
75
|
+
def missing_path?(path)
|
|
76
|
+
File.stat(path)
|
|
77
|
+
false
|
|
78
|
+
rescue Errno::ENOENT, Errno::ENOTDIR
|
|
79
|
+
true
|
|
80
|
+
rescue SystemCallError
|
|
81
|
+
false
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Why starting binary failed. A file that is there but fails to start as
|
|
85
|
+
# missing cannot run: the interpreter its #! line names, or its dynamic
|
|
86
|
+
# loader, is not on this machine. The message names that line rather than
|
|
87
|
+
# repeating the file's path as if it were missing.
|
|
88
|
+
def start_failure_message(binary, error)
|
|
89
|
+
not_found = error.is_a?(Errno::ENOENT) || error.is_a?(Errno::ENOTDIR)
|
|
90
|
+
return "starting #{binary} failed: #{error.message}" if !not_found || missing_path?(binary)
|
|
91
|
+
|
|
92
|
+
interpreter_line = script_interpreter_line(binary)
|
|
93
|
+
unusable_binary = "starting #{binary} failed: it cannot run because"
|
|
94
|
+
return "#{unusable_binary} its interpreter or dynamic loader is not on this machine" if interpreter_line.empty?
|
|
95
|
+
|
|
96
|
+
"#{unusable_binary} the interpreter its first line names is not on this machine: #{interpreter_line}"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# The #! line that starts the file at path, or "" when it starts with none or cannot be read.
|
|
100
|
+
def script_interpreter_line(path)
|
|
101
|
+
start = File.binread(path, 256) || ""
|
|
102
|
+
first_line = start.split("\n", 2).first.to_s.force_encoding(Encoding::UTF_8).scrub
|
|
103
|
+
first_line.start_with?("#!") ? first_line.strip : ""
|
|
104
|
+
rescue SystemCallError, IOError
|
|
105
|
+
""
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|