修改 backup.sh;增加restore.sh

This commit is contained in:
chinky 2018-07-09 16:54:17 +08:00
parent 818d60d495
commit 984583e356
4 changed files with 69 additions and 10 deletions

View File

@ -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
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

View File

@ -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"

2
lsbak.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
sudo ls /sharedfolders/git/gitea -lh

47
restore.sh Normal file
View File

@ -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