Class: Backarch::Snapshot::Cassandra

Inherits:
Backarch::Snapshot show all
Defined in:
lib/backarch/snapshot/cassandra.rb

Instance Method Summary collapse

Methods inherited from Backarch::Snapshot

run, #snapshot_destination, #snapshot_name

Instance Method Details

#deleteObject



37
38
39
40
41
42
43
44
45
# File 'lib/backarch/snapshot/cassandra.rb', line 37

def delete
  LOG.info("Removing snapshot #{snapshot_name}")
  case Config.cassandra_version
  when /\A0\.6\./
    `find #{Config.input} -type d -wholename '*/snapshots/#{snapshot_name}' -exec rm -rf {} \\;`
  else
    `#{Config.nodetool} clearsnapshot -t #{snapshot_name}`
  end
end

#requestObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/backarch/snapshot/cassandra.rb', line 4

def request
  LOG.info "Requesting snapshot #{snapshot_name}"
  # Create a new snapshot in cassandra with the requested name
  case Config.cassandra_version
  when /\A0\.6\./
    `#{Config.nodetool} snapshot #{snapshot_name}`
    `find #{Config.input} -type f -wholename '*/backups/*' -exec rm {} \\; 2>/dev/null`
    ## Going to move the directory it created to what we expect it to be now.
    `for snapshot in \`find #{Config.input} -type d -wholename '*/snapshots/*-#{snapshot_name}'\`; do basedir=\`dirname $snapshot\`; rm -rfv $basedir/#{snapshot_name}; mv $snapshot $basedir/#{snapshot_name}; done`
  else
    `#{Config.nodetool} snapshot -t #{snapshot_name} 2>/dev/null`
    `find #{Config.input} -type f -wholename '*/backups/*' -exec rm {} \\;`
  end
end

#syncObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/backarch/snapshot/cassandra.rb', line 19

def sync
  $0 = "#{Config.program_name} snapshotter syncing #{snapshot_name}"
  LOG.info 'Ready to sync snapshot'
  snapshot_dirs = `find #{Config.input} -type d -wholename '*/snapshots/#{snapshot_name}'`.split(/\n/)
  snapshot_dirs.map do |dir|
    dest_dir = dir[%r{/data/(.+)/snapshots/}, 1]
    prior_dir = Config.link_prior
    link_prior = prior_dir ? "--link-dest=#{prior_dir}/#{dest_dir}" : ''
    command = "rsync -ar --stats #{link_prior} #{dir}/ #{snapshot_destination}/#{dest_dir}"
    LOG.debug command

    FileUtils.mkdir_p "#{snapshot_destination}/#{dest_dir}"
    FileUtils.chmod 0700, "#{snapshot_destination}/#{dest_dir}"
    FileUtils.chown  'root', 'root', "#{snapshot_destination}/#{dest_dir}"
    `#{command}`
  end
end