Permalink
Browse files

made filesystem operations on local work in Windows

  • Loading branch information...
1 parent 6ea7d14 commit 09270ba3fcd9327ea3d439a4239ffe242a45a1f5 @akloboucnik akloboucnik committed with Apr 14, 2011
Showing with 43 additions and 17 deletions.
  1. +43 −17 lib/symfony1.rb
View
@@ -419,7 +419,7 @@ def load_database_config(data, env)
namespace :dump do
desc "Dump remote database"
task :remote do
- filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.bz2"
+ filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.gz"
file = "/tmp/#{filename}"
sqlfile = "#{application}_dump.sql"
config = ""
@@ -430,70 +430,96 @@ def load_database_config(data, env)
case config['type']
when 'mysql'
- run "mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}" do |ch, stream, data|
+ run "mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | gzip -c > #{file}" do |ch, stream, data|
puts data
end
when 'pgsql'
- run "pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}" do |ch, stream, data|
+ run "pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | gzip -c > #{file}" do |ch, stream, data|
puts data
end
end
- `mkdir -p backups`
+ require "FileUtils"
+ FileUtils.mkdir_p("backups")
get file, "backups/#{filename}"
- `cd backups && ln -nfs #{filename} #{application}.remote_dump.latest.sql.bz2`
+ begin
+ FileUtils.ln_sf(filename, "backups/#{application}.remote_dump.latest.sql.gz")
+ rescue NotImplementedError # hack for windows which doesnt support symlinks
+ FileUtils.cp_r("backups/#{filename}", "backups/#{application}.remote_dump.latest.sql.gz")
+ end
run "rm #{file}"
end
desc "Dump local database"
task :local do
- filename = "#{application}.local_dump.#{Time.now.to_i}.sql.bz2"
+ filename = "#{application}.local_dump.#{Time.now.to_i}.sql.gz"
+ tmpfile = "backups/#{application}_dump_tmp.sql"
file = "backups/#{filename}"
config = load_database_config IO.read('config/databases.yml'), symfony_env_local
sqlfile = "#{application}_dump.sql"
- `mkdir -p backups`
+ require "FileUtils"
+ FileUtils::mkdir_p("backups")
case config['type']
when 'mysql'
- `mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
+ `mysqldump -u#{config['user']} --password=\"#{config['pass']}\" #{config['db']} > #{tmpfile}`
when 'pgsql'
- `pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
+ `pg_dump -U #{config['user']} --password=\"#{config['pass']}\" #{config['db']} > #{tmpfile}`
+ end
+ File.open(tmpfile, "r+") do |f|
+ gz = Zlib::GzipWriter.open(file)
+ while (line = f.gets)
+ gz << line
+ end
+ gz.flush
+ gz.close
end
- `cd backups && ln -nfs #{filename} #{application}.local_dump.latest.sql.bz2`
+ begin
+ FileUtils.ln_sf(filename, "backups/#{application}.local_dump.latest.sql.gz")
+ rescue NotImplementedError # hack for windows which doesnt support symlinks
+ FileUtils.cp_r("backups/#{filename}", "backups/#{application}.local_dump.latest.sql.gz")
+ end
+ FileUtils.rm(tmpfile)
end
end
namespace :move do
desc "Dump remote database, download it to local & populate here"
task :to_local do
- filename = "#{application}.remote_dump.latest.sql.bz2"
+ filename = "#{application}.remote_dump.latest.sql.gz"
config = load_database_config IO.read('config/databases.yml'), symfony_env_local
sqlfile = "#{application}_dump.sql"
database.dump.remote
- `bunzip2 -kc backups/#{filename} > backups/#{sqlfile}`
+ require "FileUtils"
+ f = File.new("backups/#{sqlfile}", "a+")
+ require "zlib"
+ gz = Zlib::GzipReader.new(File.open("backups/#{filename}", "r"))
+ f << gz.read
+ f.close
+
case config['type']
when 'mysql'
- `mysql -u#{config['user']} --password='#{config['pass']}' #{config['db']} < backups/#{sqlfile}`
+ `mysql -u#{config['user']} --password=\"#{config['pass']}\" #{config['db']} < backups/#{sqlfile}`
when 'pgsql'
- `psql -U #{config['user']} --password='#{config['pass']}' #{config['db']} < backups/#{sqlfile}`
+ `psql -U #{config['user']} --password=\"#{config['pass']}\" #{config['db']} < backups/#{sqlfile}`
end
- `rm backups/#{sqlfile}`
+ FileUtils.rm("backups/#{sqlfile}")
end
desc "Dump local database, load it to remote & populate there"
task :to_remote do
- filename = "#{application}.local_dump.latest.sql.bz2"
+ filename = "#{application}.local_dump.latest.sql.gz"
file = "backups/#{filename}"
sqlfile = "#{application}_dump.sql"
config = ""
database.dump.local
upload(file, "/tmp/#{filename}", :via => :scp)
- run "bunzip2 -kc /tmp/#{filename} > /tmp/#{sqlfile}"
+ run "gunzip -c /tmp/#{filename} > /tmp/#{sqlfile}"
run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
config = load_database_config data, symfony_env_prod

0 comments on commit 09270ba

Please sign in to comment.