optimacms_backups 0.0.1 → 0.0.2
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/optimacms_backups/backup/config.rb +168 -0
- data/lib/optimacms_backups/backup/init.rb +78 -0
- data/lib/optimacms_backups/backup/models/app_files_backup.rb +81 -0
- data/lib/optimacms_backups/backup/models/db_backup.rb +62 -0
- data/lib/optimacms_backups/backup/models/user_files_backup.rb +79 -0
- data/lib/optimacms_backups/version.rb +1 -1
- data/lib/tasks/optimacms_backups/optimacms_backups.rake +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfaf348593d203a00a7c2cb7fd8972f31bb9e2f7
|
4
|
+
data.tar.gz: 957d51d343fabcaf07fcfe3f69d5c0caa2914973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbda4da685377bb0a0f31878a0a4e860c1f6523e36e4285fd150fd2fd5eb620c9799a1799b372cda8504a7893f54e690f87bbd5d9396fc095dd3c3bb9e978aec
|
7
|
+
data.tar.gz: afa11cd3f9b941531cf85cf087d35dad5d3bb826e5516e57e5a2346df977129c78e29ca0ad01ef67df97a690ec0b4e46f623956c72a7002d40bd150705797e30
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# Backup v4.x Configuration
|
5
|
+
#
|
6
|
+
# Documentation: http://backup.github.io/backup
|
7
|
+
# Issue Tracker: https://github.com/backup/backup/issues
|
8
|
+
|
9
|
+
##
|
10
|
+
|
11
|
+
require_relative 'init'
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
# Config Options
|
17
|
+
#
|
18
|
+
# The options here may be overridden on the command line, but the result
|
19
|
+
# will depend on the use of --root-path on the command line.
|
20
|
+
#
|
21
|
+
# If --root-path is used on the command line, then all paths set here
|
22
|
+
# will be overridden. If a path (like --tmp-path) is not given along with
|
23
|
+
# --root-path, that path will use it's default location _relative to --root-path_.
|
24
|
+
#
|
25
|
+
# If --root-path is not used on the command line, a path option (like --tmp-path)
|
26
|
+
# given on the command line will override the tmp_path set here, but all other
|
27
|
+
# paths set here will be used.
|
28
|
+
#
|
29
|
+
# Note that relative paths given on the command line without --root-path
|
30
|
+
# are relative to the current directory. The root_path set here only applies
|
31
|
+
# to relative paths set here.
|
32
|
+
#
|
33
|
+
# ---
|
34
|
+
#
|
35
|
+
# Sets the root path for all relative paths, including default paths.
|
36
|
+
# May be an absolute path, or relative to the current working directory.
|
37
|
+
#
|
38
|
+
#root_path '.'
|
39
|
+
|
40
|
+
#
|
41
|
+
# Sets the path where backups are processed until they're stored.
|
42
|
+
# This must have enough free space to hold apx. 2 backups.
|
43
|
+
# May be an absolute path, or relative to the current directory or +root_path+.
|
44
|
+
#
|
45
|
+
# tmp_path 'my/tmp'
|
46
|
+
#
|
47
|
+
# Sets the path where backup stores persistent information.
|
48
|
+
# When Backup's Cycler is used, small YAML files are stored here.
|
49
|
+
# May be an absolute path, or relative to the current directory or +root_path+.
|
50
|
+
#
|
51
|
+
# data_path 'my/data'
|
52
|
+
|
53
|
+
##
|
54
|
+
# Utilities
|
55
|
+
#
|
56
|
+
# If you need to use a utility other than the one Backup detects,
|
57
|
+
# or a utility can not be found in your $PATH.
|
58
|
+
#
|
59
|
+
# Utilities.configure do
|
60
|
+
# tar '/usr/bin/gnutar'
|
61
|
+
# redis_cli '/opt/redis/redis-cli'
|
62
|
+
# end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Logging
|
66
|
+
#
|
67
|
+
# Logging options may be set on the command line, but certain settings
|
68
|
+
# may only be configured here.
|
69
|
+
#
|
70
|
+
# Logger.configure do
|
71
|
+
# console.quiet = true # Same as command line: --quiet
|
72
|
+
# logfile.max_bytes = 2_000_000 # Default: 500_000
|
73
|
+
# syslog.enabled = true # Same as command line: --syslog
|
74
|
+
# syslog.ident = 'my_app_backup' # Default: 'backup'
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# Command line options will override those set here.
|
78
|
+
# For example, the following would override the example settings above
|
79
|
+
# to disable syslog and enable console output.
|
80
|
+
# backup perform --trigger my_backup --no-syslog --no-quiet
|
81
|
+
|
82
|
+
##
|
83
|
+
# Component Defaults
|
84
|
+
#
|
85
|
+
# Set default options to be applied to components in all models.
|
86
|
+
# Options set within a model will override those set here.
|
87
|
+
|
88
|
+
if $backup_config['s3']
|
89
|
+
s3_config = $backup_config['s3']
|
90
|
+
|
91
|
+
Storage::S3.defaults do |s3|
|
92
|
+
s3.access_key_id = s3_config['access_key_id']
|
93
|
+
s3.secret_access_key = s3_config['secret_access_key']
|
94
|
+
s3.region = s3_config['region']
|
95
|
+
s3.bucket = s3_config['bucket']
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
Notifier::Mail.defaults do |mail|
|
102
|
+
mail.on_success = true
|
103
|
+
mail.on_warning = true
|
104
|
+
mail.on_failure = true
|
105
|
+
|
106
|
+
# user
|
107
|
+
if $backup_config['notify'] && $backup_config['notify']['mail']
|
108
|
+
c = $backup_config['notify']['mail']
|
109
|
+
|
110
|
+
mail.from = c['from']
|
111
|
+
mail.to = c['to']
|
112
|
+
#mail.cc = "cc@email.com"
|
113
|
+
#mail.bcc = "bcc@email.com"
|
114
|
+
mail.reply_to = c['reply_to']
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
if $smtp_config
|
121
|
+
c = $smtp_config
|
122
|
+
|
123
|
+
# smtp
|
124
|
+
mail.address = c['address']
|
125
|
+
mail.port = c['port']
|
126
|
+
mail.domain = c['domain']
|
127
|
+
mail.user_name = c['user_name']
|
128
|
+
mail.password = c['password']
|
129
|
+
mail.authentication = c['authentication']
|
130
|
+
mail.encryption = c['encryption']
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
# mail.address = 'smtp.gmail.com'
|
135
|
+
# mail.port = 587
|
136
|
+
# mail.domain = 'your.host.name'
|
137
|
+
# mail.user_name = 'sender@email.com'
|
138
|
+
# mail.password = 'my_password'
|
139
|
+
# mail.authentication = 'plain'
|
140
|
+
# mail.encryption = :starttls
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Preconfigured Models
|
145
|
+
#
|
146
|
+
# Create custom models with preconfigured components.
|
147
|
+
# Components added within the model definition will
|
148
|
+
# +add to+ the preconfigured components.
|
149
|
+
#
|
150
|
+
# preconfigure 'MyModel' do
|
151
|
+
# archive :user_pictures do |archive|
|
152
|
+
# archive.add '~/pictures'
|
153
|
+
# end
|
154
|
+
#
|
155
|
+
# notify_by Mail do |mail|
|
156
|
+
# mail.to = 'admin@email.com'
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# MyModel.new(:john_smith, 'John Smith Backup') do
|
161
|
+
# archive :user_music do |archive|
|
162
|
+
# archive.add '~/music'
|
163
|
+
# end
|
164
|
+
#
|
165
|
+
# notify_by Mail do |mail|
|
166
|
+
# mail.to = 'john.smith@email.com'
|
167
|
+
# end
|
168
|
+
# end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
$app_env = ENV['RAILS_ENV'] || ENV['app_env'] || 'development'
|
2
|
+
$rails_app_env = $app_env
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
root = File.absolute_path(File.dirname(__FILE__))
|
7
|
+
current_dir = File.dirname(__FILE__)
|
8
|
+
|
9
|
+
#
|
10
|
+
#$backup_config = YAML.load_file(File.join(current_dir, 'config', "#{$app_env}.yml"))
|
11
|
+
#$backup_config = YAML.load_file(File.join(Rails.root, 'config', 'backup', "#{$app_env}.yml"))
|
12
|
+
$backup_config = YAML.load_file(File.join(current_dir, '../config/backup', "#{$app_env}.yml"))
|
13
|
+
#$backup_config = OptimacmsBackups.backups_config
|
14
|
+
|
15
|
+
#puts "backup_config: #{$backup_config}"
|
16
|
+
|
17
|
+
# config - app
|
18
|
+
app_path = File.expand_path("../../", __FILE__)+'/'
|
19
|
+
|
20
|
+
$app_config = {
|
21
|
+
path: app_path
|
22
|
+
}
|
23
|
+
|
24
|
+
#puts "app config: #{$app_config}"
|
25
|
+
|
26
|
+
#
|
27
|
+
app_rails_secrets = YAML.load_file("#{$app_config[:path]}config/secrets.yml")[$rails_app_env]
|
28
|
+
|
29
|
+
# db
|
30
|
+
$db_config = app_rails_secrets
|
31
|
+
|
32
|
+
#puts "db: #{$db_config}"
|
33
|
+
|
34
|
+
|
35
|
+
# smtp
|
36
|
+
$smtp_config = app_rails_secrets['smtp']
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
### helpers
|
42
|
+
|
43
|
+
def build_storage_local(local, options)
|
44
|
+
b = options
|
45
|
+
|
46
|
+
local.path = "#{b['path']}"
|
47
|
+
local.keep = 30
|
48
|
+
# local.keep = Time.now - 2592000 # Remove all backups older than 1 month.
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_storage_scp(server, opts)
|
52
|
+
b = opts
|
53
|
+
|
54
|
+
server.username = b['username']
|
55
|
+
server.password = b['password']
|
56
|
+
server.ip = b['ip']
|
57
|
+
server.port = b['port']
|
58
|
+
server.path = b['path']
|
59
|
+
|
60
|
+
# Use a number or a Time object to specify how many backups to keep.
|
61
|
+
server.keep = 30
|
62
|
+
|
63
|
+
# Additional options for the SSH connection.
|
64
|
+
# server.ssh_options = {}
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def build_storage_s3(s3, opts)
|
70
|
+
b = opts
|
71
|
+
|
72
|
+
s3_config = $backup_config['s3']
|
73
|
+
s3.access_key_id = b['access_key_id'] || s3_config['access_key_id']
|
74
|
+
s3.secret_access_key = b['secret_access_key'] || s3_config['secret_access_key']
|
75
|
+
s3.region = b['region'] || s3_config['region']
|
76
|
+
s3.bucket = b['bucket'] || s3_config['bucket']
|
77
|
+
s3.path = b['path'] || s3_config['path']
|
78
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
|
5
|
+
|
6
|
+
Model.new(:app_files_backup, 'App files') do
|
7
|
+
|
8
|
+
archive :files do |archive|
|
9
|
+
dir_app = $app_config[:path]
|
10
|
+
|
11
|
+
|
12
|
+
#archive.add "/path/to/a/file.rb"
|
13
|
+
archive.add "#{dir_app}"
|
14
|
+
|
15
|
+
in_dirs = ($backup_config['backup']['app_files']['include'] rescue []) || []
|
16
|
+
|
17
|
+
ignore_dirs = %w[.idea .git .vagrant .ansible .chef backup]
|
18
|
+
ex_dirs_base = %w[tmp log public/assets public/images public/uploads ]
|
19
|
+
ex_dirs = ($backup_config['backup']['app_files']['exclude'] rescue []) || []
|
20
|
+
|
21
|
+
(in_dirs).each do |d|
|
22
|
+
archive.add "#{dir_app}#{d}"
|
23
|
+
end
|
24
|
+
|
25
|
+
(ex_dirs_base+ignore_dirs+ex_dirs).each do |d|
|
26
|
+
archive.exclude "#{dir_app}#{d}"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
#### Storages
|
38
|
+
|
39
|
+
|
40
|
+
$backup_config['storages'].each do |b|
|
41
|
+
if b['type']=='scp'
|
42
|
+
store_with SCP do |server|
|
43
|
+
build_storage_scp(server, b)
|
44
|
+
end
|
45
|
+
|
46
|
+
elsif b['type']=='s3'
|
47
|
+
##
|
48
|
+
# Store on Amazon S3
|
49
|
+
#
|
50
|
+
store_with S3 do |s3|
|
51
|
+
build_storage_s3(s3, b)
|
52
|
+
end
|
53
|
+
|
54
|
+
elsif b['type']=='local'
|
55
|
+
##
|
56
|
+
# Local (Copy)
|
57
|
+
#
|
58
|
+
store_with Local do |local|
|
59
|
+
build_storage_local(local, b)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
##
|
67
|
+
# Gzip [Compressor]
|
68
|
+
#
|
69
|
+
compress_with Gzip
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
### notify
|
74
|
+
|
75
|
+
notify_by Mail do |mail|
|
76
|
+
c = $smtp_config
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
|
5
|
+
|
6
|
+
Model.new(:db_backup, 'Backup DB of Rails app') do
|
7
|
+
database MySQL, :gex do |db|
|
8
|
+
db.name = $db_config['db']
|
9
|
+
db.host = $db_config['db_host']
|
10
|
+
db.username = $db_config['db_user']
|
11
|
+
db.password = $db_config['db_password']
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#### Storages
|
20
|
+
|
21
|
+
$backup_config['storages'].each do |b|
|
22
|
+
if b['type']=='scp'
|
23
|
+
store_with SCP do |server|
|
24
|
+
build_storage_scp(server, b)
|
25
|
+
end
|
26
|
+
|
27
|
+
elsif b['type']=='s3'
|
28
|
+
##
|
29
|
+
# Store on Amazon S3
|
30
|
+
#
|
31
|
+
store_with S3 do |s3|
|
32
|
+
build_storage_s3(s3, b)
|
33
|
+
end
|
34
|
+
|
35
|
+
elsif b['type']=='local'
|
36
|
+
##
|
37
|
+
# Local (Copy)
|
38
|
+
#
|
39
|
+
store_with Local do |local|
|
40
|
+
build_storage_local(local, b)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
##
|
48
|
+
# Gzip [Compressor]
|
49
|
+
#
|
50
|
+
compress_with Gzip
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
### notify
|
55
|
+
|
56
|
+
notify_by Mail do |mail|
|
57
|
+
c = $smtp_config
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
|
5
|
+
|
6
|
+
Model.new(:user_files_backup, 'App files') do
|
7
|
+
|
8
|
+
archive :files do |archive|
|
9
|
+
dir_app = $app_config[:path]
|
10
|
+
|
11
|
+
|
12
|
+
archive.add "#{dir_app}"
|
13
|
+
|
14
|
+
ignore_dirs = %w[.idea .git .vagrant .ansible .chef]
|
15
|
+
ex_dirs_base = %w[tmp log ]
|
16
|
+
in_dirs = ($backup_config['backup']['user_files']['include'] rescue []) || []
|
17
|
+
ex_dirs = ($backup_config['backup']['user_files']['exclude'] rescue []) || []
|
18
|
+
|
19
|
+
(in_dirs).each do |d|
|
20
|
+
archive.add "#{dir_app}#{d}"
|
21
|
+
end
|
22
|
+
|
23
|
+
(ignore_dirs+ex_dirs_base+ex_dirs).each do |d|
|
24
|
+
archive.exclude "#{dir_app}#{d}"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
#### Storages
|
34
|
+
|
35
|
+
#setup_storages
|
36
|
+
|
37
|
+
|
38
|
+
$backup_config['storages'].each do |b|
|
39
|
+
if b['type']=='scp'
|
40
|
+
store_with SCP do |server|
|
41
|
+
build_storage_scp(server, b)
|
42
|
+
end
|
43
|
+
|
44
|
+
elsif b['type']=='s3'
|
45
|
+
##
|
46
|
+
# Store on Amazon S3
|
47
|
+
#
|
48
|
+
store_with S3 do |s3|
|
49
|
+
build_storage_s3(s3, b)
|
50
|
+
end
|
51
|
+
|
52
|
+
elsif b['type']=='local'
|
53
|
+
##
|
54
|
+
# Local (Copy)
|
55
|
+
#
|
56
|
+
store_with Local do |local|
|
57
|
+
build_storage_local(local, b)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
##
|
65
|
+
# Gzip [Compressor]
|
66
|
+
#
|
67
|
+
compress_with Gzip
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
### notify
|
72
|
+
|
73
|
+
notify_by Mail do |mail|
|
74
|
+
c = $smtp_config
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -20,7 +20,7 @@ namespace :optimacms_backups do
|
|
20
20
|
]
|
21
21
|
|
22
22
|
files.each do |f|
|
23
|
-
source = File.join(Gem.loaded_specs["optimacms_backups"].full_gem_path, "backup", f)
|
23
|
+
source = File.join(Gem.loaded_specs["optimacms_backups"].full_gem_path, "lib/optimacms_backups/backup", f)
|
24
24
|
target = File.join(Rails.root, "backup", f)
|
25
25
|
|
26
26
|
FileUtils.cp_r source, target
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimacms_backups
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Ivak
|
@@ -59,6 +59,11 @@ files:
|
|
59
59
|
- config/routes.rb
|
60
60
|
- lib/optimacms/admin_menu/admin_menu.rb
|
61
61
|
- lib/optimacms_backups.rb
|
62
|
+
- lib/optimacms_backups/backup/config.rb
|
63
|
+
- lib/optimacms_backups/backup/init.rb
|
64
|
+
- lib/optimacms_backups/backup/models/app_files_backup.rb
|
65
|
+
- lib/optimacms_backups/backup/models/db_backup.rb
|
66
|
+
- lib/optimacms_backups/backup/models/user_files_backup.rb
|
62
67
|
- lib/optimacms_backups/engine.rb
|
63
68
|
- lib/optimacms_backups/version.rb
|
64
69
|
- lib/tasks/optimacms_backups/optimacms_backups.rake
|