From 40abd112fd9b34692cc2164ec329827667ca091f Mon Sep 17 00:00:00 2001 From: Julien Toscano Date: Tue, 9 Jun 2020 23:04:55 +0200 Subject: [PATCH] Backup gitea from docker --- backup/backup_gitea | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 backup/backup_gitea diff --git a/backup/backup_gitea b/backup/backup_gitea new file mode 100755 index 0000000..c05dd71 --- /dev/null +++ b/backup/backup_gitea @@ -0,0 +1,23 @@ +#!/bin/bash + +# Variables +BACKUP_ROOT_GITEA="/backup/gitea" +BACKUP_GITEA_RETENTION=10 + +# Starting backup +echo "Starting gitea backup process ..." + +# Backup server configuration +mkdir -p ${BACKUP_ROOT_GITEA} +HOUR=`date +%Y%m%d%H%M` + +# Launch dump command on docker +docker exec -w /data $(docker ps -qf "name=gitea") su - git sh -c "/app/gitea/gitea dump -c /data/gitea/conf/app.ini -f gitea-dump-${HOUR}.zip" +# And get from docker +docker cp $(docker ps -qf "name=gitea"):/data/git/gitea-dump-${HOUR}.zip ${BACKUP_ROOT_GITEA} +# Finally, remove backup on container +docker exec -w /data $(docker ps -qf "name=gitea") su - git sh -c "rm gitea-dump-${HOUR}.zip" + +# Purge old backup +echo "Starting gitea purge process for backup older than ${BACKUP_GITEA_RETENTION} ..." +find ${BACKUP_ROOT_GITEA} -type f -mtime +${BACKUP_GITEA_RETENTION} -exec rm -f {} \;