Last active
December 24, 2022 21:20
-
-
Save tyrm/cb71adc7c0537ea4ed0ebe7919b333ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
#imports | |
. /etc/default/backup | |
# config | |
NAME=$1 | |
# generated | |
case $NAME in | |
ptzo-masto-pettingzoo) | |
BUCKET=ptzo-masto-pettingzoo | |
ALIAS=do-sfo3 | |
;; | |
*) | |
echo Instance code $INSTANCE unknown. | |
exit 1 | |
;; | |
esac | |
BACKUPPATH=ph/backups-s3/${ALIAS}/$(date +%Y)/$(date +%m)/$(date +%d)/ | |
SCRATCH=/scratch/s3-mirror/${ALIAS} | |
TARBALL=${SCRATCH}/${BUCKET}.txz | |
# sync files from cloud | |
if [ ! -d "${SCRATCH}" ]; then | |
echo | |
echo Creating scratch folder | |
mkdir -p ${SCRATCH}; | |
fi | |
echo | |
echo Syncing Files | |
nice mc --no-color \ | |
mirror \ | |
--overwrite \ | |
--remove \ | |
--monitoring-address localhost:9969 \ | |
${ALIAS}/${BUCKET} ${SCRATCH}/${BUCKET} | |
# compress | |
if [ -f "${TARBALL}" -o -f "${TARBALL}.gpg" ]; then | |
echo | |
echo Removing Old Tarball | |
rm -Rvf ${TARBALL} ${TARBALL}.gpg | |
fi | |
CORES=$(grep -c ^processor /proc/cpuinfo) | |
COREDIV=2 | |
COMPTHREADS=$(( CORES / COREDIV )) | |
echo | |
echo Compressing using ${CORES} threads | |
cd ${SCRATCH} | |
#nice tar --create --xz --file=${TARBALL} ${BUCKET}$ | |
nice tar cf - ${BUCKET} | nice xz -T ${CORES} -z - > ${TARBALL} | |
# encrypt | |
echo | |
echo Encrypting | |
nice gpg --yes --batch --passphrase=${GPG_PASSWORD} -c ${TARBALL} | |
# upload to backups | |
nice mc cp ${TARBALL}.gpg ${BACKUPPATH} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment