diff --git a/README.markdown b/README.markdown index a68a389..5a08e02 100644 --- a/README.markdown +++ b/README.markdown @@ -36,6 +36,10 @@ Add to config/deploy.rb: # if you want to remove the dump file from the server after downloading set :db_remote_clean, true + # configure the local db filename + set :local_db_dir, "tmp" + set :prefix_db_with_stage, true #staging_appname_prod_20150501011.sql.bz2 + # If you want to import assets, you can change default asset dir (default = system) # This directory must be in your shared directory on the server set :assets_dir, %w(public/assets public/att) diff --git a/lib/capistrano-db-tasks/database.rb b/lib/capistrano-db-tasks/database.rb index 29f8b87..87c9468 100644 --- a/lib/capistrano-db-tasks/database.rb +++ b/lib/capistrano-db-tasks/database.rb @@ -41,20 +41,32 @@ def current_time end def output_file - @output_file ||= "db/#{database}_#{current_time}.sql.bz2" + @output_file ||= "#{local_db_dir}/#{prefix_db_with_stage}#{database}_#{current_time}.sql.bz2" end def pgpass "PGPASSWORD='#{@config['password']}'" if @config['password'] end + def local_db_dir + @local_db_dir ||= @cap.fetch(:local_db_dir) || "db" + end + + def prefix_db_with_stage + @db_prefix ||= @cap.fetch(:prefix_db_with_stage) ? "#{@cap.fetch(:stage)}_" : "" + end + + def dump_cmd_flags + @dump_cmd_flags ||= @cap.fetch(:dump_cmd_flags) || '' + end + private def dump_cmd if mysql? - "mysqldump #{credentials} #{database} --lock-tables=false" + "mysqldump #{dump_cmd_flags} #{credentials} #{database} --lock-tables=false" elsif postgresql? - "#{pgpass} pg_dump --no-acl --no-owner #{credentials} #{database}" + "#{pgpass} pg_dump #{dump_cmd_flags} --no-acl --no-owner #{credentials} #{database}" end end