backuper 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
@@ -0,0 +1,43 @@
1
+ = About
2
+
3
+ Backuper is a simple server backup tool written in Ruby. It is aimed to backup a Rails application (file assets and database) to a remote SSH server (using rsync).
4
+
5
+ = Installation
6
+
7
+ sudo gem install backuper
8
+
9
+ = Configuration
10
+
11
+ Configure and run the backup :
12
+
13
+ Backuper.new do
14
+ set :source_path, '/var/apps/blop/current/shared/system'
15
+ set :local_backup_base_path, '/var/backups/blop'
16
+ set :remote_backup_ssh_info, 'username@host:/path/to/backups/blop'
17
+ set :max_kept_backups, 30
18
+ set :mysql_params, YAML::load(File.read('config/database.yml'))['production']
19
+ end
20
+
21
+ Put this in a script (e.g., *app/backup.rb*).
22
+
23
+ Don't forget to set up the public keys, it won't work with password authentication.
24
+
25
+ = Scheduling
26
+
27
+ Add a line to your crontab with *crontab -e* to run the script.
28
+
29
+ Or use whenever :
30
+
31
+ require 'backuper'
32
+
33
+ every 12.hours do
34
+ command "script"
35
+ end
36
+
37
+ = Credits
38
+
39
+ (c) 2009 Aurélien Malisart
40
+ http://aurelien.malisart.be
41
+
42
+ This is open source software released under GNU GPLv3 license.
43
+ http://www.gnu.org/copyleft/gpl.html
@@ -0,0 +1,2 @@
1
+ require 'rake'
2
+ require 'lib/backuper'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.1
@@ -0,0 +1,42 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{backuper}
8
+ s.version = File.read('VERSION')
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Aur\303\251lien Malisart"]
12
+ s.date = %q{2009-10-28}
13
+ s.description = %q{simple server backup tool}
14
+ s.email = %q{aurelien.malisart@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "backuper.gemspec",
24
+ "lib/backuper.rb"
25
+ ]
26
+ s.homepage = %q{http://github.com/aurels/backuper}
27
+ s.rdoc_options = ["--charset=UTF-8"]
28
+ s.require_paths = ["lib"]
29
+ s.rubygems_version = %q{1.3.5}
30
+ s.summary = %q{simple server backup tool}
31
+
32
+ if s.respond_to? :specification_version then
33
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
34
+ s.specification_version = 3
35
+
36
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
37
+ else
38
+ end
39
+ else
40
+ end
41
+ end
42
+
@@ -0,0 +1,78 @@
1
+ class Backuper
2
+
3
+ attr_accessor :source_path, :local_backup_base_path, :remote_backup_ssh_info,
4
+ :remote_backup_base_path, :max_kept_backups, :mysql_params
5
+
6
+ def initialize(&block)
7
+ instance_eval(&block)
8
+
9
+ mysql_params['host'] ||= 'localhost'
10
+ mysql_params['username'] ||= 'root'
11
+
12
+ system "mkdir -p #{local_backup_base_path}"
13
+
14
+ perform_files_backup
15
+ perform_database_backup
16
+ perform_remote_sync
17
+ end
18
+
19
+ def set(attribute, value)
20
+ instance_variable_set("@#{attribute}", value)
21
+ end
22
+
23
+ def perform_files_backup
24
+ timestamp = "#{Time.now.strftime('%Y-%-m-%d-%s')}"
25
+ local_current_backup_path = "#{local_backup_base_path}/files/#{timestamp}"
26
+ local_latest_backup_path = Dir["#{local_backup_base_path}/files/*"].last
27
+ system "mkdir -p #{local_current_backup_path}"
28
+
29
+ # Local backup
30
+
31
+ if File.exist?("#{local_latest_backup_path}")
32
+ puts "Performing local backup with hard links to pervious version"
33
+ system "rsync -az --delete --link-dest=#{local_latest_backup_path} #{source_path} #{local_current_backup_path}"
34
+ else
35
+ puts "Performing initial local backup"
36
+ system "rsync -az #{source_path} #{local_current_backup_path}"
37
+ end
38
+
39
+ # Cleanup of old versions
40
+
41
+ Dir["#{local_backup_base_path}/files/*"].reverse.each_with_index do |backup_version, index|
42
+ if index >= max_kept_backups
43
+ system "rm -rf #{backup_version}"
44
+ end
45
+ end
46
+ end
47
+
48
+ def perform_database_backup
49
+ return if mysql_params['database'] == '' || !(mysql_params['adapter'] =~ /mysql/)
50
+
51
+ timestamp = "#{Time.now.strftime('%Y-%-m-%d-%s')}"
52
+ local_current_backup_path = "#{local_backup_base_path}/mysql/#{timestamp}.sql"
53
+ local_latest_backup_path = Dir["#{local_backup_base_path}/mysql/*.sql"].last
54
+
55
+ unless File.exist?("#{local_backup_base_path}/mysql")
56
+ system "mkdir #{local_backup_base_path}/mysql"
57
+ end
58
+
59
+ # Local backup
60
+
61
+ puts "Performing local backup of database #{mysql_params['database']} as user #{mysql_params['username']}"
62
+ system "mysqldump #{mysql_params['database']} --user=#{mysql_params['username']} --password=#{mysql_params['password']} > #{local_current_backup_path}"
63
+
64
+ # Cleanup of old versions
65
+
66
+ Dir["#{local_backup_base_path}/mysql/*"].reverse.each_with_index do |backup_version, index|
67
+ if index >= max_kept_backups
68
+ system "rm -rf #{backup_version}"
69
+ end
70
+ end
71
+ end
72
+
73
+ def perform_remote_sync
74
+ puts "Performing remote backup sync"
75
+ system "rsync -azH --delete #{local_backup_base_path} #{remote_backup_ssh_info}"
76
+ puts "Done"
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backuper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 1
10
+ version: 2.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Aur\xC3\xA9lien Malisart"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2009-10-28 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: simple server backup tool
23
+ email: aurelien.malisart@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - .gitignore
32
+ - README.rdoc
33
+ - Rakefile
34
+ - VERSION
35
+ - backuper.gemspec
36
+ - lib/backuper.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/aurels/backuper
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.4.1
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: simple server backup tool
71
+ test_files: []
72
+