Commit 6f1ab9fa authored by Nicolas Steinmetz's avatar Nicolas Steinmetz

Improve backup mechanism

parent b914ce16
Pipeline #933 passed with stage
in 2 minutes and 6 seconds
#!/usr/bin/env sh
BACKUP_FILE=nextcloud-`date +%F`.tgz
BACKUP_NAME=nextcloud
BACKUP_FILE=${BACKUP_NAME}-`date +%F`.tgz
BACKUP_DIR=/srv/backup
SRC_DIR=/srv/files
SEGMENT_SIZE=1073741824
# Clean repo
find ${BACKUP_DIR}/${BACKUP_NAME}-*.tgz -type f -mtime +0 | xargs rm -f
# Do backup
tar czf ${BACKUP_DIR}/${BACKUP_FILE} ${SRC_DIR}
# Enable swift upload - assume environment variables are set
if [[ ${SWIFT_UPLOAD} ]]; then
swift upload ${SWIFT_CONTAINER} ${BACKUP_DIR}/${BACKUP_FILE} --object-name ${BACKUP_FILE}
swift upload ${SWIFT_CONTAINER} ${BACKUP_DIR}/${BACKUP_FILE} --object-name ${BACKUP_FILE} --segment-size ${SEGMENT_SIZE}
if [[ $? == 0 ]]; then
rm -f ${BACKUP_DIR}/${BACKUP_FILE}
fi
fi
# Clean repo
find ${BACKUP_DIR}/nextcloud-*.tgz -type f | xargs rm -f
#!/usr/bin/env sh
export PGPASSWORD=${NEXTCLOUD_DB_PASSWORD}
BACKUP_FILE=${NEXTCLOUD_DB_NAME}-`date +%F`.sql
pg_dump -w -h ${NEXTCLOUD_DB_HOST} -U ${NEXTCLOUD_DB_USER} -d ${NEXTCLOUD_DB_NAME} -Fc -f /srv/backup/${BACKUP_FILE}
BACKUP_DIR=/srv/backup
export PGPASSWORD=${NEXTCLOUD_DB_PASSWORD}
# Clean repo
find ${BACKUP_DIR}/${NEXTCLOUD_DB_NAME}-*.sql -type f -mtime +7 |xargs rm -f
# Do backup
pg_dump -w -h ${NEXTCLOUD_DB_HOST} -U ${NEXTCLOUD_DB_USER} -d ${NEXTCLOUD_DB_NAME} -Fc -f ${BACKUP_DIR}/${BACKUP_FILE}
unset PGPASSWORD
# Enable swift upload - assume environment variables are set
if [[ ${SWIFT_UPLOAD} ]]; then
swift upload ${SWIFT_CONTAINER} /srv/backup/${BACKUP_FILE} --object-name ${BACKUP_FILE}
fi
# Clean repo
find /srv/backup/${NEXTCLOUD_DB_NAME}-*.sql -type f -mtime +7 |xargs rm -f
swift upload ${SWIFT_CONTAINER} ${BACKUP_DIR}/${BACKUP_FILE} --object-name ${BACKUP_FILE}
if [[ $? == 0 ]]; then
rm -f ${BACKUP_DIR}/${BACKUP_FILE}
fi
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment