2019-06-04 16:20:18 +08:00
|
|
|
#!/bin/bash
|
|
|
|
backup_path="/sharedfolders/git/gitea"
|
|
|
|
|
|
|
|
cd $(dirname ${BASH_SOURCE:-$0})
|
|
|
|
|
|
|
|
|
|
|
|
# 恢复备份
|
|
|
|
PS3="请选择恢复的备份: "
|
2019-06-04 22:17:16 +08:00
|
|
|
menu=$(ls -1 ${backup_path} | sed -n 's/gitea-backup-\([0-9]\{8\}_[0-9]\{6\}\)\.zip/\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
|
|
|
|
|
|
|
|
|
|
|
|
read -n1 -p "恢复备份 : ${dump_filename} (N/y)? : " answer
|
|
|
|
case $answer in
|
|
|
|
Y|y)
|
|
|
|
echo
|
|
|
|
echo "恢复备份 \"${dump_filename}\" 中 ..."
|
2019-06-04 22:17:16 +08:00
|
|
|
cid=$(docker-compose ps -q gitea)
|
|
|
|
if [ ${#cid} -gt 0 ]; then
|
|
|
|
docker-compose down
|
|
|
|
fi
|
|
|
|
|
2019-06-04 16:20:18 +08:00
|
|
|
mkdir -p ./data
|
2019-06-04 22:17:16 +08:00
|
|
|
docker-compose up -d
|
2019-06-04 16:20:18 +08:00
|
|
|
cd data
|
2019-06-04 22:17:16 +08:00
|
|
|
docker-compose exec gitea sh -c "mv /data/gitea /data/$(date '+gitea_%Y%m%d_%H%M%S.bak')"
|
2019-06-04 16:20:18 +08:00
|
|
|
sudo tar -zxf ${backup_path}/${dump_filename}
|
|
|
|
echo "恢复完毕."
|
|
|
|
echo "启动 Gitea ..."
|
|
|
|
docker-compose up -d
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|