Sha256: a1b6cc1cf6b5de99bb35ebcc414e8bf13f622a2f0e5c27ae30df49561fef72c4

Contents?: true

Size: 1.77 KB

Versions: 18

Compression:

Stored size: 1.77 KB

Contents

namespace :backup do
  desc 'Restore data from git repo, last backup by default'
  task :restore, :tag do |task, args|
    on roles(:app) do
      within release_path do
        with rails_env: fetch(:stage) do
          execute :rake, "backup:restore #{args[:tag]}"
        end
      end
    end
  end
end

desc 'Backup data to a git repo, tagging it into the git repo'
task :backup, :tag do |task, args|
  on roles(:app) do
    within release_path do
      with rails_env: "production" do
        execute :rake, "backup #{args[:tag]}"
      end
    end
  end
end

namespace :pull do
  desc 'Pull data (db/files) from remote (i.e: production) application.'
  task :data do
    invoke "pull:files"
    invoke "pull:db"
  end

  desc 'Pull db: Hot backup, download and restore of the stage database'
  task :db do
    on roles(:app) do
      within release_path do
        with rails_env: fetch(:stage) do
          execute :rake, 'db:backup'
          execute "mv #{release_path}/tmp/db.sql /tmp/db.sql"
          download! '/tmp/db.sql', 'tmp/db.sql'
        end
        run_locally do
          begin # Don't raise error if rails version < 5
            execute 'rails db:environment:set RAILS_ENV=development'
          rescue;end
          rake 'db:restore'
        end
      end
    end
  end

  desc 'Pull files uploaded'
  task :files do
    on roles(:app) do |host|
      run_locally do
        debug ":   Pulling Files from #{fetch(:stage)} ..."
        if fetch(:backup_dirs).any?
          fetch(:backup_dirs).each do |dir|
            execute "rm -r #{dir}"
            execute "scp -r -P #{host.port} #{host.user}@#{host.hostname}:#{current_path}/#{dir} #{dir}"
          end
        else
          error ":    Set key :backup_dirs to know which ones to pull"
        end

      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
prun-ops-0.3.4 lib/capistrano/backup.rake
prun-ops-0.3.3 lib/capistrano/backup.rake
prun-ops-0.3.2 lib/capistrano/backup.rake
prun-ops-0.3.1 lib/capistrano/backup.rake
prun-ops-0.3.0 lib/capistrano/backup.rake
prun-ops-0.2.18 lib/capistrano/backup.rake
prun-ops-0.2.17 lib/capistrano/backup.rake
prun-ops-0.2.16 lib/capistrano/backup.rake
prun-ops-0.2.15 lib/capistrano/backup.rake
prun-ops-0.2.14 lib/capistrano/backup.rake
prun-ops-0.2.13 lib/capistrano/backup.rake
prun-ops-0.2.12 lib/capistrano/backup.rake
prun-ops-0.2.11 lib/capistrano/backup.rake
prun-ops-0.2.10 lib/capistrano/backup.rake
prun-ops-0.2.9 lib/capistrano/backup.rake
prun-ops-0.2.8 lib/capistrano/backup.rake
prun-ops-0.2.7 lib/capistrano/backup.rake
prun-ops-0.2.6 lib/capistrano/backup.rake