backup 4.0.5 → 4.0.6
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/lib/backup.rb +1 -0
- data/lib/backup/config/dsl.rb +1 -1
- data/lib/backup/database/sqlite.rb +103 -0
- data/lib/backup/version.rb +1 -1
- data/templates/cli/databases/sqlite +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92b075a8c0c4cd0cfb491b9eebe7a832a4bd4e0c
|
4
|
+
data.tar.gz: 3f5d1f313497276ea43879502ad2729d74c417e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43f674576dfddb1feefc4ffaf068b5994ac15949a12565c2c67e234383d2e6f8f946d9ffe70a6b5ccc9db75c7a94fe32aa508cf8e474b545be83f1e57a520203
|
7
|
+
data.tar.gz: baffa3b4132cce710376518ae9e7af343077dbdadaf7eb1152aaefb870d9832b785c6c5da7d29c59879fb8fbee697529e74933c39e345e633d87ff93debcd4cc
|
data/lib/backup.rb
CHANGED
data/lib/backup/config/dsl.rb
CHANGED
@@ -27,7 +27,7 @@ module Backup
|
|
27
27
|
create_modules(
|
28
28
|
DSL,
|
29
29
|
[ # Databases
|
30
|
-
['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Riak', 'OpenLDAP'],
|
30
|
+
['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Riak', 'OpenLDAP', 'SQLite'],
|
31
31
|
# Storages
|
32
32
|
['S3', 'CloudFiles', 'Ninefold', 'Dropbox', 'FTP',
|
33
33
|
'SFTP', 'SCP', 'RSync', 'Local'],
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Database
|
5
|
+
class SQLite < Base
|
6
|
+
class Error < Backup::Error; end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Name of the database that needs to get dumped
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
# path option
|
13
|
+
attr_accessor :path
|
14
|
+
|
15
|
+
##
|
16
|
+
# Path to sqlite utility (optional)
|
17
|
+
attr_accessor :sqlitedump_utility
|
18
|
+
|
19
|
+
##
|
20
|
+
# Creates a new instance of the SQLite adapter object
|
21
|
+
def initialize(model, database_id = nil, &block)
|
22
|
+
super
|
23
|
+
instance_eval(&block) if block_given?
|
24
|
+
|
25
|
+
@name ||= :all
|
26
|
+
@sqlitedump_utility ||= utility(:sqlitedump)
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Performs the sqlitedump command and outputs the
|
31
|
+
# data to the specified path based on the 'trigger'
|
32
|
+
def perform!
|
33
|
+
super
|
34
|
+
|
35
|
+
dumps = sqlitedump
|
36
|
+
db_name_list = db_names
|
37
|
+
|
38
|
+
dumps.each_with_index do |dump, i|
|
39
|
+
pipeline = Pipeline.new
|
40
|
+
dump_ext = 'sql'
|
41
|
+
|
42
|
+
pipeline << dump
|
43
|
+
if @model.compressor
|
44
|
+
@model.compressor.compress_with do |command, ext|
|
45
|
+
pipeline << command
|
46
|
+
dump_ext << ext
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
dump_filename = db_name_list[i]
|
51
|
+
pipeline << "cat > '#{ File.join(@dump_path, dump_filename) }.#{ dump_ext }'"
|
52
|
+
|
53
|
+
pipeline.run
|
54
|
+
|
55
|
+
if pipeline.success?
|
56
|
+
log!(:finished)
|
57
|
+
else
|
58
|
+
raise Error,
|
59
|
+
"#{ database_name } Dump Failed!\n" + pipeline.error_messages
|
60
|
+
end
|
61
|
+
|
62
|
+
i += 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
##
|
69
|
+
# Builds the full SQLite dump string based on all attributes
|
70
|
+
def sqlitedump
|
71
|
+
db_names.map { |n| "echo '.dump' | #{ sqlitedump_utility } #{ db_path }#{ n }" }
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Returns the database path and adds a / at the end if not present
|
76
|
+
def db_path
|
77
|
+
if path.length >= 1 && path[-1, 1] != "/"
|
78
|
+
"#{path}/"
|
79
|
+
else
|
80
|
+
path
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Returns the database names to use in the SQLite dump command.
|
86
|
+
def db_names
|
87
|
+
if @all_dbs.nil?
|
88
|
+
@all_dbs = Dir.new(path).entries.select{|f| /.*.sqlite3$/.match(f)}
|
89
|
+
end
|
90
|
+
dump_all? ? @all_dbs : Array(name)
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Return true if we're dumping all databases.
|
95
|
+
# `name` will be set to :all if it is not set,
|
96
|
+
# so this will be true by default
|
97
|
+
def dump_all?
|
98
|
+
name == :all
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/backup/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
##
|
2
|
+
# SQLite [Database]
|
3
|
+
#
|
4
|
+
database SQLite do |db|
|
5
|
+
# To dump all databases, set `db.name = :all` (or leave blank)
|
6
|
+
db.name = "my_database_name"
|
7
|
+
db.path = "/path/to/my/sqlite/db"
|
8
|
+
|
9
|
+
# Optional: Use to set the location of this utility
|
10
|
+
# if it cannot be found by name in your $PATH
|
11
|
+
db.sqlitedump_utility = "/opt/local/bin/sqlite3"
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -593,6 +593,7 @@ files:
|
|
593
593
|
- lib/backup/database/postgresql.rb
|
594
594
|
- lib/backup/database/redis.rb
|
595
595
|
- lib/backup/database/riak.rb
|
596
|
+
- lib/backup/database/sqlite.rb
|
596
597
|
- lib/backup/encryptor/base.rb
|
597
598
|
- lib/backup/encryptor/gpg.rb
|
598
599
|
- lib/backup/encryptor/open_ssl.rb
|
@@ -654,6 +655,7 @@ files:
|
|
654
655
|
- templates/cli/databases/postgresql
|
655
656
|
- templates/cli/databases/redis
|
656
657
|
- templates/cli/databases/riak
|
658
|
+
- templates/cli/databases/sqlite
|
657
659
|
- templates/cli/encryptor/gpg
|
658
660
|
- templates/cli/encryptor/openssl
|
659
661
|
- templates/cli/model
|