2019-06-04 16:20:18 +08:00
|
|
|
#!/bin/bash
|
|
|
|
backup_path="/sharedfolders/git/gitea"
|
|
|
|
|
2020-01-31 15:24:20 +08:00
|
|
|
backup_path_docker="/backup"
|
2019-06-04 16:20:18 +08:00
|
|
|
|
2020-01-31 15:24:20 +08:00
|
|
|
backup_filename=${backup_path_docker}/$(date "+gitea-backup-%Y%m%d_%H%M%S")
|
2019-06-04 16:20:18 +08:00
|
|
|
|
2020-01-31 15:24:20 +08:00
|
|
|
cd $(dirname $0)
|
|
|
|
|
|
|
|
# ls -1 ${backup_path}
|
2019-06-04 16:20:18 +08:00
|
|
|
# 恢复备份
|
|
|
|
PS3="请选择恢复的备份: "
|
2020-01-31 15:24:20 +08:00
|
|
|
menu=$(ls -1 ${backup_path} | sed -n 's/gitea-backup-\(20[0-9]\{6\}_[0-9]\{6\}\)\.tgz/\1/g p' )
|
2019-06-04 16:20:18 +08:00
|
|
|
|
|
|
|
select dump_filename in ${menu} "退出"
|
|
|
|
do
|
|
|
|
if [ -n "${dump_filename}" ]; then
|
|
|
|
case "${dump_filename}" in
|
|
|
|
"退出")
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-01-31 15:24:20 +08:00
|
|
|
dump_filename="gitea-backup-${dump_filename}.tgz"
|
2019-06-04 16:20:18 +08:00
|
|
|
|
|
|
|
read -n1 -p "恢复备份 : ${dump_filename} (N/y)? : " answer
|
|
|
|
case $answer in
|
|
|
|
Y|y)
|
|
|
|
echo
|
2019-06-04 22:17:16 +08:00
|
|
|
cid=$(docker-compose ps -q gitea)
|
|
|
|
if [ ${#cid} -gt 0 ]; then
|
|
|
|
docker-compose down
|
|
|
|
fi
|
|
|
|
|
2020-01-31 15:24:20 +08:00
|
|
|
docker-compose run --rm gitea sh -c "/app/gitea/gitea -v >/data/gitea/version.txt &&cd /data &&sqlite3 /data/gitea/gitea.db .dump >/data/gitea/gitea.sql&&echo "备份当前文件到 ${backup_filename}.tgz &&tar -zcpf ${backup_filename}.tgz ssh gitea git && chown git:users /backup -R && chmod -R a+r ${backup_path_docker}/* && rm -rf /data/* && echo "恢复备份 ${dump_filename} ..." && tar -zxf ${backup_path_docker}/${dump_filename} "
|
|
|
|
|
|
|
|
# mkdir -p ./data
|
|
|
|
# docker-compose up -d
|
|
|
|
# cd /data
|
|
|
|
# docker-compose -rm run gitea sh -c "mv /data/gitea /data/$(date '+gitea_%Y%m%d_%H%M%S.bak')"
|
|
|
|
# echo "解压文件..."
|
|
|
|
# sudo tar -zxf ${backup_path}/${dump_filename}
|
2019-06-04 16:20:18 +08:00
|
|
|
echo "恢复完毕."
|
|
|
|
echo "启动 Gitea ..."
|
2020-01-31 15:24:20 +08:00
|
|
|
# cd $(dirname ${BASH_SOURCE:-$0})
|
2019-06-04 16:20:18 +08:00
|
|
|
docker-compose up -d
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|