Created
November 22, 2012 10:22
-
-
Save casparjones/4130424 to your computer and use it in GitHub Desktop.
svn-backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'xmlsimple' | |
require 'date' | |
require 'fileutils' | |
require "pp" | |
time = Time.new | |
CURRENTDIR=Dir.getwd | |
ownpid=$$ | |
TEMPDIR="/tmp/svnbackup.#{ownpid}" | |
ARCHIVENAME="" | |
Dir.mkdir(TEMPDIR) | |
svn_stat=%x{/usr/bin/svn stat --xml} | |
statxmldoc = XmlSimple.xml_in(svn_stat) | |
statfiles = statxmldoc['target'][0]['entry'] | |
statfiles.each { |file| | |
if file['path'] != '.' | |
next if file['wc-status'][0]['item'] == 'external' | |
pp file['path'] | |
%x{mkdir -p #{File.dirname("#{TEMPDIR}/#{file['path']}")}} | |
dest="#{TEMPDIR}/#{file['path']}" | |
if !File.directory?(file['path']) | |
FileUtils.copy(file['path'], dest) if !File.exists?(dest) | |
else | |
%x{rsync -rv --exclude=.svn #{file['path']} #{dest}} | |
end | |
end | |
} | |
Dir.chdir(TEMPDIR) | |
%x{tar cfvz #{CURRENTDIR}/SVNBACKUP_#{time.strftime("%Y%m%d-%H%M%S")}.tar.gz .} | |
Dir.chdir(CURRENTDIR) | |
%x{rm -rfv #{TEMPDIR}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment