bup 0.3.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +1 -1
- data/README.md +8 -1
- data/buprc +1 -0
- data/exe/bup +15 -3
- data/lib/bup/tar.rb +62 -29
- data/lib/bup/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 817a27933493ae6ac118d4c6d9def7851bd44151f4bfd8b5ec1293cd485351e8
|
4
|
+
data.tar.gz: b49c3a4cd1dec954a400bee0d9aa7ac5259b19e9bfadc26baa3a479a73d4af89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '014508ef6bbc01de2eebf734b96173ac0a8c3891ae85ccfd5fd985ed03a3553344331e938bc079777e8ae492155c61abc1f56de6dd0bf8bd6c0212a599579fd7'
|
7
|
+
data.tar.gz: e62b3723768c1f6d948f627c437a175be706344eabaa0ec1bbf4a07116bdae1ad4667a11d279c850d937ab7bdabe7295bcbb537a0f0eaff5fc7e84aaf9b9b348
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.7.0] - 2021-11-29
|
4
|
+
|
5
|
+
- BUG FIX: Create destination was not being expanded.
|
6
|
+
|
7
|
+
## [0.6.0] - 2021-11-29
|
8
|
+
|
9
|
+
- Add pre_cmds list to allow executing command before backup, such as dumping a database.
|
10
|
+
- Add BUP_DESTINATION that holds the backup destination directory.
|
11
|
+
This may be used to put dumped database files in before a backup and clean
|
12
|
+
them up with a post_cmd.
|
13
|
+
- Refactor the tar.rb file for more simple individual function calls
|
14
|
+
and to do a little less redundant processing.
|
15
|
+
- Replaced --type=[full|incremental] with --incremental and --full options.
|
16
|
+
|
17
|
+
## [0.5.0] - 2021-11-13
|
18
|
+
|
19
|
+
- Allow for a history size of 0.
|
20
|
+
- Add default_profile setting.
|
21
|
+
|
22
|
+
## [0.4.0] - 2021-11-13
|
23
|
+
|
24
|
+
- Bug fix for empty post_cmds list.
|
25
|
+
|
26
|
+
## [0.3.0] - 2021-11-13
|
27
|
+
|
3
28
|
- Communicate the backup file base name through the environment variable BUP_FILENAME.
|
4
29
|
- Rubocop fixes or ignore files.
|
5
30
|
- Add post commands, incase you want to default copy something around.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -14,11 +14,13 @@ Create a file ~/.buprc with the default contents...
|
|
14
14
|
|
15
15
|
```yaml
|
16
16
|
---
|
17
|
+
default_profile: default
|
17
18
|
profiles:
|
18
19
|
default:
|
19
20
|
description: Simple backup of critical files.
|
20
21
|
include:
|
21
22
|
- "$HOME"
|
23
|
+
- /$BUP_DESTINATION/db.dump
|
22
24
|
exclude:
|
23
25
|
- "$HOME"
|
24
26
|
- "$HOME/backups"
|
@@ -29,9 +31,14 @@ profiles:
|
|
29
31
|
- tar
|
30
32
|
- cJvf
|
31
33
|
- "${BUP_FILENAME}.tar.xz"
|
34
|
+
pre_cmds:
|
35
|
+
- - dumpdatabase
|
36
|
+
- /$BUP_DESTINATION/db.dump
|
32
37
|
post_cmds:
|
33
38
|
- - ls
|
34
39
|
- $BUP_FILENAME.tar.xz
|
40
|
+
- - rm
|
41
|
+
- /$BUP_DESTINATION/db.dump
|
35
42
|
```
|
36
43
|
|
37
44
|
This defines a single profile, "default". You can list
|
@@ -56,4 +63,4 @@ Before a new backup is run, previous backups are removed. If you run many
|
|
56
63
|
uncompleted backups, you will eventually remove all good backups from your
|
57
64
|
backup history. This behavior is desired because backups should nearly always
|
58
65
|
succeed and we want to ensure that disk pressure is kep lower than higher.
|
59
|
-
Higher disk pressure might cause a backup to fail.
|
66
|
+
Higher disk pressure might cause a backup to fail.
|
data/buprc
CHANGED
data/exe/bup
CHANGED
@@ -6,6 +6,7 @@ require "optparse"
|
|
6
6
|
|
7
7
|
configfile = File.join(ENV["HOME"], ".buprc")
|
8
8
|
config = Bup::Config.new
|
9
|
+
profile = nil
|
9
10
|
|
10
11
|
OptParse.new do |opt|
|
11
12
|
opt.banner = "#{$PROGRAM_NAME} #{Bup::VERSION}"
|
@@ -15,11 +16,15 @@ OptParse.new do |opt|
|
|
15
16
|
end
|
16
17
|
|
17
18
|
opt.on("-p", "--profile=profile", String, "Profile name.") do |p|
|
18
|
-
|
19
|
+
profile = p
|
19
20
|
end
|
20
21
|
|
21
|
-
opt.on("-
|
22
|
-
config.runtime["type"] =
|
22
|
+
opt.on("-i", "--incremental", String, "Set the type of backup to incremental.") do
|
23
|
+
config.runtime["type"] = "incremental"
|
24
|
+
end
|
25
|
+
|
26
|
+
opt.on("-f", "--full", String, "Set the type of backup to full.") do
|
27
|
+
config.runtime["type"] = "full"
|
23
28
|
end
|
24
29
|
|
25
30
|
opt.on("-l", "--list", "List profiles and exit.") do
|
@@ -29,6 +34,13 @@ end.parse!
|
|
29
34
|
|
30
35
|
config.load(configfile) if File.exist?(configfile)
|
31
36
|
|
37
|
+
if profile
|
38
|
+
config.runtime["profile"] = profile
|
39
|
+
elsif config.config["default_profile"]
|
40
|
+
config.runtime["profile"] = config.config["default_profile"]
|
41
|
+
end
|
42
|
+
|
43
|
+
|
32
44
|
case config.runtime["action"]
|
33
45
|
when "list"
|
34
46
|
config.config["profiles"].each do |key, profile|
|
data/lib/bup/tar.rb
CHANGED
@@ -32,8 +32,9 @@ module Bup
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# Prepare the destination directory.
|
35
|
-
def prepare_destination(profile_name)
|
36
|
-
destination = expand_string(
|
35
|
+
def prepare_destination(profile_name, profile)
|
36
|
+
destination = expand_string(profile["destination"] || ".")
|
37
|
+
|
37
38
|
type = @config.runtime["type"] || "full"
|
38
39
|
|
39
40
|
FileUtils.mkdir_p(destination) unless File.exist?(destination)
|
@@ -44,68 +45,100 @@ module Bup
|
|
44
45
|
|
45
46
|
history = @config.profile(profile_name)["history"] || 0
|
46
47
|
|
47
|
-
if type == "full"
|
48
|
+
if type == "full"
|
49
|
+
if history.positive?
|
50
|
+
prune_history(profile_name, destination, filename_base, history)
|
51
|
+
elsif history == 0
|
52
|
+
clear_history(profile_name, destination)
|
53
|
+
end
|
54
|
+
end
|
48
55
|
|
49
|
-
|
56
|
+
ENV["BUP_DESTINATION"] = destination
|
57
|
+
ENV["BUP_FILENAME"] = filename
|
58
|
+
filename
|
59
|
+
end
|
50
60
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
else
|
57
|
-
File.delete(fullbackup)
|
58
|
-
end
|
59
|
-
end
|
61
|
+
def clear_history(profile_name, destination)
|
62
|
+
Dir["#{destination}/#{profile_name}*"].each do |backup|
|
63
|
+
File.delete(backup)
|
64
|
+
end
|
65
|
+
end
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
def prune_history(profile_name, destination, filename_base, history)
|
68
|
+
oldest_kept_file = nil
|
69
|
+
|
70
|
+
# Keep some full backups and remove the others.
|
71
|
+
# We capture the oldest full backup and get rid of preceeding incrementals.
|
72
|
+
Dir["#{destination}/#{filename_base}*"].sort.reverse.each_with_index do |fullbackup, idx|
|
73
|
+
if idx < history
|
74
|
+
oldest_kept_file = fullbackup
|
75
|
+
else
|
76
|
+
File.delete(fullbackup)
|
67
77
|
end
|
68
78
|
end
|
69
79
|
|
70
|
-
|
80
|
+
# Remove all incremental files that are older than the oldest kept full backup.
|
81
|
+
if oldest_kept_file
|
82
|
+
remove_before = File.stat(oldest_kept_file).ctime
|
83
|
+
Dir["#{destination}/#{profile_name}*"].each do |backupfile|
|
84
|
+
File.delete(backupfile) if File.stat(backupfile).ctime < remove_before
|
85
|
+
end
|
86
|
+
end
|
71
87
|
end
|
72
88
|
|
89
|
+
# Run tar.
|
73
90
|
def call(profile_name = nil)
|
74
91
|
profile_name ||= @config.runtime["profile"]
|
75
92
|
profile = @config.config["profiles"][profile_name]
|
76
93
|
|
77
94
|
raise "Missing profile #{profile_name}." unless profile
|
78
95
|
|
79
|
-
args =
|
96
|
+
args = profile["tarcmd"].dup || ["tar", "cJvf", "${BUP_FILENAME}.tar.xz"]
|
80
97
|
|
81
|
-
|
98
|
+
prepare_destination(profile_name, profile)
|
82
99
|
|
83
100
|
if @config.runtime["type"] == "incremental"
|
84
101
|
lastrun = @config.lastrun(profile_name)
|
85
102
|
args += ["--newer", lastrun.strftime("%Y-%m-%d %H:%M:%S %z")] if lastrun
|
86
103
|
end
|
87
104
|
|
105
|
+
run_pre_cmds profile
|
106
|
+
|
88
107
|
@config.update_lastrun(profile_name)
|
89
108
|
|
90
109
|
tf = build_exclude_file(profile["exclude"] || [])
|
91
110
|
|
92
|
-
|
93
|
-
args += (@config.profile(profile_name)["include"] || ["."])
|
94
|
-
args = args.map do |str|
|
95
|
-
expand_string(str)
|
96
|
-
end
|
97
|
-
|
111
|
+
# Build and run tar command.
|
98
112
|
begin
|
113
|
+
args += ["--exclude-from", tf.path]
|
114
|
+
args += (profile["include"] || ["."])
|
115
|
+
args = args.map do |str|
|
116
|
+
expand_string(str)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Run tar.
|
99
120
|
run_cmd(*args)
|
100
121
|
ensure
|
101
122
|
tf.unlink
|
102
123
|
end
|
103
124
|
|
104
|
-
|
125
|
+
run_post_cmds profile
|
126
|
+
end
|
127
|
+
|
128
|
+
def run_pre_cmds(profile)
|
129
|
+
# Before we update the last_run, execute any pre_cmds.
|
130
|
+
(profile["pre_cmds"] || []).each do |args|
|
131
|
+
run_cmd(*args.map { |c| expand_string(c) })
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def run_post_cmds(profile)
|
136
|
+
(profile["post_cmds"] || []).each do |args|
|
105
137
|
run_cmd(*args.map { |c| expand_string(c) })
|
106
138
|
end
|
107
139
|
end
|
108
140
|
|
141
|
+
# Exec and run a command in a standard way.
|
109
142
|
def run_cmd(*args)
|
110
143
|
Open3.popen3(*args) do |stdin, stdout, stderr, wait_thr|
|
111
144
|
stdin.close
|
data/lib/bup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Baskinger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Backup tool driver that connects tar, gnupg, and other tools to accomplish
|
14
14
|
backups.
|