From 714e14125c11228a6cae8ec3e813fedb48498631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Thu, 18 Apr 2019 18:58:35 +0200 Subject: [PATCH] Enabling reading dirlist from file --- backup.sh | 99 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 42 deletions(-) diff --git a/backup.sh b/backup.sh index 5f8b816..4dff085 100755 --- a/backup.sh +++ b/backup.sh @@ -16,7 +16,10 @@ export GNUPGHOME="$(mktemp -d)" bucket="${1}" ; shift name="${1}" ; shift -backup_source="${1}" ; shift +backup_sources_file="${1}" ; shift + +declare -a backup_sources +readarray backup_sources < "${backup_sources_file}" install --directory --owner $(id -u) --group $(id -g) --mode 700 "${GNUPGHOME}" @@ -29,6 +32,7 @@ trap cleanup EXIT tmpgpg() { gpg \ --batch \ + --keyid-format=0xlong \ --no-default-keyring \ --no-options \ --trust-model always \ @@ -36,44 +40,55 @@ tmpgpg() { } tmpgpg --import "${dir}/pubkey.asc" -find \ - "${backup_source}" \ - \( \ - -regex "${backup_source}.*nextcloud/.*/files_trashbin" \ - -o \ - -regex "${backup_source}.*nextcloud/nextcloud.log" \ - -o \ - -regex "${backup_source}.*registry/docker/registry" \ - -o \ - -regex "${backup_source}.*gogs/.*/gogs.log.*" \ - -o \ - -regex "${backup_source}.*gogs/gogs/data/sessions/.*" \ - -o \ - -regex "${backup_source}.*/cache/.*" \ - \) \ - -prune \ - -o \ - -print0 \ - | tar \ - --create \ - --verbose \ - --no-auto-compress \ - --ignore-failed-read \ - --acls \ - --selinux \ - --xattrs \ - --null \ - --no-recursion \ - --files-from - \ - --file - \ - | gzip \ - --to-stdout \ - | tmpgpg \ - --output - \ - --encrypt \ - --recipient 0x078A167A8741BD30 \ - | aws \ - s3 cp \ - --storage-class=DEEP_ARCHIVE \ - - \ - "s3://${bucket}/${name}-$(date --utc -Iseconds).tar.gz.gpg" +tmpgpg -k + +timestamp="$(date --utc -Iseconds)" + +for backup_dir in "${backup_sources[@]}" ; do + backup_dir_expanded=($(eval "echo $backup_dir")) + for dir in "${backup_dir_expanded[@]}" ; do + echo $dir + set -x + find \ + "${dir[@]}" \ + \( \ + -regex "${dir}.*/files_trashbin" \ + -o \ + -regex "${dir}.*nextcloud.log.*" \ + -o \ + -regex "${dir}.*registry/docker/registry" \ + -o \ + -regex "${dir}.*/gogs.log.*" \ + -o \ + -regex "${dir}.*gogs/data/sessions/.*" \ + -o \ + -regex "${dir}.*/cache/.*" \ + \) \ + -prune \ + -o \ + -print0 \ + | tar \ + --create \ + --verbose \ + --no-auto-compress \ + --ignore-failed-read \ + --acls \ + --selinux \ + --xattrs \ + --null \ + --force-local \ + --no-recursion \ + --files-from - \ + --file - \ + | gzip \ + --to-stdout \ + | tmpgpg \ + --output - \ + --encrypt \ + --recipient 0x078A167A8741BD30 \ + | aws \ + s3 cp \ + - \ + "s3://${bucket}/${name}-${timestamp}/${dir}.tar.gz.gpg" + done +done