#!/usr/bin/ruby # Dumps the Subversion repositories of applications on Rails Machine. # This script is intended to be called by cron on your Rails Machine. # # Andrew Stewart, AirBlade Software Ltd (boss at airbladesoftware dot com) # Feedback gratefully received. # # Version 0.1 require 'rubygems' require 'logger' require 'yaml' # Configure the script here. You won't need to change anything # unless you have modified your Rails Machine setup. APPS_PATH = '/var/www/apps' # Path to all your apps EXCLUSIONS = %w( rails mephisto ) # Any directories or apps to exclude BACKUP_PATH = '/backup/storage' # Where to store the backups TIMESTAMP = '%Y%m%d%H%M%S' # Timestamp for databases' backup files LOG_FILE = '/home/deploy/svn_dump.log' # Where to log activity # The body of the script follows. log = Logger.new(LOG_FILE, 5, 10*1024) log.level = Logger::DEBUG log.info 'Starting subversion dumps' Dir["#{APPS_PATH}/*"].each do |entry| app = File.basename entry app_backup_path = "#{BACKUP_PATH}/#{app}" next if File.file?(entry) || EXCLUSIONS.include?(app) Dir.mkdir app_backup_path unless File.exist? app_backup_path repos = "#{entry}/repos" dump = "#{app_backup_path}/svn-repos-#{Time.now.strftime(TIMESTAMP)}.gz" dump_cmd = "svnadmin dump #{repos} | gzip - > #{dump}" log.debug "Executing: #{dump_cmd}" `#{dump_cmd}` log.info "Dumped #{repos} to #{dump}" end log.info 'Finished subversion dumps'