git-confident 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ = git-confidence - Automate Configuration Backup to a Remote Git repository
2
+
3
+ * Keep a backup of single files scattered around your file system,
4
+ * Add those files to a Git repository
5
+ * When they change, they get backed up
6
+ * Restore your files
7
+
8
+ = Requirements
9
+
10
+ * A remote (preferably non-public) server to push your repository to.
11
+
12
+ = Multiple Branches for Computers with Similar Configurations
13
+
14
+ If you are backing up similar configurations from different computers,
15
+ you may want to keep several versions in branches.
16
+ If that is the case, just create the branch locally and check it out.
17
+
18
+ = Getting Started
19
+
20
+ == Create a Git Repository of The Files You Want Backed Up
21
+
22
+ * Create an empty Git repository:
23
+ $ mkdir ~/my_backup
24
+ $ git init
25
+ * Add some files, mimicking their full path:
26
+ $ mkdir -p etc
27
+ $ cp /etc/hosts etc/
28
+ $ git add etc/hosts
29
+ * Set up a git repository on your remote server:
30
+ $ mkdir -p ~/gitpath/my_backup
31
+ $ cd ~/gitpath/my_backup
32
+ $ git init --bare
33
+ * Add your remote server as 'origin':
34
+ $ git remote add origin ssh://my.remote.com/gitpath/my_backup
35
+ * Check commit and push work:
36
+ $ git commit -m "I'm starting by backing up my /etc/hosts"
37
+ $ git push
38
+
39
+ == Set Up a Cron Job
40
+
41
+ $ crontab -e
42
+ 13 23 * * * cd ~/my_backup && git-confidence
43
+
44
+ = Functions
45
+
46
+
47
+ = Alternatives
48
+
49
+ * rsync
50
+ * gitback[http://github.com/brycethornton/gitback] - very similar to this project, but sets up the repository from a config file.
51
+ * Desktop backup systems
52
+ * Time machine (on OS X)
53
+
54
+ = TODO
55
+
56
+ Restore:
57
+
58
+ if options[ :restore ]
59
+ `rsync -av --no-p --no-g --no-implied-dirs --files-from=- ./ /`
60
+ exit
61
+ end
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'rake'
3
+ require 'rake/gempackagetask'
4
+ require 'spec/rake/spectask'
5
+ require 'rake/rdoctask'
6
+ $:.unshift( File.dirname( __FILE__ ) + '/lib' )
7
+ require 'git/confident'
8
+
9
+ ADMIN_FILES = FileList[ 'Rakefile', 'README.rdoc' ]
10
+ SOURCE_FILES = FileList[ 'bin/*', 'lib/**/*.rb' ]
11
+ SPEC_FILES = FileList[ 'spec/**/*' ]
12
+ RDOC_FILES = FileList[ 'README.rdoc' ] + SOURCE_FILES
13
+ RDOC_OPTS = [ '--quiet', '--main', 'README.rdoc', '--inline-source' ]
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = 'git-confident'
17
+ s.summary = 'Automate computer configuration backup'
18
+ s.description = 'Provides git-confident'
19
+ s.version = Git::Confident::VERSION::STRING
20
+
21
+ s.homepage = 'http://github.com/joeyates/git-confident'
22
+ s.author = 'Joe Yates'
23
+ s.email = 'joe.g.yates@gmail.com'
24
+
25
+ s.files = ADMIN_FILES +
26
+ SOURCE_FILES
27
+ s.require_paths = [ 'lib' ]
28
+ s.add_dependency( 'rake', '>= 0.8.7' )
29
+ s.add_dependency( 'git', '>= 1.2.5' )
30
+
31
+ s.has_rdoc = true
32
+ s.rdoc_options += RDOC_OPTS
33
+ s.extra_rdoc_files = RDOC_FILES
34
+
35
+ s.test_files = SPEC_FILES
36
+ end
37
+
38
+ Rake::GemPackageTask.new( spec ) do |pkg|
39
+ end
40
+
41
+ Spec::Rake::SpecTask.new do |t|
42
+ t.spec_files = FileList[ 'spec/**/*_spec.rb' ]
43
+ t.spec_opts += [ '--color', '--format specdoc' ]
44
+ end
45
+
46
+ Spec::Rake::SpecTask.new( 'spec:rcov' ) do |t|
47
+ t.spec_files = FileList[ 'spec/**/*_spec.rb' ]
48
+ t.rcov = true
49
+ t.rcov_opts = [ '--exclude spec' ]
50
+ end
51
+
52
+ Rake::RDocTask.new do |rdoc|
53
+ rdoc.rdoc_dir = 'html'
54
+ rdoc.options += RDOC_OPTS
55
+ rdoc.title = 'Automate computer configuration backup'
56
+ rdoc.rdoc_files.add RDOC_FILES
57
+ end
data/bin/git-confident ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems' if RUBY_VERSION < '1.9'
4
+ require 'optparse'
5
+ ROOT_PATH = File.dirname( File.expand_path( File.dirname( __FILE__ ) ) )
6
+ LIB_PATH = File.join( ROOT_PATH, 'lib' )
7
+ $:.unshift( LIB_PATH )
8
+ require 'git/confident'
9
+
10
+ options = {
11
+ :restore => false,
12
+ :commit => true,
13
+ :path => File.expand_path( Dir::pwd ) # Default to current directory
14
+ }
15
+ options[ :path ] = '/Users/joe/setup/client'
16
+
17
+ OptionParser.new do | opts |
18
+ opts.banner = "Usage: $0 [options]"
19
+
20
+ opts.on("-C", "--no-commit", "Only copy files, do not do a git commit") do
21
+ options[:commit] = false
22
+ end
23
+
24
+ opts.on("-p", "--path PATH", "The path to the local copy of the repository. Defaults to current directory") do | path |
25
+ options[ :path ] = File.expand_path( path )
26
+ end
27
+
28
+ opts.on("-r", "--restore", "Restore system files from the repository") do
29
+ options[ :restore ] = true
30
+ end
31
+ end.parse!
32
+
33
+ conf = Git::Confident.new( options[ :path ] )
34
+ conf.local_backup
35
+ conf.commit
36
+ conf.push
@@ -0,0 +1,45 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'git'
3
+
4
+ module Git
5
+
6
+ class Confident < ::Git::Base
7
+
8
+ module VERSION #:nodoc:
9
+ MAJOR = 0
10
+ MINOR = 0
11
+ TINY = 1
12
+
13
+ STRING = [ MAJOR, MINOR, TINY ].join( '.' )
14
+ end
15
+
16
+ def initialize( path )
17
+ raise "Git repository not found at '#{ path }'" if ! File.directory?( "#{ path }/.git" )
18
+ @path = path.clone
19
+ super( { :working_directory => @path } )
20
+ end
21
+
22
+ def files
23
+ ls_files.keys.sort
24
+ end
25
+
26
+ def local_backup
27
+ IO.popen( "rsync -av --files-from=- / #{ @path }/", "w+" ) do | pipe |
28
+ files.each { | pathname | pipe.puts pathname }
29
+ end
30
+ end
31
+
32
+ def commit
33
+ needs_commit = status.changed.size > 0
34
+ return if ! needs_commit
35
+ add
36
+ super( "Automatic commit at #{ Time.now }" )
37
+ end
38
+
39
+ def push
40
+ super( 'origin', lib.branch_current )
41
+ end
42
+
43
+ end
44
+
45
+ end
data/spec/git_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'spec'
3
+ require 'git'
4
+
5
+ SPEC_PATH = File.expand_path( File.dirname( __FILE__ ) )
6
+ ROOT_PATH = File.dirname( SPEC_PATH )
7
+ require File.join( ROOT_PATH, 'lib', 'git', 'confident' )
8
+
9
+ describe 'when handling the repository' do
10
+
11
+ before( :each ) do
12
+ @repo_path = File.join( SPEC_PATH, 'repo' )
13
+ repo = Git::Base.init( @repo_path )
14
+ File.open( File.join( @repo_path, 'test_file' ), 'w' ) do | file |
15
+ file.write "Hello"
16
+ end
17
+ repo.add 'test_file'
18
+ end
19
+
20
+ after( :each ) do
21
+ `rm -rf '#{ @repo_path }'`
22
+ end
23
+
24
+ it 'lists files' do
25
+ conf = Git::Confident.new( @repo_path )
26
+ conf.files.should == [ 'test_file' ]
27
+ end
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-confident
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Joe Yates
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-02 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 49
30
+ segments:
31
+ - 0
32
+ - 8
33
+ - 7
34
+ version: 0.8.7
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: git
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 21
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 5
50
+ version: 1.2.5
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Provides git-confident
54
+ email: joe.g.yates@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - README.rdoc
61
+ - bin/git-confident
62
+ - lib/git/confident.rb
63
+ files:
64
+ - Rakefile
65
+ - README.rdoc
66
+ - bin/git-confident
67
+ - lib/git/confident.rb
68
+ - spec/git_spec.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/joeyates/git-confident
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --quiet
76
+ - --main
77
+ - README.rdoc
78
+ - --inline-source
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Automate computer configuration backup
106
+ test_files:
107
+ - spec/git_spec.rb