update backup-container

This commit is contained in:
root 2014-11-02 16:52:35 +01:00
parent c148ae99df
commit ae9b07dba9
1 changed files with 14 additions and 30 deletions

View File

@ -9,7 +9,7 @@ BACKUP_LOCATIONS = %w{home srv etc usr/local}
CONFIG_PATH="/etc/lxc/container.json" CONFIG_PATH="/etc/lxc/container.json"
DUPLICITY_PATH= Pathname.new("/data/duplicity/") DUPLICITY_PATH= Pathname.new("/data/duplicity/")
BACKUP_PATH="file:///mnt/backup/duplicity" BACKUP_PATH="file:///mnt/backup/duplicity"
FULL_BACKUP_COUNT=2 FULL_BACKUP_COUNT=1
def load_config def load_config
return JSON.load(File.open(CONFIG_PATH)) return JSON.load(File.open(CONFIG_PATH))
@ -79,18 +79,6 @@ class Container
end end
end end
if ARGV.size > 0
if ["full", "incr"].include?(ARGV.first)
action = ARGV.first
else
$stderr.puts "action must be full or incr"
$stderr.puts "USAGE #{File.basename($0)} [full|incr]"
exit 1
end
else
action = "incr"
end
Dir.chdir(DUPLICITY_PATH) do Dir.chdir(DUPLICITY_PATH) do
config = load_config config = load_config
backup_paths = BACKUP_LOCATIONS.map do |location| backup_paths = BACKUP_LOCATIONS.map do |location|
@ -102,30 +90,26 @@ Dir.chdir(DUPLICITY_PATH) do
backup_paths += container.backup_paths backup_paths += container.backup_paths
backup_paths += container.run_backup_scripts backup_paths += container.run_backup_scripts
end end
gpg_args = ["--gpg-options", "--secret-keyring ./duplicity.sec --keyring ./duplicity.pub"] gpg_args = ["--sign-key", "AF5834A6", "--encrypt-key", "AF5834A6", "--gpg-options", "--secret-keyring ./duplicity.sec --keyring ./duplicity.pub"]
args = gpg_args + ["--verbosity", "notice", args = ["--archive-dir", "cache", "--log-file", "/var/log/duplicity.log"] + gpg_args
"--encrypt-key", "AF5834A6", backup_args = args + ["--verbosity", "notice",
"--sign-key", "AF5834A6", "--full-if-older-than", "30D",
"--full-if-older-than", "60D",
"--num-retries", "3", "--num-retries", "3",
"--asynchronous-upload", "--asynchronous-upload",
"--volsize", "250", "--volsize", "250",
"--include-globbing-filelist", "/dev/stdin", "--include-globbing-filelist", "/dev/stdin", "--exclude", "**",
"--archive-dir", "cache", "/", BACKUP_PATH]
"--log-file", "/var/log/duplicity.log",
action, "/", BACKUP_PATH]
env = { "PASSPHRASE" => File.read("pgp-passphrase") } env = { "PASSPHRASE" => File.read("pgp-passphrase") }
stdin, stdout, stderr = Open3.popen3(env, "duplicity", *args) sh("find", "cache", "-type", "f", "-name", "lockfile.lock", "-exec", "rm -f {} ;")
if action == "full" sh("duplicity", env, "cleanup", "--force", BACKUP_PATH, *args)
sh("duplicity", env, "remove-all-but-n-full", FULL_BACKUP_COUNT.to_s, BACKUP_PATH, *gpg_args) stdin, stdout, stderr = Open3.popen3(env, "duplicity", *backup_args)
end
backup_paths.each do |path| backup_paths.each do |path|
stdin.puts("+ #{path}") stdin.puts(path)
puts("+ #{path}") puts(path)
end end
stdin.puts("- **")
puts("- **")
stdin.close stdin.close
puts stdout.read puts stdout.read
puts stderr.read puts stderr.read
sh("duplicity", env, "remove-older-than", "30D", "--force", BACKUP_PATH, *args)
sh("duplicity", env, "remove-all-inc-of-but-n-full", FULL_BACKUP_COUNT.to_s, "--force", BACKUP_PATH, *args)
end end