diff --git a/backup.sh b/backup.sh index d86d6dc..9555486 100644 --- a/backup.sh +++ b/backup.sh @@ -1,15 +1,27 @@ #!/bin/bash -# 自动备份时使用以下命令 +# 自动备份时使用以下命令,需要root权限 # /bin/bash /srv/dev-disk-by-label-hd2/docker/gitea/backup.sh +backup_path="/sharedfolders/git/gitea" +backup_filename=$(date "+gitea-backup-%Y%m%d%H%M%S.tgz") + +# if sudo -n uptime 2>&1 | grep -q "load"; then +# echo "请用root权限运行" +# exit 1 +# fi + cd $(dirname ${BASH_SOURCE:-$0}) cid=$(docker-compose ps -q gitea) if [ ${#cid} -gt 0 ]; then - echo "Backuping applications ..." - docker-compose exec -T gitea /bin/bash -c "cd /app/gitea/backup; su git -c \"gitea dump\"" - exit 0 -else - echo "The container \"gitea\" not running. Please start container \"gitea\"" - exit 1 -fi \ No newline at end of file + docker-compose down +fi + +cd data +echo "备份到 ${backup_path}/${backup_filename} ..." +sudo tar -zcpf ${backup_path}/${backup_filename} gitea +sudo chown git:users ${backup_path} -R +echo "备份完毕." +cd .. +echo "启动 Gitea ..." +docker-compose up -d \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index aeab350..3d0c8b6 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,8 +28,6 @@ services: - gitea volumes: - /data/gitea:/data - # - ./data/gitea/git:/data/git - # - ./data/backup:/app/gitea/backup ports: - "3000:3000" - "22:22" diff --git a/lsbak.sh b/lsbak.sh new file mode 100644 index 0000000..0976634 --- /dev/null +++ b/lsbak.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo ls /sharedfolders/git/gitea -lh diff --git a/restore.sh b/restore.sh new file mode 100644 index 0000000..dd8505c --- /dev/null +++ b/restore.sh @@ -0,0 +1,47 @@ +#!/bin/bash +backup_path="/sharedfolders/git/gitea" + +cd $(dirname ${BASH_SOURCE:-$0}) + +cid=$(docker-compose ps -q gitea) +if [ ${#cid} -gt 0 ]; then + docker-compose down +fi + +# 恢复备份 +PS3="请选择恢复的备份: " +menu=$(ls -1 ${backup_path} | grep "gitea-backup") + +select dump_filename in ${menu} "退出" +do + if [ -n "${dump_filename}" ]; then + case "${dump_filename}" in + "退出") + exit 1 + ;; + *) + break + ;; + esac + fi +done + + +read -n1 -p "恢复备份 : ${dump_filename} (N/y)? : " answer +case $answer in + Y|y) + echo + echo "恢复备份 \"${dump_filename}\" 中 ..." + mkdir -p ./data + cd data + sudo mv gitea $(date "+gitea.%Y%m%d%H%M%S") + sudo tar -zxf ${backup_path}/${dump_filename} + echo "恢复完毕." + echo "启动 Gitea ..." + docker-compose up -d + ;; + *) + echo + exit 1 + ;; +esac