mina-data_sync 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/backup-2015-03-30.sql +2845 -0
- data/backup-2015-03-30.tar +0 -0
- data/backup.tar +0 -0
- data/config/database.yml +39 -0
- data/config/deploy.rb +125 -0
- data/lib/mina/data_sync/defaults.rb +4 -0
- data/lib/mina/data_sync/helpers.rb +70 -0
- data/lib/mina/data_sync/tasks.rb +39 -0
- data/lib/mina/data_sync/version.rb +5 -0
- data/lib/mina/data_sync.rb +12 -0
- data/mina-data_sync.gemspec +26 -0
- metadata +116 -0
Binary file
|
data/backup.tar
ADDED
Binary file
|
data/config/database.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: utf8
|
4
|
+
pool: 5
|
5
|
+
username: postgres
|
6
|
+
password:
|
7
|
+
host: localhost
|
8
|
+
|
9
|
+
rakovac: &rakovac
|
10
|
+
<<: *default
|
11
|
+
username: <%= ENV['PGSQL_USER'] %>
|
12
|
+
password: <%= ENV['PGSQL_PASSWORD'] %>
|
13
|
+
host: <%= ENV['PGSQL_HOST'] %>
|
14
|
+
port: <%= ENV['PGSQL_PORT'] %>
|
15
|
+
|
16
|
+
# development:
|
17
|
+
# adapter: mysql2
|
18
|
+
# encoding: utf8
|
19
|
+
# database: miramo_club_development
|
20
|
+
# pool: 5
|
21
|
+
# username: root
|
22
|
+
# password:
|
23
|
+
# host: localhost
|
24
|
+
|
25
|
+
development: &development
|
26
|
+
<<: *default
|
27
|
+
database: miramo_club_development
|
28
|
+
|
29
|
+
test:
|
30
|
+
<<: *default
|
31
|
+
database: miramo_club_test
|
32
|
+
|
33
|
+
production: &production
|
34
|
+
<<: *rakovac
|
35
|
+
database: miramo_infinum_co
|
36
|
+
|
37
|
+
staging:
|
38
|
+
<<: *rakovac
|
39
|
+
database: miramo_staging_infinum_co
|
data/config/deploy.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
lib = File.expand_path('../../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'mina/bundler'
|
5
|
+
require 'mina/rails'
|
6
|
+
require 'mina/git'
|
7
|
+
require 'pry'
|
8
|
+
require 'mina/data_sync'
|
9
|
+
# require 'mina/whenever' # uncomment if using whenever
|
10
|
+
|
11
|
+
# Setup project
|
12
|
+
# - mina production setup
|
13
|
+
# Deploy project
|
14
|
+
# - mina production deploy
|
15
|
+
# Tail log from project
|
16
|
+
# - mina prodution log
|
17
|
+
# Pull data from production
|
18
|
+
# - mina production data:pull
|
19
|
+
|
20
|
+
set :repository, 'git@bitbucket.org:infinum_hr/web_miramoclub.git'
|
21
|
+
set :backup_path, '/Users/stef/dev/databases/pg'
|
22
|
+
set :port, 22220
|
23
|
+
set :user, 'staging'
|
24
|
+
set :domain, 'miramo.infinum.co'
|
25
|
+
|
26
|
+
task :production do
|
27
|
+
set :deploy_to, '/home/staging/www/m/miramo.infinum.co'
|
28
|
+
set :rails_env, 'production'
|
29
|
+
set :branch, 'master'
|
30
|
+
set :bundle_withouts, 'development:test:staging'
|
31
|
+
end
|
32
|
+
|
33
|
+
# If you have
|
34
|
+
task :staging do
|
35
|
+
set :domain, 'miramo.infinum.co'
|
36
|
+
set :deploy_to, '/home/staging/www/m/miramo.infinum.co'
|
37
|
+
set :rails_env, 'staging'
|
38
|
+
set :branch, 'develop'
|
39
|
+
set :bundle_withouts, 'development:test:production'
|
40
|
+
end
|
41
|
+
|
42
|
+
task :development do
|
43
|
+
set :rails_env, 'development'
|
44
|
+
end
|
45
|
+
##################################################################################
|
46
|
+
########################## DO NOT EDIT THE CODE BELOW ############################
|
47
|
+
##################################################################################
|
48
|
+
|
49
|
+
# While linking asssets it will only precompile that assets that was changed, not all of them
|
50
|
+
set :shared_paths, ['log']
|
51
|
+
|
52
|
+
task :deploy => :stages do
|
53
|
+
deploy do
|
54
|
+
invoke :'git:clone'
|
55
|
+
invoke :'deploy:link_shared_paths'
|
56
|
+
invoke :'bundle:install'
|
57
|
+
invoke :'rails:db_migrate'
|
58
|
+
invoke :'rails:assets_precompile'
|
59
|
+
invoke :'deploy:cleanup'
|
60
|
+
|
61
|
+
to :launch do
|
62
|
+
# Capistrano to Mina Fix, symlink system to shared
|
63
|
+
queue! %[echo "-----> Symlink system to shared"]
|
64
|
+
queue! %[ln -nFs #{deploy_to}/shared/system #{deploy_to}/#{current_path}/public/system]
|
65
|
+
|
66
|
+
#invoke :'whenever:update' # uncomment if using whenever (why here? read https://gist.github.com/gabskoro/abfc245a55a9d155f8de)
|
67
|
+
invoke :restart_application
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# First ensure that the stage is selected
|
73
|
+
task :stages do
|
74
|
+
unless domain
|
75
|
+
print_error "A server needs to be specified. e.g. production/staging"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Just overwrote to execute stages first
|
81
|
+
task :setup => :stages do
|
82
|
+
queue! %[mkdir -p "#{deploy_to}/shared/log"]
|
83
|
+
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
|
84
|
+
end
|
85
|
+
|
86
|
+
# Tail log from server
|
87
|
+
task :log => :stages do
|
88
|
+
queue "tail -f #{deploy_to}/#{current_path}/log/#{rails_env}.log"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Restart application after deployment
|
92
|
+
task :restart_application do
|
93
|
+
queue %[echo "-----> Restarting application"]
|
94
|
+
queue "mkdir -p #{deploy_to}/#{current_path}/tmp"
|
95
|
+
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
|
96
|
+
end
|
97
|
+
|
98
|
+
namespace :data do
|
99
|
+
set :pretty_print, true
|
100
|
+
set :db_path, '/Users/stef/dev/databases'
|
101
|
+
|
102
|
+
# # Sync database
|
103
|
+
# RYAML = <<-BASH
|
104
|
+
# function ryaml {
|
105
|
+
# ruby -ryaml -e 'puts ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@"
|
106
|
+
# };
|
107
|
+
# BASH
|
108
|
+
|
109
|
+
task :pull => :stages do
|
110
|
+
queue RYAML
|
111
|
+
queue! "HOST=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} host)"
|
112
|
+
queue! "DATABASE=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} database)"
|
113
|
+
queue! "USERNAME=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} username)"
|
114
|
+
queue! "PASSWORD=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} password)"
|
115
|
+
queue! "mysqldump $DATABASE --host=$HOST --user=$USERNAME --password=$PASSWORD > #{deploy_to}/dump.sql"
|
116
|
+
queue! "gzip -f #{deploy_to}/dump.sql"
|
117
|
+
|
118
|
+
to :after_hook do
|
119
|
+
queue! "scp -P #{port} #{user}@#{domain}:#{deploy_to}/dump.sql.gz ."
|
120
|
+
queue! "gunzip -f dump.sql.gz"
|
121
|
+
queue! "#{RYAML} mysql --verbose --user=$(ryaml config/database.yml development username) --password=$(ryaml config/database.yml development password) $(ryaml config/database.yml development database) < dump.sql"
|
122
|
+
queue! "rm dump.sql"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
DC = <<-RUBY
|
2
|
+
dc = YAML.load(ERB.new(File.read(ARGV[0])).result)[ARGV[1]]
|
3
|
+
adapter = dc["adapter"]
|
4
|
+
database = dc["database"]
|
5
|
+
host = dc["host"]
|
6
|
+
username = dc["username"]
|
7
|
+
password = dc["password"]
|
8
|
+
port = dc["port"]
|
9
|
+
arguments = ""
|
10
|
+
case adapter.to_s
|
11
|
+
when "postgresql"
|
12
|
+
arguments += " -d " + database if database
|
13
|
+
arguments += " -h " + host if host
|
14
|
+
arguments += " -U " + username if username
|
15
|
+
arguments += " -p " + port.to_s if port
|
16
|
+
puts arguments
|
17
|
+
end
|
18
|
+
RUBY
|
19
|
+
|
20
|
+
DATABASE_CONF = <<-BASH
|
21
|
+
function database_conf {
|
22
|
+
ruby -ryaml -rerb -e '#{DC}' "$@"
|
23
|
+
};
|
24
|
+
BASH
|
25
|
+
|
26
|
+
# module Mina
|
27
|
+
# module DataSync
|
28
|
+
# class Base
|
29
|
+
# def initialize(database_path, rails_env, deploy_to, tar)
|
30
|
+
# @database_conf = YAML.load(ERB.new(File.read(database_path)).result)[rails_env]
|
31
|
+
# @tar = tar
|
32
|
+
# @deploy_to = deploy_to
|
33
|
+
# end
|
34
|
+
|
35
|
+
# def database
|
36
|
+
# @database_conf['database']
|
37
|
+
# end
|
38
|
+
|
39
|
+
# def host
|
40
|
+
# @database_conf['host']
|
41
|
+
# end
|
42
|
+
|
43
|
+
# def username
|
44
|
+
# @database_conf['username']
|
45
|
+
# end
|
46
|
+
|
47
|
+
# def port
|
48
|
+
# @database_conf['port']
|
49
|
+
# end
|
50
|
+
|
51
|
+
# def file_sql
|
52
|
+
# @file_sql ||= "backup-#{Date.today}.sql"
|
53
|
+
# end
|
54
|
+
|
55
|
+
# def file_tar
|
56
|
+
# @file_tar ||= "backup-#{Date.today}.tar"
|
57
|
+
# end
|
58
|
+
|
59
|
+
# def file
|
60
|
+
# @tar ? file_tar : file_sql
|
61
|
+
# end
|
62
|
+
|
63
|
+
# def options
|
64
|
+
# options = "-O -a"
|
65
|
+
# options += ' -Ft' if @tar
|
66
|
+
# options
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
# end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
namespace :data_sync do
|
2
|
+
set :term_mode, :pretty
|
3
|
+
|
4
|
+
desc "pull"
|
5
|
+
task :pg_pull => :environment do
|
6
|
+
queue "echo '-----> Dumping database'"
|
7
|
+
queue "#{DATABASE_CONF}"
|
8
|
+
queue "cd #{deploy_to}/#{current_path}"
|
9
|
+
queue "ARGS=$(database_conf #{database_path} #{rails_env})"
|
10
|
+
queue! "pg_dump $ARGS #{pg_options} --clean > #{backup_file}"
|
11
|
+
|
12
|
+
to :after_hook do
|
13
|
+
queue "echo '-----> Copying backup'"
|
14
|
+
queue "#{DATABASE_CONF}"
|
15
|
+
queue "ARGS=$(database_conf #{database_path} development)"
|
16
|
+
queue! "scp -P #{port} #{user}@#{domain}:#{deploy_to}/#{current_path}/#{backup_file} #{backup_path}/#{backup_file}"
|
17
|
+
queue "echo '-----> Restoring database'"
|
18
|
+
queue! "pg_restore $ARGS #{pg_options} --clean #{backup_path}/#{backup_file}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "push"
|
23
|
+
task :pg_push => :environment do
|
24
|
+
to :before_hook do
|
25
|
+
queue "#{DATABASE_CONF}"
|
26
|
+
queue "echo '-----> Dumping database'"
|
27
|
+
queue "ARGS=$(database_conf #{database_path} development)"
|
28
|
+
queue! "pg_dump $ARGS #{pg_options} --clean > #{backup_file}"
|
29
|
+
queue "echo '-----> Copying backup'"
|
30
|
+
queue! "scp -P #{port} #{backup_file} #{user}@#{domain}:#{deploy_to}/#{current_path}/#{backup_file}"
|
31
|
+
end
|
32
|
+
|
33
|
+
queue "echo '-----> Restoring database'"
|
34
|
+
queue "#{DATABASE_CONF}"
|
35
|
+
queue "cd #{deploy_to}/#{current_path}"
|
36
|
+
queue "ARGS=$(database_conf #{database_path} #{rails_env})"
|
37
|
+
queue! "pg_restore $ARGS #{pg_options} --clean #{backup_file}"
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mina/data_sync/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mina-data_sync"
|
8
|
+
spec.version = Mina::DataSync::VERSION
|
9
|
+
spec.authors = ["Stjepan Hadjic"]
|
10
|
+
spec.email = ["d4be4st@gmail.com"]
|
11
|
+
spec.summary = "Summary"
|
12
|
+
spec.description = "Description"
|
13
|
+
spec.homepage = "https://github.com/d4be4st/mina-data_sync"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "pry", "~> 0"
|
24
|
+
|
25
|
+
spec.add_dependency 'mina', '~> 0'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mina-data_sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stjepan Hadjic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mina
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Description
|
70
|
+
email:
|
71
|
+
- d4be4st@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- backup-2015-03-30.sql
|
82
|
+
- backup-2015-03-30.tar
|
83
|
+
- backup.tar
|
84
|
+
- config/database.yml
|
85
|
+
- config/deploy.rb
|
86
|
+
- lib/mina/data_sync.rb
|
87
|
+
- lib/mina/data_sync/defaults.rb
|
88
|
+
- lib/mina/data_sync/helpers.rb
|
89
|
+
- lib/mina/data_sync/tasks.rb
|
90
|
+
- lib/mina/data_sync/version.rb
|
91
|
+
- mina-data_sync.gemspec
|
92
|
+
homepage: https://github.com/d4be4st/mina-data_sync
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Summary
|
116
|
+
test_files: []
|