Compare commits
7 Commits
94f8682e64
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c3764c7ff | |||
| c72a1f81ce | |||
| e7738b1a71 | |||
| 7f06058b44 | |||
| 841f35ca06 | |||
| 5626dc78e6 | |||
| 674500b3f9 |
@@ -8,6 +8,8 @@ RUN apk add --update \
|
||||
tar \
|
||||
sed \
|
||||
xz \
|
||||
sshpass \
|
||||
openssh-client \
|
||||
tzdata \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
|
||||
64
backup.sh
64
backup.sh
@@ -19,20 +19,20 @@ fi
|
||||
rm -f ~/$BACKUP_FILENAME.gpg ~/$BACKUP_FILENAME
|
||||
|
||||
healthchck_fail(){
|
||||
if [ -n $HEALTHCHECK_URL ]; then
|
||||
if [ -n "$HEALTHCHECK_URL" ]; then
|
||||
curl -X POST --data "$*" --retry 3 $HEALTHCHECK_URL/fail --silent --output /dev/null
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
healthchck_start(){
|
||||
if [ -n $HEALTHCHECK_URL ]; then
|
||||
if [ -n "$HEALTHCHECK_URL" ]; then
|
||||
curl -X POST --data "$*" --retry 3 $HEALTHCHECK_URL/start --silent --output /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
healthchck_ok(){
|
||||
if [ -n $HEALTHCHECK_URL ]; then
|
||||
if [ -n "$HEALTHCHECK_URL" ]; then
|
||||
curl -X POST --data "$*" --retry 3 $HEALTHCHECK_URL --silent --output /dev/null
|
||||
fi
|
||||
}
|
||||
@@ -59,25 +59,45 @@ gpg --batch --trust-model always --enable-progress-filter --output ~/$BACKUP_FIL
|
||||
rm ~/$BACKUP_FILENAME
|
||||
|
||||
echo "uploading"
|
||||
AWS_ENDPOINT_OPTION=
|
||||
AWS_STORAGECLASS_OPTION="--storage-class DEEP_ARCHIVE"
|
||||
if [ "$AWS_USE_MINIO" -eq 1 ] ; then
|
||||
aws configure set default.s3.signature_version s3v4
|
||||
AWS_ENDPOINT_OPTION="--endpoint-url https://${MINIO_ENDPOINT}"
|
||||
AWS_STORAGECLASS_OPTION=
|
||||
fi
|
||||
echo aws ${AWS_ENDPOINT_OPTION} s3 cp ~/$BACKUP_FILENAME.gpg s3://$S3_BUCKET_NAME/$BACKUP_FILENAME.gpg ${AWS_STORAGECLASS_OPTION} || healthchck_fail "Upload Failed"
|
||||
aws ${AWS_ENDPOINT_OPTION} s3 cp --no-progress ~/$BACKUP_FILENAME.gpg s3://$S3_BUCKET_NAME/$BACKUP_FILENAME.gpg ${AWS_STORAGECLASS_OPTION} || healthchck_fail "Upload Failed"
|
||||
rm ~/$BACKUP_FILENAME.gpg
|
||||
echo "done"
|
||||
|
||||
# On first month day do
|
||||
if [ "$AWS_USE_MINIO" -eq 1 ]; then
|
||||
echo "no monthly"
|
||||
if [ "$USE_SFTP" -eq 1 ]; then
|
||||
echo "use sftp"
|
||||
cd ~/
|
||||
sshpass -e sftp -oStrictHostKeyChecking=no -oBatchMode=no ${SFTP_EXTRA} -b - ${SFTP_USER}@${SFTP_HOST} << !
|
||||
cd ${SFTP_PATH}
|
||||
put ${BACKUP_FILENAME}.gpg
|
||||
bye
|
||||
!
|
||||
if [ "$month_day" -eq 1 ] ; then
|
||||
echo "make monthly backup"
|
||||
sshpass -e sftp -oStrictHostKeyChecking=no -oBatchMode=no ${SFTP_EXTRA} -b - ${SFTP_USER}@${SFTP_HOST} << !
|
||||
cd ${SFTP_PATH}
|
||||
cp ${BACKUP_FILENAME}.gpg ${BACKUP_FILENAME_MONTHLY}.gpg
|
||||
bye
|
||||
!
|
||||
fi
|
||||
rm ~/$BACKUP_FILENAME.gpg
|
||||
else
|
||||
if [ "$month_day" -eq 1 ] ; then
|
||||
echo "make monthly backup"
|
||||
aws ${AWS_ENDPOINT_OPTIOM} s3 cp s3://$S3_BUCKET_NAME/$BACKUP_FILENAME.gpg s3://$S3_BUCKET_NAME/$BACKUP_FILENAME_MONTHLY.gpg --storage-class DEEP_ARCHIVE || healthchck_fail "failed to create monthly backup"
|
||||
fi
|
||||
AWS_ENDPOINT_OPTION=
|
||||
AWS_STORAGECLASS_OPTION="--storage-class DEEP_ARCHIVE"
|
||||
if [ "$AWS_USE_MINIO" -eq 1 ] ; then
|
||||
aws configure set default.s3.signature_version s3v4
|
||||
AWS_ENDPOINT_OPTION="--endpoint-url https://${MINIO_ENDPOINT}"
|
||||
AWS_STORAGECLASS_OPTION=
|
||||
fi
|
||||
echo aws ${AWS_ENDPOINT_OPTION} s3 cp ~/$BACKUP_FILENAME.gpg s3://$S3_BUCKET_NAME/$BACKUP_FILENAME.gpg ${AWS_STORAGECLASS_OPTION} || healthchck_fail "Upload Failed"
|
||||
aws ${AWS_ENDPOINT_OPTION} s3 cp --no-progress ~/$BACKUP_FILENAME.gpg s3://$S3_BUCKET_NAME/$BACKUP_FILENAME.gpg ${AWS_STORAGECLASS_OPTION} || healthchck_fail "Upload Failed"
|
||||
rm ~/$BACKUP_FILENAME.gpg
|
||||
echo "done"
|
||||
|
||||
# On first month day do
|
||||
if [ "$AWS_USE_MINIO" -eq 1 ]; then
|
||||
echo "no monthly"
|
||||
else
|
||||
if [ "$month_day" -eq 1 ] ; then
|
||||
echo "make monthly backup"
|
||||
aws ${AWS_ENDPOINT_OPTIOM} s3 cp s3://$S3_BUCKET_NAME/$BACKUP_FILENAME.gpg s3://$S3_BUCKET_NAME/$BACKUP_FILENAME_MONTHLY.gpg --storage-class DEEP_ARCHIVE || healthchck_fail "failed to create monthly backup"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
healthchck_ok "Success"
|
||||
|
||||
12
restore.sh
12
restore.sh
@@ -2,15 +2,15 @@
|
||||
|
||||
gpg --import /keys/*
|
||||
|
||||
aws s3 ls s3://$S3_BUCKET_NAME
|
||||
echo "These are the files currently available in your backup bucket."
|
||||
echo "Which file contains the backup you want to restore from?"
|
||||
echo -n "File name: "
|
||||
read RESTORE_FILE
|
||||
AWS_ENDPOINT_OPTION=
|
||||
if [ "$AWS_USE_MINIO" -eq 1 ] ; then
|
||||
aws configure set default.s3.signature_version s3v4
|
||||
AWS_ENDPOINT_OPTION="--endpoint-url https://${MINIO_ENDPOINT}"
|
||||
fi
|
||||
|
||||
cd /restore
|
||||
|
||||
aws s3 cp s3://$S3_BUCKET_NAME/$RESTORE_FILE .
|
||||
aws ${AWS_ENDPOINT_OPTION} s3 cp s3://$S3_BUCKET_NAME/$RESTORE_FILE .
|
||||
|
||||
gpg --output ./restore.tar.xz --decrypt $RESTORE_FILE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user