capistrano-db-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 +11 -0
- data/Gemfile +6 -0
- data/README.md +9 -0
- data/capistrano-db-sync.gemspec +20 -0
- data/lib/capistrano-db-sync.rb +0 -0
- data/lib/capistrano/db-sync.rb +0 -0
- data/lib/capistrano/tasks/db.rake +57 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3db5aa95ae5ba2321304c947c208f0a9a32c8cf1
|
4
|
+
data.tar.gz: 512955cd7ea984d1b08bca9b29ae5fea61d5fae5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df7522ed52be6bc89d7623b9d70fa5eed8392ba3a0f0d3b189b8baecf4a3161b5a9eb254909f63ed2bd59dcf3530e99a7bb041b1f800b192fc7c055c4c6615a6
|
7
|
+
data.tar.gz: ed4eefff382ff5c36c8d633d34347113f3e203ae2b79495de8bab99b87b0ad9597462e981ba2837ee64d16308614f3fffe7a25c6ea9c1e273b40de0a008e08ee
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'capistrano-db-sync'
|
6
|
+
spec.version = '0.0.1'
|
7
|
+
spec.date = Date.today.to_s
|
8
|
+
spec.summary = "Capistrano synchronization databases task"
|
9
|
+
spec.description = "Capistrano synchronization task for syncing databases between the local development environment and different multi_stage environments"
|
10
|
+
spec.authors = ["Albuisson Stéphane"]
|
11
|
+
spec.email = 'stephane.albuisson@gmail.com'
|
12
|
+
spec.files = `git ls-files`.split("\n")
|
13
|
+
spec.homepage = 'http://www.stephane-albuisson.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency 'capistrano', '~> 3.1'
|
20
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../models/database')
|
2
|
+
|
3
|
+
namespace :db do
|
4
|
+
|
5
|
+
namespace :sync do
|
6
|
+
|
7
|
+
task :local_to_remote do
|
8
|
+
|
9
|
+
on roles(:all) do
|
10
|
+
# Backup de la base donnée distante
|
11
|
+
|
12
|
+
# Création du répertoire de synchronisation
|
13
|
+
execute :mkdir, "-p #{shared_path}/sync"
|
14
|
+
|
15
|
+
# Création du fichier SQL de la base de données locale
|
16
|
+
filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H-%M-%S'}.sql"
|
17
|
+
username, password, database, host = database_config('development')
|
18
|
+
system "mysqldump -u #{username} --password=#{password} #{database} > #{filename}"
|
19
|
+
|
20
|
+
# Export du fichier SQL
|
21
|
+
upload! filename, "#{shared_path}/sync/#{filename}"
|
22
|
+
system "rm -f #{filename}"
|
23
|
+
|
24
|
+
# Import de la base de données
|
25
|
+
username, password, database, host = remote_database_config(:stage)
|
26
|
+
hostcmd = host.nil? ? '' : "-h #{host}"
|
27
|
+
execute :mysql, "-u #{username} --password=#{password} #{database} #{hostcmd} < #{shared_path}/sync/#{filename}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def database_config(db)
|
37
|
+
database = YAML::load_file('config/database.yml')
|
38
|
+
return database["#{db}"]['user'], database["#{db}"]['password'], database["#{db}"]['dbname'], database["#{db}"]['host']
|
39
|
+
end
|
40
|
+
|
41
|
+
def remote_database_config(db)
|
42
|
+
remote_config = capture("cat #{shared_path}/config/database.yml")
|
43
|
+
database = YAML::load(remote_config)
|
44
|
+
return database["#{db}"]['user'], database["#{db}"]['password'], database["#{db}"]['dbname'], database["#{db}"]['host']
|
45
|
+
end
|
46
|
+
|
47
|
+
def purge_old_backups(base)
|
48
|
+
count = fetch(:sync_backups, 5).to_i
|
49
|
+
backup_files = capture("ls -xt #{shared_path}/sync/#{base}*").split.reverse
|
50
|
+
if count >= backup_files.length
|
51
|
+
logger.important "no old backups to clean up"
|
52
|
+
else
|
53
|
+
logger.info "keeping #{count} of #{backup_files.length} sync backups"
|
54
|
+
delete_backups = (backup_files - backup_files.last(count)).join(" ")
|
55
|
+
try_sudo "rm -rf #{delete_backups}"
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-db-sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Albuisson Stéphane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
description: Capistrano synchronization task for syncing databases between the local
|
28
|
+
development environment and different multi_stage environments
|
29
|
+
email: stephane.albuisson@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- capistrano-db-sync.gemspec
|
38
|
+
- lib/capistrano-db-sync.rb
|
39
|
+
- lib/capistrano/db-sync.rb
|
40
|
+
- lib/capistrano/tasks/db.rake
|
41
|
+
homepage: http://www.stephane-albuisson.com
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.6.13
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Capistrano synchronization databases task
|
65
|
+
test_files: []
|