From ae9b07dba9d200af2c5cb0bf367076c3abe17491 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 2 Nov 2014 16:52:35 +0100 Subject: [PATCH] update backup-container --- backup-container | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/backup-container b/backup-container index ce46689..ff040f5 100755 --- a/backup-container +++ b/backup-container @@ -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