Files
aws-glacier-backup/backup.sh

79 lines
1.7 KiB
Bash
Raw Normal View History

2019-04-13 20:40:37 +02:00
#!/usr/bin/env bash
set -o nounset
set -o errexit
2019-04-13 20:51:27 +02:00
set -o xtrace
2019-04-13 22:10:45 +02:00
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ ! -e "${dir}/venv" ]] ; then
python3 -m venv "${dir}/venv"
2019-04-13 22:04:29 +02:00
fi
2019-04-13 22:10:45 +02:00
source "${dir}/venv/bin/activate"
command -v aws || pip install -r "${dir}/requirements.txt"
2019-04-13 22:04:29 +02:00
2019-04-13 22:10:45 +02:00
export GNUPGHOME="$(mktemp -d)"
2019-04-13 21:10:58 +02:00
2019-04-13 20:51:27 +02:00
bucket="${1}" ; shift
name="${1}" ; shift
2019-04-28 20:28:18 +02:00
filelist_script="${1}" ; shift
2019-04-24 20:52:12 +02:00
gpg_pubkey_file="${1}" ; shift
gpg_pubkey_id="${1}" ; shift
2019-04-18 18:58:35 +02:00
2019-04-13 21:10:58 +02:00
install --directory --owner $(id -u) --group $(id -g) --mode 700 "${GNUPGHOME}"
2019-04-13 20:40:37 +02:00
cleanup() {
2019-04-13 21:10:58 +02:00
rm -rf "${GNUPGHOME}"
2019-04-13 20:40:37 +02:00
}
trap cleanup EXIT
tmpgpg() {
gpg \
--batch \
2019-04-18 18:58:35 +02:00
--keyid-format=0xlong \
2019-04-13 20:40:37 +02:00
--no-default-keyring \
--no-options \
2019-04-13 21:10:58 +02:00
--trust-model always \
2019-04-13 20:40:37 +02:00
"${@}"
}
2019-04-24 20:52:12 +02:00
tmpgpg --import "${gpg_pubkey_file}"
2019-04-18 18:58:35 +02:00
tmpgpg -k
timestamp="$(date --utc -Iseconds)"
2019-04-28 20:28:18 +02:00
"${filelist_script}" | while read filelist ; do
filepath="$(echo "$filelist" | cut -d ':' -f 1)"
fifo="$(echo "$filelist" | cut -d ':' -f 2)"
mkdir -p "$(dirname "${filepath}")"
echo "$fifo"
<"$fifo" 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 \
2019-05-20 22:42:30 +02:00
--compress-algo none \
2019-05-20 22:42:51 +02:00
--cipher-algo AES256 \
--digest-algo SHA256 \
2019-04-28 20:28:18 +02:00
--recipient "${gpg_pubkey_id}" \
| aws \
s3 cp \
2019-05-20 22:02:41 +02:00
--storage-class DEEP_ARCHIVE \
2019-04-28 20:28:18 +02:00
- \
"s3://${bucket}/${name}-${timestamp}/${filepath##*(/)}.tar.gz.gpg"
2019-04-18 18:58:35 +02:00
done