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