blavosync 0.0.1
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.
- data/Blavosync.gemspec +50 -0
- data/LICENSE +20 -0
- data/README.rdoc +94 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/init.rb +3 -0
- data/lib/blavosync.rb +0 -0
- data/pkg/blavosync-0.0.0.pre1.gem +0 -0
- data/pkg/blavosync-0.0.1.gem +0 -0
- data/recipes/content_rsync.rb +37 -0
- data/recipes/content_sync.rb +71 -0
- data/recipes/db_sync.rb +104 -0
- data/recipes/shared_sync.rb +96 -0
- metadata +68 -0
data/Blavosync.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{blavosync}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["jayronc"]
|
12
|
+
s.date = %q{2009-12-29}
|
13
|
+
s.description = %q{Sync a remote db and rsync content to your development environment. Useful for small teams and developers who are not able to do this manually.}
|
14
|
+
s.email = %q{jerrodblavos@mac.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Blavosync.gemspec",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/blavosync.rb",
|
27
|
+
"pkg/blavosync-0.0.0.pre1.gem",
|
28
|
+
"pkg/blavosync-0.0.1.gem",
|
29
|
+
"recipes/content_rsync.rb",
|
30
|
+
"recipes/content_sync.rb",
|
31
|
+
"recipes/db_sync.rb",
|
32
|
+
"recipes/shared_sync.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/jerrod/Blavosync}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["recipes"]
|
37
|
+
s.rubygems_version = %q{1.3.5}
|
38
|
+
s.summary = %q{Sync a remote db and rsync content to your development environment.}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 jayronc
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
= indierockmedia-blavosync
|
2
|
+
|
3
|
+
|
4
|
+
BLAVOSYNC
|
5
|
+
|
6
|
+
adds the following tasks to projects using capistrano
|
7
|
+
|
8
|
+
------------------------------------------------------------
|
9
|
+
cap local:backup_content
|
10
|
+
------------------------------------------------------------
|
11
|
+
Downloads a tarball of shared content (identified by the :shared_content and
|
12
|
+
:content_directories properties) from a deployable environment (RAILS_ENV) to
|
13
|
+
the local filesystem.
|
14
|
+
|
15
|
+
------------------------------------------------------------
|
16
|
+
cap local:backup_db
|
17
|
+
------------------------------------------------------------
|
18
|
+
Backs up deployable environment's database (idgit loentified by the
|
19
|
+
RAILS_ENV environment variable, which defaults to 'production') and copies it to
|
20
|
+
the local machine
|
21
|
+
|
22
|
+
------------------------------------------------------------
|
23
|
+
cap local:force_backup_content
|
24
|
+
------------------------------------------------------------
|
25
|
+
Regenerate files.
|
26
|
+
|
27
|
+
------------------------------------------------------------
|
28
|
+
cap local:force_backup_db
|
29
|
+
------------------------------------------------------------
|
30
|
+
Regenerate files.
|
31
|
+
|
32
|
+
------------------------------------------------------------
|
33
|
+
cap local:restore_content
|
34
|
+
------------------------------------------------------------
|
35
|
+
Restores the backed up content (env var FROM specifies which environment
|
36
|
+
was backed up, defaults to RAILS_ENV) to the local development environment app
|
37
|
+
|
38
|
+
------------------------------------------------------------
|
39
|
+
cap local:restore_db
|
40
|
+
------------------------------------------------------------
|
41
|
+
Untars the backup file downloaded from local:backup_db (specified via the FROM
|
42
|
+
env
|
43
|
+
variable, which defalts to RAILS_ENV), and imports (via mysql command line tool)
|
44
|
+
it back into the database
|
45
|
+
defined in the RESTORE_ENV env variable (defaults to development).
|
46
|
+
|
47
|
+
------------------------------------------------------------
|
48
|
+
cap local:resync_db
|
49
|
+
------------------------------------------------------------
|
50
|
+
Ensure that a fresh remote data dump is retrieved before syncing to the local
|
51
|
+
environment
|
52
|
+
|
53
|
+
------------------------------------------------------------
|
54
|
+
cap local:sync
|
55
|
+
------------------------------------------------------------
|
56
|
+
Wrapper for local:sync_db and local:sync_content
|
57
|
+
$> cap local:sync RAILS_ENV=production RESTORE_ENV=development
|
58
|
+
|
59
|
+
------------------------------------------------------------
|
60
|
+
cap local:sync_content
|
61
|
+
------------------------------------------------------------
|
62
|
+
Wrapper for local:backup_content and local:restore_content
|
63
|
+
$> cap local:sync_content RAILS_ENV=production RESTORE_ENV=development
|
64
|
+
|
65
|
+
------------------------------------------------------------
|
66
|
+
cap local:sync_db
|
67
|
+
------------------------------------------------------------
|
68
|
+
Wrapper for local:backup_db and local:restore_db.
|
69
|
+
$> cap local:sync_db RAILS_ENV=production RESTORE_ENV=development
|
70
|
+
|
71
|
+
------------------------------------------------------------
|
72
|
+
cap local:sync_init
|
73
|
+
------------------------------------------------------------
|
74
|
+
Wrapper for local:force_backup_db, local:force_backup_content, and the
|
75
|
+
local:sync to get
|
76
|
+
a completely fresh set of data from the server
|
77
|
+
$> cap local:sync RAILS_ENV=production RESTORE_ENV=development
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
== Note on Patches/Pull Requests
|
83
|
+
|
84
|
+
* Fork the project.
|
85
|
+
* Make your feature addition or bug fix.
|
86
|
+
* Add tests for it. This is important so I don't break it in a
|
87
|
+
future version unintentionally.
|
88
|
+
* Commit, do not mess with rakefile, version, or history.
|
89
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
90
|
+
* Send me a pull request. Bonus points for topic branches.
|
91
|
+
|
92
|
+
== Copyright
|
93
|
+
|
94
|
+
Copyright (c) 2009 jayronc. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "blavosync"
|
8
|
+
gem.summary = %Q{Sync a remote db and rsync content to your development environment.}
|
9
|
+
gem.description = %Q{Sync a remote db and rsync content to your development environment. Useful for small teams and developers who are not able to do this manually.}
|
10
|
+
gem.email = "jerrodblavos@mac.com"
|
11
|
+
gem.homepage = "http://github.com/jerrod/Blavosync"
|
12
|
+
gem.authors = ["jayronc"]
|
13
|
+
gem.has_rdoc = false
|
14
|
+
gem.require_path = 'recipes'
|
15
|
+
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test' << 'recipes'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test' << 'recipes'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "blavosync #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('recipes/**/*.rb')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/init.rb
ADDED
data/lib/blavosync.rb
ADDED
File without changes
|
Binary file
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
namespace :local do
|
2
|
+
|
3
|
+
desc <<-DESC
|
4
|
+
Rsyncs the your production content (identified by the :shared_content and
|
5
|
+
:content_directories properties) from a deployable environment (RAILS_ENV) to the local filesystem.
|
6
|
+
DESC
|
7
|
+
task :rsync_content do
|
8
|
+
from = ENV['FROM'] || 'production'
|
9
|
+
system("rsync -avz -e ssh '#{user}@#{domain}:#{content_path}' '#{rails_root}/tmp/'")
|
10
|
+
end
|
11
|
+
|
12
|
+
desc <<-DESC
|
13
|
+
Creates a symlink to public/system from tmp/system
|
14
|
+
DESC
|
15
|
+
task :rsync_restore_content do
|
16
|
+
# from = ENV['FROM'] || 'production'
|
17
|
+
print "\033[1;45m Linking Assets to public directory \033[0m\n"
|
18
|
+
system "ln -nfs #{rails_root}/tmp/system #{rails_root}/public/system"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
desc <<-DESC
|
23
|
+
Wrapper for local:rsync_content and local:rsync_restore_content
|
24
|
+
$> cap local:rsync RAILS_ENV=production
|
25
|
+
DESC
|
26
|
+
task :rsync do
|
27
|
+
transaction do
|
28
|
+
rsync_content
|
29
|
+
rsync_restore_content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def generate_remote_content_backup
|
36
|
+
run "cd #{shared_path} && tar czf #{rsync_content_backup_file} 'system'"
|
37
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
namespace :local do
|
2
|
+
|
3
|
+
desc <<-DESC
|
4
|
+
Downloads a tarball of shared content (identified by the :shared_content and
|
5
|
+
:content_directories properties) from a deployable environment (RAILS_ENV) to the local filesystem.
|
6
|
+
DESC
|
7
|
+
task :backup_content do
|
8
|
+
files = retrieve_local_files('production', 'content')
|
9
|
+
timestamp = most_recent_local_backup(from_env, 'content').to_i
|
10
|
+
last_modified = last_mod_time(content_backup_file).to_i
|
11
|
+
should_redownload = !(timestamp == last_modified)
|
12
|
+
if should_redownload
|
13
|
+
generate_remote_content_backup if last_modified < (Time.now.to_i - (remote_backup_expires))
|
14
|
+
system("mkdir -p #{tmp_dir}")
|
15
|
+
download(content_backup_file, "#{local_content_backup_dir(:env => from_env, :timestamp=>last_modified)}.tar.#{zip_ext}", :via=> :scp) do|ch, name, sent, total|
|
16
|
+
print "\r\033[1;42m #{File.basename(name)}: #{sent}/#{total} -- #{(sent.to_f * 100 / total.to_f).to_i}% \033[0m"
|
17
|
+
end
|
18
|
+
else
|
19
|
+
print "\r\033[1;42m Your Files are already up-to-date \033[0m\n"
|
20
|
+
@current_timestamp = files.first.to_i
|
21
|
+
end
|
22
|
+
util::tmp::check
|
23
|
+
end
|
24
|
+
|
25
|
+
desc <<-DESC
|
26
|
+
Regenerate files.
|
27
|
+
DESC
|
28
|
+
task :force_backup_content do
|
29
|
+
generate_remote_content_backup
|
30
|
+
end
|
31
|
+
|
32
|
+
desc <<-DESC
|
33
|
+
Restores the backed up content (env var FROM specifies which environment
|
34
|
+
was backed up, defaults to RAILS_ENV) to the local development environment app
|
35
|
+
DESC
|
36
|
+
task :restore_content do
|
37
|
+
timestamp = most_recent_local_backup(from_env, 'content')
|
38
|
+
local_dir = local_content_backup_dir(:env => from_env, :timestamp=>timestamp)
|
39
|
+
print "\033[1;45m Local Dir: #{local_dir} \033[0m\n"
|
40
|
+
system "mkdir -p #{local_dir}"
|
41
|
+
system "tar xzf #{local_dir}.tar.#{zip_ext} -C #{local_dir}"
|
42
|
+
print "\033[1;45m Removing old public/system directory \033[0m\n"
|
43
|
+
system "rm -rf public/system"
|
44
|
+
print "\033[1;45m Moving Assets to public directory \033[0m\n"
|
45
|
+
system "mv #{local_dir}/system public/system"
|
46
|
+
print "\033[1;41m Cleaning up \033[0m\n"
|
47
|
+
system "rm -rf #{local_dir}"
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
desc <<-DESC
|
52
|
+
Wrapper for local:backup_content and local:restore_content
|
53
|
+
$> cap local:sync_content RAILS_ENV=production RESTORE_ENV=development
|
54
|
+
DESC
|
55
|
+
task :sync_content do
|
56
|
+
transaction do
|
57
|
+
backup_content
|
58
|
+
restore_content
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def local_content_backup_dir(args={})
|
64
|
+
timestamp = args[:timestamp] || current_timestamp
|
65
|
+
"#{tmp_dir}/#{application}-#{from_env}-content-#{timestamp.to_s.strip}"
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def generate_remote_content_backup
|
70
|
+
run "cd #{shared_path} && tar czf #{tar_content_backup_file} 'system'"
|
71
|
+
end
|
data/recipes/db_sync.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
namespace :local do
|
2
|
+
desc <<-DESC
|
3
|
+
Backs up deployable environment's database (identified by the
|
4
|
+
RAILS_ENV environment variable, which defaults to 'production') and copies it to the local machine
|
5
|
+
DESC
|
6
|
+
task :backup_db, :roles => :db do
|
7
|
+
files = retrieve_local_files(from_env, 'db')
|
8
|
+
timestamp = most_recent_local_backup(from_env, 'db').to_i
|
9
|
+
last_modified = last_mod_time(db_backup_zip_file).to_i
|
10
|
+
|
11
|
+
if last_modified < (Time.now.to_i - (remote_backup_expires))
|
12
|
+
generate_remote_db_backup
|
13
|
+
should_redownload = true
|
14
|
+
end
|
15
|
+
should_redownload = !(timestamp == last_modified)
|
16
|
+
if should_redownload
|
17
|
+
system "mkdir -p #{tmp_dir}"
|
18
|
+
download(db_backup_zip_file, "#{local_db_backup_file(:env=>from_env, :timestamp=>last_modified)}.#{zip_ext}", :via=> :scp) do|ch, name, sent, total|
|
19
|
+
print "\r\033[1;42m #{File.basename(name)}: #{sent}/#{total} -- #{(sent.to_f * 100 / total.to_f).to_i}% \033[0m"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
print "\r\033[1;42m Your Files are already up-to-date \033[0m\n"
|
23
|
+
@current_timestamp = files.first.to_i
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc <<-DESC
|
28
|
+
Regenerate files.
|
29
|
+
DESC
|
30
|
+
task :force_backup_db do
|
31
|
+
generate_remote_db_backup
|
32
|
+
end
|
33
|
+
|
34
|
+
desc <<-DESC
|
35
|
+
Untars the backup file downloaded from local:backup_db (specified via the FROM env
|
36
|
+
variable, which defalts to RAILS_ENV), and imports (via mysql command line tool) it back into the database
|
37
|
+
defined in the RESTORE_ENV env variable (defaults to development).
|
38
|
+
DESC
|
39
|
+
task :restore_db, :roles => :db do
|
40
|
+
mysql_str = "mysql #{mysql_connection_for(to_env)}"
|
41
|
+
mysql_dump = "mysqldump #{mysql_connection_for(from_env)}"
|
42
|
+
local_db_create = "mysql #{mysql_connection_for(to_env)} -e \"create database if not exists #{mysql_db_for(to_env)}\""
|
43
|
+
remote_backup_file = local_db_backup_file(:env => from_env, :timestamp=>most_recent_local_backup(from_env, 'db')).strip
|
44
|
+
|
45
|
+
puts "\n\033[1;42m Restoring database backup to #{to_env} environment FROM #{remote_backup_file}--#{from_env} using #{mysql_str}\033[0m"
|
46
|
+
system(local_db_create.strip)
|
47
|
+
cmd = ""
|
48
|
+
cmd << <<-CMD
|
49
|
+
#{unzip} -c #{remote_backup_file}.#{zip_ext} > #{remote_backup_file} &&
|
50
|
+
#{mysql_str} < #{remote_backup_file} &&
|
51
|
+
rm -f #{remote_backup_file}
|
52
|
+
CMD
|
53
|
+
system(cmd.strip)
|
54
|
+
util::tmp::check
|
55
|
+
end
|
56
|
+
|
57
|
+
desc <<-DESC
|
58
|
+
Wrapper for local:backup_db and local:restore_db.
|
59
|
+
$> cap local:sync_db RAILS_ENV=production RESTORE_ENV=development
|
60
|
+
DESC
|
61
|
+
task :sync_db do
|
62
|
+
transaction do
|
63
|
+
backup_db
|
64
|
+
restore_db
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc <<-DESC
|
69
|
+
Ensure that a fresh remote data dump is retrieved before syncing to the local environment.
|
70
|
+
DESC
|
71
|
+
task :resync_db do
|
72
|
+
util::tmp::clean_remote
|
73
|
+
sync_db
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def generate_remote_db_backup
|
80
|
+
run "mysqldump #{mysql_connection_for(from_env)} > #{db_backup_file}"
|
81
|
+
run "rm -f #{db_backup_zip_file} && #{zip} #{db_backup_file} && rm -f #{db_backup_file}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def local_db_backup_file(args = {})
|
85
|
+
env = args[:env] || 'production'
|
86
|
+
timestamp = args[:timestamp] || current_timestamp
|
87
|
+
"#{tmp_dir}/#{application}-#{env}-db-#{timestamp.to_s.strip}.sql"
|
88
|
+
end
|
89
|
+
|
90
|
+
def mysql_connection_for(environment)
|
91
|
+
db_settings = YAML.load_file(local_db_conf(environment))[environment]
|
92
|
+
pass = pluck_pass_str(db_settings)
|
93
|
+
host = (db_settings['host'].nil?) ? nil : "--host=#{db_settings['host']}"
|
94
|
+
socket = (db_settings['socket'].nil?) ? nil : "--socket=#{db_settings['socket']}"
|
95
|
+
user = (db_settings['username'].nil?) ? nil : "-u #{db_settings['username']}"
|
96
|
+
database = (db_settings['database'].nil?) ? nil : " #{db_settings['database']}"
|
97
|
+
[user, pass, host, socket, database ].join(" ")
|
98
|
+
end
|
99
|
+
|
100
|
+
def mysql_db_for(environment)
|
101
|
+
restore_from = ENV['FROM'] || 'production'
|
102
|
+
@from_db ||= YAML.load_file(local_db_conf(restore_from))[restore_from]
|
103
|
+
@from_database ||= (@from_db['database'].nil?) ? nil : " #{@from_db['database']}"
|
104
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
set :rails_root, fetch(:blavosync_local_root, Pathname.new('.').realpath )
|
2
|
+
set :content_dir, fetch(:blavosync_content_directories, content_directories ||= "system" )
|
3
|
+
set :content_path, fetch(:blavosync_content_path, File.join(shared_path, content_dir) )
|
4
|
+
set :public_path, fetch(:blavosync_public_path, File.join(latest_release, 'public') )
|
5
|
+
set :remote_backup_expires, fetch(:blavosync_remote_backup_expires, 100000 )
|
6
|
+
set :zip, fetch(:blavosync_zip_command, "gzip" )
|
7
|
+
set :unzip, fetch(:blavosync_unzip_command, "gunzip" )
|
8
|
+
set :zip_ext, fetch(:blavosync_compressed_extension, "gz" )
|
9
|
+
set :tmp_dir, fetch(:blavosync_tmp_dir, "tmp" )
|
10
|
+
set :content_sync_method, fetch(:blavosync_content_sync_method, 'rsync' )
|
11
|
+
set :from_env, fetch(:blavosync_from_env, (ENV['FROM_ENV'].nil? ? 'production' : ENV['RAILS_ENV']) )
|
12
|
+
set :to_env, fetch(:blavosync_to_env, (ENV['TO_ENV'].nil? ? 'development' : ENV['TO_ENV']) )
|
13
|
+
set :rsync_content_backup_file, fetch(:blavosync_rsync_content_backup_file, "#{shared_path}/system" )
|
14
|
+
set :tar_content_backup_file, fetch(:blavosync_tar_content_backup_file, "#{shared_path}/backup_#{from_env}_content.tar.#{zip_ext}" )
|
15
|
+
set :db_backup_file, fetch(:blavosync_db_backup_file, "#{shared_path}/backup_#{from_env}_db.sql" )
|
16
|
+
set :db_backup_zip_file, fetch(:blavosync_db_backup_zip_file, "#{db_backup_file}.#{zip_ext}" )
|
17
|
+
|
18
|
+
|
19
|
+
def local_db_conf(env = nil)
|
20
|
+
env ||= fetch(:to_env)
|
21
|
+
fetch(:config_structure, :rails).to_sym == :sls ?
|
22
|
+
File.join('config', env.to_s, 'database.yml') :
|
23
|
+
File.join('config', 'database.yml')
|
24
|
+
end
|
25
|
+
|
26
|
+
def pluck_pass_str(db_config)
|
27
|
+
db_config['password'].nil? ? '' : "-p'#{db_config['password']}'"
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_timestamp
|
31
|
+
@current_timestamp ||= Time.now.to_i.to_s.strip
|
32
|
+
end
|
33
|
+
|
34
|
+
def retrieve_local_files(env, type)
|
35
|
+
`ls -r #{tmp_dir} | awk -F"-" '{ if ($2 ~ /#{env}/ && $3 ~ /#{type}/) { print $4; } }'`.split(' ')
|
36
|
+
end
|
37
|
+
|
38
|
+
def most_recent_local_backup(env, type)
|
39
|
+
retrieve_local_files(env, type).first.to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def last_mod_time(path)
|
43
|
+
capture("stat -c%Y #{path}")
|
44
|
+
end
|
45
|
+
|
46
|
+
def server_cache_valid?(path)
|
47
|
+
capture("[ -f #{path} ] || echo '1'").empty? && ((Time.now.to_i - last_mod_time(path)) <= remote_backup_expires)
|
48
|
+
end
|
49
|
+
|
50
|
+
namespace :util do
|
51
|
+
|
52
|
+
namespace :tmp do
|
53
|
+
desc "[capistrano-extensions]: Displays warning if :tmp_dir has more than 10 files or is greater than 50MB"
|
54
|
+
task :check do
|
55
|
+
#[ 5 -le "`ls -1 tmp/cap | wc -l`" ] && echo "Display Me"
|
56
|
+
cmd = %Q{ [ 10 -le "`ls -1 #{tmp_dir} | wc -l`" ] || [ 50 -le "`du -sh #{tmp_dir} | awk '{print int($1)}'`" ] && printf "\033[1;41m Clean up #{tmp_dir} directory \033[0m\n" && du -sh #{tmp_dir}/* }
|
57
|
+
system(cmd)
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "[capistrano-extensions]: Remove the current remote env's backups from :tmp_dir"
|
61
|
+
task :clean_remote do
|
62
|
+
system("rm -rf #{rails_root}/#{tmp_dir}/#{fetch(:application)}-*")
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
namespace :local do
|
69
|
+
desc <<-DESC
|
70
|
+
Wrapper for local:sync_db and local:sync_content
|
71
|
+
$> cap local:sync RAILS_ENV=production RESTORE_ENV=development
|
72
|
+
DESC
|
73
|
+
task :sync do
|
74
|
+
sync_db
|
75
|
+
if content_sync_method == 'tar'
|
76
|
+
sync_content
|
77
|
+
else
|
78
|
+
rsync_content
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc <<-DESC
|
83
|
+
Wrapper for local:force_backup_db, local:force_backup_content, and the local:sync to get
|
84
|
+
a completely fresh set of data from the server
|
85
|
+
$> cap local:sync RAILS_ENV=production RESTORE_ENV=development
|
86
|
+
DESC
|
87
|
+
task :sync_init do
|
88
|
+
force_backup_db
|
89
|
+
force_backup_content
|
90
|
+
sync
|
91
|
+
end
|
92
|
+
|
93
|
+
task :test_root do
|
94
|
+
puts "RAILS_ROOT #{rails_root}"
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blavosync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jayronc
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-29 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Sync a remote db and rsync content to your development environment. Useful for small teams and developers who are not able to do this manually.
|
17
|
+
email: jerrodblavos@mac.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- Blavosync.gemspec
|
27
|
+
- LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- init.rb
|
32
|
+
- lib/blavosync.rb
|
33
|
+
- pkg/blavosync-0.0.0.pre1.gem
|
34
|
+
- pkg/blavosync-0.0.1.gem
|
35
|
+
- recipes/content_rsync.rb
|
36
|
+
- recipes/content_sync.rb
|
37
|
+
- recipes/db_sync.rb
|
38
|
+
- recipes/shared_sync.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/jerrod/Blavosync
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- recipes
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Sync a remote db and rsync content to your development environment.
|
67
|
+
test_files: []
|
68
|
+
|