phusion-backup 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/phusion-backup CHANGED
@@ -63,7 +63,7 @@ class Core
63
63
  next if hostname =~ /^\./
64
64
  fullname = "#{dir}/#{hostname}"
65
65
  if File.directory?(fullname)
66
- results << Server.new(hostname, fullname)
66
+ results << Server.new(hostname, File.expand_path(fullname))
67
67
  end
68
68
  end
69
69
  end
@@ -71,7 +71,8 @@ class Core
71
71
  end
72
72
 
73
73
  def find_server(hostname_or_dir)
74
- return servers.find { |s| s.hostname == hostname_or_dir || s.dir == hostname_or_dir }
74
+ fulldir = File.expand_path(hostname_or_dir)
75
+ return servers.find { |s| s.hostname == hostname_or_dir || s.dir == fulldir }
75
76
  end
76
77
 
77
78
  def generate(dir)
@@ -94,15 +95,45 @@ class Core
94
95
  filename = create_globbing_filelist(server)
95
96
  begin
96
97
  sh!('rdiff-backup',
97
- '-v6',
98
+ '-v5',
99
+ '--print-statistics',
98
100
  '--exclude-sockets',
99
101
  '--include-globbing-filelist', filename,
100
102
  "root@#{server.hostname}::/",
101
103
  "#{server.dir}/data")
104
+ delete_old_backups(server)
102
105
  ensure
103
106
  File.unlink(filename)
104
107
  end
105
108
  end
109
+
110
+ def delete_old_backups(server)
111
+ return if !File.exist?(server.dir)
112
+ command = "rdiff-backup --list-increments --parsable-output \"#{server.dir}/data\""
113
+ increments = `#{command}`
114
+ if $?.exitstatus != 0
115
+ puts_error "The command `#{command}` failed."
116
+ raise CommandError
117
+ end
118
+
119
+ timestamps = []
120
+ increments.split("\n").each do |line|
121
+ if line =~ /^(\d+) directory$/
122
+ timestamps << $1.to_i
123
+ else
124
+ puts_error "The command `#{command}` returned an unrecognized output line: #{line.inspect}"
125
+ exit 1
126
+ end
127
+ end
128
+
129
+ if timestamps.size > 5
130
+ puts "<b>Deleting all but the most recent 5 backups...</b>"
131
+ timestamps.sort! { |a, b| b <=> a }
132
+ sh!("rdiff-backup", "--remove-older-than",
133
+ timestamps[4].to_s, "--force",
134
+ "#{server.dir}/data")
135
+ end
136
+ end
106
137
 
107
138
  private
108
139
  class CommandError < StandardError
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "phusion-backup"
3
- s.version = "1.0.0"
3
+ s.version = "1.0.1"
4
4
  s.authors = ["Hongli Lai"]
5
5
  s.date = "2011-03-30"
6
6
  s.description = "Simple backup tool utilizing rdiff-backup."
@@ -1,5 +1,6 @@
1
1
  # Standard, essential tools
2
2
  apt-get install bash-completion screen
3
+ apt-get install rdiff-backup python-pylibacl-dbg python-pyxattr-dbg
3
4
 
4
5
  # Compiler toolchain
5
6
  apt-get install build-essential gdb
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phusion-backup
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hongli Lai