+ <% copy_source = SiteConstruct.find(params[:copy_id]) rescue nil %>
+ <% if copy_source %>
+
<%= f.label :server_type ,"Server", :class => "control-label muted" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 04b4ae0..6af4856 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1,5 +1,6 @@
en:
client_management:
+ only_copy_installed_module: Only copy installed modules
copy_source: Copy Source
see_sites: See sites on the server
client_management: Client Management
diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml
index 338cd46..7ac4b6f 100644
--- a/config/locales/zh_tw.yml
+++ b/config/locales/zh_tw.yml
@@ -1,5 +1,6 @@
zh_tw:
client_management:
+ only_copy_installed_module: 只複製安裝的模組
copy_source: 複製來源
see_sites: 查看主機上的網站
client_management: 網站管理系統
diff --git a/lib/tasks/copy_site.rake b/lib/tasks/copy_site.rake
index e42de3e..5cd8011 100644
--- a/lib/tasks/copy_site.rake
+++ b/lib/tasks/copy_site.rake
@@ -2,7 +2,7 @@ require 'net/ssh'
require 'pathname'
namespace :create_site do
desc "Copy Site from another site"
- task :copy_site,[:ip,:user,:password,:site_name,:domain_name,:port,:db_name,:path,:site_construct_id,:template_site_construct_id] => :environment do |task,args|
+ task :copy_site,[:ip,:user,:password,:site_name,:domain_name,:port,:db_name,:path,:site_construct_id,:template_site_construct_id,:only_copy_installed_module] => :environment do |task,args|
@password = args.password
template_site = SiteConstruct.find(args.template_site_construct_id)
if args.site_construct_id.blank?
@@ -60,16 +60,20 @@ namespace :create_site do
update_infos("copying site's files for #{args.site_name}")
exec_ssh_command_for_create(ssh,"sudo -p 'sudo password:' apt-get install -y rsync")
+ extra_exclude_path = ""
+ if args.only_copy_installed_module == true || args.only_copy_installed_module == "true"
+ extra_exclude_path = ",public/uploads/"
+ end
if @site_construct.server_type == template_site.server_type
- exec_ssh_command_for_create(ssh,"rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*} #{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
+ exec_ssh_command_for_create(ssh,"rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*#{extra_exclude_path}} #{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
else
server = SiteServer.where(:server_name => template_site.server_type).first
exec_ssh_command_for_create(ssh,"sudo -p 'sudo password:' apt-get install -y sshpass")
- outputs = exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
+ outputs = exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*#{extra_exclude_path}} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
if outputs.join("\n").include?("Host key verification failed")
exec_ssh_command_by_sudo_for_create(ssh,"ssh-keygen -f \"$HOME/.ssh/known_hosts\" -R #{server.ip}")
exec_ssh_command_by_sudo_for_create(ssh,"ssh-keyscan -H #{server.ip} >> ~/.ssh/known_hosts")
- exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
+ exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete --exclude={tmp/cache/,tmp/unicorn.sock,tmp/pids/*#{extra_exclude_path}} #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/ #{args.path}/#{@site_construct.get_site_name}/",true)
end
end
update_infos("Finish copying site's files for #{args.site_name}!")
@@ -79,21 +83,21 @@ namespace :create_site do
db_setting_text = ssh.exec!("cat #{args.path}/#{args.site_name}/config/mongoid.yml")
update_infos("setting dbname to #{args.db_name}")
exec_ssh_command_by_sudo_for_create(ssh,"sh -c \"echo '#{db_setting_text.gsub(template_site.db_name,args.db_name)}' > #{args.path}/#{@site_construct.get_site_name}/config/mongoid.yml\"",true)
-
- update_infos("copying db from #{template_site.db_name} to #{args.db_name}")
- if @site_construct.server_type == template_site.server_type
- exec_ssh_command_by_sudo_for_create(ssh,"mongodump -d #{template_site.db_name} -o #{args.path}/#{@site_construct.get_site_name}/dump_xxxx")
- exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}")
- exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx")
- else
- exec_ssh_command_by_sudo_for_create(ssh,"sshpass -p '#{server.password}' ssh #{server.account}@#{server.ip} 'mongodump -d #{template_site.db_name} -o #{template_site.path}/#{template_site.site_name}/dump_xxxx'")
- exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/dump_xxxx/ #{args.path}/#{args.site_name}/dump_xxxx/")
- exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}")
- exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx")
- exec_ssh_command_by_sudo_for_create(ssh,"sshpass -p '#{server.password}' ssh #{server.account}@#{server.ip} 'rm -rf #{template_site.path}/#{template_site.get_site_name}/dump_xxxx'")
+ unless args.only_copy_installed_module == true || args.only_copy_installed_module == "true"
+ update_infos("copying db from #{template_site.db_name} to #{args.db_name}")
+ if @site_construct.server_type == template_site.server_type
+ exec_ssh_command_by_sudo_for_create(ssh,"mongodump -d #{template_site.db_name} -o #{args.path}/#{@site_construct.get_site_name}/dump_xxxx")
+ exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}")
+ exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx")
+ else
+ exec_ssh_command_by_sudo_for_create(ssh,"sshpass -p '#{server.password}' ssh #{server.account}@#{server.ip} 'mongodump -d #{template_site.db_name} -o #{template_site.path}/#{template_site.site_name}/dump_xxxx'")
+ exec_ssh_command_for_create(ssh,"sshpass -p \"#{server.password}\" rsync -arv --delete #{server.account}@#{server.ip}:#{template_site.path}/#{template_site.get_site_name}/dump_xxxx/ #{args.path}/#{args.site_name}/dump_xxxx/")
+ exec_ssh_command_by_sudo_for_create(ssh,"mongorestore --drop -d #{args.db_name} #{args.path}/#{@site_construct.get_site_name}/dump_xxxx/#{template_site.db_name}")
+ exec_ssh_command_by_sudo_for_create(ssh,"rm -rf #{args.path}/#{@site_construct.get_site_name}/dump_xxxx")
+ exec_ssh_command_by_sudo_for_create(ssh,"sshpass -p '#{server.password}' ssh #{server.account}@#{server.ip} 'rm -rf #{template_site.path}/#{template_site.get_site_name}/dump_xxxx'")
+ end
+ update_infos("Finish copying database!")
end
- update_infos("Finish copying database!")
-
update_infos("Checking extensions!")
extensions = ["downloaded_extensions.rb","built_in_extensions.rb"]
extensions.each do |extension_file|