Skip to content

Loading…

Riak Backup Support #236

Merged
merged 3 commits into from

3 participants

@josephcrim

Hey Guys,

Added Riak database backup support with specs. Tested this out and it works fine.

Let me know if you guys have questions.

Thanks,

Joe

Joe Crim added some commits
@meskyanichi
Backup member

Nice work @josephcrim! I've never used Riak myself before, but will gladly merge this in. Cheers

@meskyanichi meskyanichi merged commit 99d9f1e into backup:develop
@meskyanichi
Backup member

@josephcrim oh and would you mind adding Riak to the databases list in the wiki?

https://github.com/meskyanichi/backup/wiki/Databases

@josephcrim

@meskyanichi added to the wiki

@meskyanichi
Backup member

Thanks!

@phene

riak-admin backup is currently deprecated and slow as mud. The only "good" way of to backup riak is to snapshot it's file tree (ring files, bitcast data, and search index).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 29, 2011
  1. Initial riak backup support.

    Joe Crim committed
  2. Adding in rspec test for Riak backups

    Joe Crim committed
  3. Backup path has to be owned by riak for riak-admin to write to it. Ma…

    Joe Crim committed
    …ke sure you use --tmp-path to allow riak-admin to work right.
View
4 lib/backup.rb
@@ -32,7 +32,7 @@ module Backup
# database "MySQL" do |mysql|
# You can do:
# database MySQL do |mysql|
- DATABASES = ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis']
+ DATABASES = ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Riak']
STORAGES = ['S3', 'CloudFiles', 'Ninefold', 'Dropbox', 'FTP', 'SFTP', 'SCP', 'RSync', 'Local']
COMPRESSORS = ['Gzip', 'Bzip2', 'Lzma']
ENCRYPTORS = ['OpenSSL', 'GPG']
@@ -114,6 +114,7 @@ module Database
autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
autoload :Redis, File.join(DATABASE_PATH, 'redis')
+ autoload :Riak, File.join(DATABASE_PATH, 'riak')
end
##
@@ -199,6 +200,7 @@ module Database
autoload :PostgreSQL, File.join(CONFIGURATION_PATH, 'database', 'postgresql')
autoload :MongoDB, File.join(CONFIGURATION_PATH, 'database', 'mongodb')
autoload :Redis, File.join(CONFIGURATION_PATH, 'database', 'redis')
+ autoload :Riak, File.join(CONFIGURATION_PATH, 'database', 'riak')
end
end
View
25 lib/backup/configuration/database/riak.rb
@@ -0,0 +1,25 @@
+# encoding: utf-8
+
+module Backup
+ module Configuration
+ module Database
+ class Riak < Base
+ class << self
+
+ ##
+ # Name is the name of the backup
+ attr_accessor :name
+
+ ##
+ # Node is the node from which to perform the backup.
+ attr_accessor :node
+
+ ##
+ # Cookie is the Erlang cookie/shared secret used to connect to the node.
+ attr_accessor :cookie
+
+ end
+ end
+ end
+ end
+end
View
45 lib/backup/database/riak.rb
@@ -0,0 +1,45 @@
+# encoding: utf-8
+
+module Backup
+ module Database
+ class Riak < Base
+
+ ##
+ # Name is the name of the backup
+ attr_accessor :name
+
+ ##
+ # Node is the node from which to perform the backup.
+ attr_accessor :node
+
+ ##
+ # Cookie is the Erlang cookie/shared secret used to connect to the node.
+ attr_accessor :cookie
+
+ ##
+ # Creates a new instance of the Riak adapter object
+ def initialize(&block)
+ load_defaults!
+
+ instance_eval(&block)
+ end
+
+ ##
+ # Builds the full riak-admin string based on all attributes
+ def riakadmin
+ "riak-admin backup #{node} #{cookie}"
+ end
+
+ ##
+ # Performs the riak-admin command and outputs the
+ # data to the specified path based on the 'trigger'
+ def perform!
+ super
+ # have to make riak the owner since the riak-admin tool runs as the riak user in a default setup.
+ run("chown -R riak.riak #{dump_path}")
+ run("#{riakadmin} #{File.join(dump_path, name)} node")
+ end
+
+ end
+ end
+end
View
8 lib/templates/database/riak
@@ -0,0 +1,8 @@
+##
+# Riak [Database]
+#
+database Riak do |db|
+ db.name = "hostname"
+ db.node = "riak@hostname"
+ db.cookie = "cookie"
+end
View
49 spec/database/riak_spec.rb
@@ -0,0 +1,49 @@
+# encoding: utf-8
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe Backup::Database::Riak do
+
+ before do
+ Backup::Database::Riak.any_instance.stubs(:load_defaults!)
+ end
+
+ let(:db) do
+ Backup::Database::Riak.new do |db|
+ db.name = 'mydatabase'
+ db.node = 'riak@localhost'
+ db.cookie = 'riak'
+ end
+ end
+
+ describe '#new' do
+ it 'should read the adapter details correctly' do
+ db.name.should == 'mydatabase'
+ db.node.should == 'riak@localhost'
+ db.cookie.should == 'riak'
+ end
+ end
+
+ describe '#riakadmin_string' do
+ it 'should return the full riakadmin string' do
+ db.riakadmin.should == "riak-admin backup riak@localhost riak"
+ end
+ end
+
+ describe '#perform!' do
+ before do
+ db.stubs(:mkdir)
+ db.stubs(:run)
+ end
+
+ it 'should ensure the directory is available' do
+ db.expects(:mkdir).with(File.join(Backup::TMP_PATH, "myapp", "Riak"))
+ db.perform!
+ end
+
+ it do
+ Backup::Logger.expects(:message).with("Backup::Database::Riak started dumping and archiving \"mydatabase\".")
+ db.perform!
+ end
+ end
+end
Something went wrong with that request. Please try again.