完整代码:

#!/bin/bash

# This script creates a .zip backup of gitea running inside docker and copies the backup file to the backup directory

echo "Delete older backup ..."
find /media/srv/docker/gitea_backup/ -type f -mtime +9 -name "*.zip" -delete


echo "Creating gitea backup inside docker containter ..."
docker exec -u git $(docker ps -qf "name=gitea_server_1") bash -c '/app/gitea/gitea dump -c /data/gitea/conf/app.ini --file /tmp/gitea-dump.zip'

echo "Copying backup file from the container to the host machine ..."
docker cp $(docker ps -qf "name=gitea_server_1"):/tmp/gitea-dump.zip /tmp

echo "Removing backup file in container ..."
docker exec -u git $(docker ps -qf "name=gitea_server_1") bash -c 'rm /tmp/gitea-dump.zip'

echo "Renaming backup file ..."
BACKUPFILE=/opt/gitea_backup/gitea-dump-$(date +"%Y%m%d%H%M").zip
mv /tmp/gitea-dump.zip $BACKUPFILE

echo "Backup file is available: $BACKUPFILE"

echo "Copy file to Nas2: $BACKUPFILE"
scp $BACKUPFILE root@192.168.3.98:/volume1/Maintenance/GiteaBackup/

echo "Done."

KuaiYu服务器备份脚本:

#!/bin/bash

dir='/volume1/Maintenance/codebase/server/backup'
ext='zip'

cd $dir

find $dir -type f -mtime +30 -name "*.$ext" -delete

time=`date "+%Y%m%d%H%M%S"`
filename="gitea-$time.$ext"
# tar -zcvf $filename --exclude=gitea/queues --exclude=gitea/sessions --exclude=giea/tmp *

docker exec -u git Gitea-Server bash -c "/app/gitea/gitea dump -c /data/gitea/conf/app.ini --file /data/backup/$filename"

scp $filename root@192.168.3.98:/volume1/Maintenance/GiteaBackup/

# rm -rf $filename