Files
aws-glacier-backup/backup.sh

53 lines
996 B
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:04:29 +02:00
if [[ ! -e ./venv ]] ; then
python3 -m venv venv
fi
source ./venv/bin/activate
command -v aws || pip install -r ./requirements.txt
2019-04-13 21:10:58 +02:00
export GNUPGHOME=./gpghome
2019-04-13 20:51:27 +02:00
bucket="${1}" ; shift
name="${1}" ; shift
backup_source="${1}" ; shift
2019-04-13 20:40:37 +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 \
--no-default-keyring \
--no-options \
2019-04-13 21:10:58 +02:00
--trust-model always \
2019-04-13 20:40:37 +02:00
"${@}"
}
tmpgpg --import ./pubkey.asc
tar \
--create \
--verbose \
2019-04-13 21:16:17 +02:00
--gzip \
2019-04-13 20:40:37 +02:00
--one-file-system \
--file - \
2019-04-13 20:51:27 +02:00
"${backup_source}" \
2019-04-13 20:40:37 +02:00
| tmpgpg \
--output - \
--encrypt \
2019-04-13 20:51:27 +02:00
--recipient 0x078A167A8741BD30 \
2019-04-13 21:10:58 +02:00
| aws \
s3 cp \
2019-04-13 20:40:37 +02:00
--storage-class=DEEP_ARCHIVE \
- \
2019-04-13 21:16:17 +02:00
"s3://${bucket}/${name}-$(date --utc -Iseconds).tar.gz.gpg"