Compare commits

..

27 Commits

Author SHA1 Message Date
9c3764c7ff disabled hostkey check
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-27 10:21:33 +02:00
c72a1f81ce updated healthcheck call
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-27 10:08:07 +02:00
e7738b1a71 fixed missing fi
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-27 07:19:59 +02:00
7f06058b44 added sshpass and sftp
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-27 07:06:40 +02:00
841f35ca06 added extra parameter for sftp
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-27 06:51:04 +02:00
5626dc78e6 allow sftp backup
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-27 06:47:09 +02:00
674500b3f9 minio support for restore 2021-01-29 05:54:29 +01:00
94f8682e64 „run.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2021-01-29 04:07:41 +00:00
53cea3c2e7 „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-12-19 14:33:35 +00:00
5ffa5ec1d3 configure timezone
All checks were successful
continuous-integration/drone/push Build is passing
2020-11-04 09:49:12 +00:00
ac307c2671 batch flag for gpg
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-06 07:16:27 +02:00
0062fd9fd5 no upload progress
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-02 07:23:55 +02:00
cb9eaa9ec1 „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-02-25 06:37:16 +00:00
519f946a27 „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-02-24 21:48:20 +00:00
f7740c83bf „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-02-24 21:47:29 +00:00
760ac6dd6c „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-02-24 21:37:37 +00:00
21ceaed9f6 „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-02-24 21:34:53 +00:00
47adb12689 „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-02-24 15:19:09 +00:00
5f6ddaa9ab Only Deep archive
All checks were successful
continuous-integration/drone/push Build is passing
2020-02-04 05:56:01 +00:00
de65d91aa6 „backup.sh“ ändern
All checks were successful
continuous-integration/drone/push Build is passing
2020-01-22 06:12:44 +00:00
09756c15d3 backup to glacier by default
All checks were successful
continuous-integration/drone/push Build is passing
2020-01-21 14:22:51 +00:00
ee7aca3c82 reverted progress display
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-29 07:11:35 +01:00
e116a90979 use xz
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-28 23:42:02 +01:00
71abb6ab65 using sh not bash
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-28 17:18:13 +01:00
19fb60982a run ci
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-28 17:14:49 +01:00
8b13faeea6 fixed subst
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-28 16:28:44 +01:00
48fbe9124b fixed frompath
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-28 11:37:03 +01:00
4 changed files with 71 additions and 29 deletions

View File

@@ -8,7 +8,13 @@ RUN apk add --update \
tar \
sed \
xz \
sshpass \
openssh-client \
tzdata \
&& rm -rf /var/cache/apk/*
ENV TZ=Europe/Berlin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN pip install awscli

View File

@@ -16,52 +16,88 @@ else
BACKUP_FILENAME_MONTHLY=monthly_$BACKUP_BASENAME.xz
fi
rm -f ~/$BACKUP_FILENAME.gpg ~/$BACKUP_FILENAME
healthchck_fail(){
if [ -n $HEALTHCHECK_URL ]; then
curl -X POST --data $1 --retry 3 $HEALTHCHECK_URL/fail --silent --output /dev/null
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
curl -X POST --data $1 --retry 3 $HEALTHCHECK_URL/start --silent --output /dev/null
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
curl -X POST --data $1 --retry 3 $HEALTHCHECK_URL --silent --output /dev/null
if [ -n "$HEALTHCHECK_URL" ]; then
curl -X POST --data "$*" --retry 3 $HEALTHCHECK_URL --silent --output /dev/null
fi
}
healthchck_start "Starting Backup"
cd /backup
echo "make archive"
FROMPATH='./*'
FROMSIZE=`du -sk ${FROMPATH} | cut -f 1`;
CHECKPOINT=`echo ${FROMSIZE}/50 | bc`;
echo "Estimated: [==================================================]";
echo -n "Progess: [";
(tar -c --record-size=1K --checkpoint="${CHECKPOINT}" --checkpoint-action="ttyout=>" -f - "${FROMPATH}" | bzip2 > "${$BACKUP_FILENAME}") || healthchck_fail "TAR Failed"
echo "]"
TAR_RETRIES=3
while [ $TAR_RETRIES -gt 0 ]; do
echo "make archive"
tar -c ${TAR_PARAM} ${TAR_EXTRA_PARAM} -f ~/$BACKUP_FILENAME ./* || healthchck_fail "TAR Failed"
if [ $? -ne 0 ]; then
TAR_RETRIES=$(($TAR_RETRIES-1))
else
TAR_RETRIES=0
fi
done
cd /
echo " done"
RECIPIENT=$(echo "$GPG_RECIPIENT" | sed "s/,/ --recipient /")
echo "encrypting"
gpg --trust-model always --enable-progress-filter --output ~/$BACKUP_FILENAME.gpg --encrypt --recipient $RECIPIENT ~/$BACKUP_FILENAME || healthchck_fail "Encryption Failed"
gpg --batch --trust-model always --enable-progress-filter --output ~/$BACKUP_FILENAME.gpg --encrypt --recipient $RECIPIENT ~/$BACKUP_FILENAME || healthchck_fail "Encryption Failed"
rm ~/$BACKUP_FILENAME
echo "uploading"
aws s3 cp ~/$BACKUP_FILENAME.gpg s3://$S3_BUCKET_NAME/$BACKUP_FILENAME.gpg --storage-class STANDARD_IA || healthchck_fail "Upload Failed"
rm ~/$BACKUP_FILENAME.gpg
echo "done"
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
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 [ "$month_day" -eq 1 ] ; then
echo "make monthly backup"
aws 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"
# 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"

View File

@@ -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

2
run.sh
View File

@@ -7,7 +7,7 @@ if [ ${RUN_NOW:-0} -ne 0 ]; then
/backup.sh
fi
# Create and install crontab file
echo "$CRON_INTERVAL /backup.sh" >> /backup.cron
echo "$CRON_INTERVAL /backup.sh" > /backup.cron
crontab /backup.cron