Sha256: 0cce0427af739abfbb5188839b5da35bdf2f5b0652f08ee298a40fa869c187e4

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Container
  module Backup
    class Volumes < Directories
      #       - "backup={volumes: [influxdb_data],databases: [influxdb: {user: ${INFLUXDB_ADMIN_USER},password: ${INFLUXDB_ADMIN_PASSWORD}}]}"
      def remove_container
        puts "Remove container #{container} (y/n)?"
        if gets.chomp == 'y'
          sh "docker rm -f #{container}"
        else
          exit
        end
      end

      def volume
        @params
      end

      def remove_volume
        puts "Remove volume #{volume} (y/n)?"
        if gets.chomp == 'y'
          sh "docker volume rm #{volume}"
        else
          exit
        end
      end

      def create_volume
        sh "docker volume create #{volume}"
      end

      # https://blog.ssdnodes.com/blog/docker-backup-volumes/

      def tar_volume(option)
        raise "Invalid tar option #{option}" unless option =~ /\A[cx]\z/
        sh "docker run --rm -v #{volume}:/temp -v #{backup_path}:/backup ubuntu bash -c \"cd /temp && tar #{option}vf /backup/#{volume}.tar #{option == 'c' ? ' .' : ''}\""
      end

      def restore
        stop
        remove_container
        remove_volume
        recover_volume
        start
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
container-backup-0.1.0 lib/container/steps/volumes.rb