The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Making backups with RBackup

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Michael Neumann

Posts: 66
Nickname: backflash
Registered: May, 2003

Michael Neumann is fallen in Love with Ruby
Making backups with RBackup Posted: Aug 16, 2004 10:06 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Michael Neumann.
Original Post: Making backups with RBackup
Feed Title: Mike's Weblog
Feed URL: http://www.ntecs.de/blog-old/index.rss?cat=ruby&count=7
Feed Description: Blogging about Ruby and other interesting stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Michael Neumann
Latest Posts From Mike's Weblog

Advertisement
Today I wrote RBackup, my own backup program, of course in Ruby. I am now using it instead of Flexbackup, which is a very decent backup program written in Perl that I used before.

It creates CPIO archives (new portable format, w/o CRC), and compresses them on the fly if desired. Note that it's all pure Ruby, so that you don't have to install the cpio program.

You can download the sources here. Make sure that you get both files cpio.rb and rbackup.rb. Of course it comes without any warranties. USE AT YOUR OWN RISK!

Below is a short example how to use RBackup:

  require 'rbackup'
  require 'enumerator'
  require 'find'

  BACKUP_DIR = '/backup/%s'

  Collection.new('projects', BACKUP_DIR) {
    Find.to_enum(:find, '/data/projects').to_a
  }.backup_monthly

  Collection.new('maildirs-home', BACKUP_DIR) {
    files = []
    Dir.glob('/data/home/*/Maildir') do |md|
      Find.find(md) {|path|
        if File.directory?(path) && %w(.Spam .Trash).include?(File.basename(path))
          Find.prune # skip those directories
        else
          files << path
        end
      }
    end
    files
  }.backup_monthly

  Collection.new('rcs', BACKUP_DIR) {
    Dir['/**/RCS'].select {|path| File.directory?(path)}.
    collect {|path| Find.to_enum(:find, path).to_a}.flatten
  }.backup_weekly

  Collection.new('etc', BACKUP_DIR) {
    Find.to_enum(:find, '/etc').to_a +
    Find.to_enum(:find, '/usr/local/etc').to_a
  }.backup_weekly

Call this script daily (via crontab or /etc/periodic/daily) to create daily incremental backups. When backup_monthly is specified, it will create a full backup every first day of the month, or in the case of backup_weekly, every first day of the week.

Note that I'm using Find.find most of the time in the example above instead of Dir.glob, as the latter does not include dotfiles by default.

Why another backup program?

I wrote RBackup, as I wanted to be able to perform an arbitrary number of incremental backups. This wasn't possible with flexbackup or at least I didn't knew how. Furthermore, I wanted to be able to specify exactly which files to backup and which not. For this purpose, Ruby is very powerful.

Read: Making backups with RBackup

Topic: Rails attempts a ride to RubyConf Previous Topic   Next Topic Topic: Arrogance, ignorance, and a blinding Sun

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use