This commit is contained in:
40
.drone-oss.yml
Normal file
40
.drone-oss.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: Git Backup
|
||||
|
||||
# 手动触发或接口触发
|
||||
trigger:
|
||||
event:
|
||||
- custom
|
||||
|
||||
steps:
|
||||
# 账号密码特殊字符需要使用 URL 编码代替
|
||||
- name: Git Clone
|
||||
image: registry.cn-hangzhou.aliyuncs.com/offends/drone:git
|
||||
pull: if-not-exists
|
||||
environment:
|
||||
GIT_USERNAME:
|
||||
from_secret: GIT_USERNAME
|
||||
GIT_PASSWORD:
|
||||
from_secret: GIT_PASSWORD
|
||||
TAR_NAME:
|
||||
from_secret: TAR_NAME
|
||||
commands:
|
||||
- bash Build.sh "$GIT_USERNAME" "$GIT_PASSWORD" "$TAR_NAME"
|
||||
|
||||
- name: Backup File To OSS
|
||||
image: registry.cn-hangzhou.aliyuncs.com/offends/drone:oss
|
||||
pull: if-not-exists
|
||||
environment:
|
||||
OOS_ENDPOINT:
|
||||
from_secret: OOS_ENDPOINT
|
||||
OOS_ACCESSKEYID:
|
||||
from_secret: OOS_ACCESSKEYID
|
||||
OOS_ACCESSKEYSECRET:
|
||||
from_secret: OOS_ACCESSKEYSECRET
|
||||
OOS_PATH:
|
||||
from_secret: OOS_PATH
|
||||
TAR_NAME:
|
||||
from_secret: TAR_NAME
|
||||
commands:
|
||||
- ossutil64 -e $OOS_ENDPOINT -i $OOS_ACCESSKEYID -k $OOS_ACCESSKEYSECRET cp ./$TAR_NAME.tar.gz $OOS_PATH --force
|
||||
41
.drone-s3.yml
Normal file
41
.drone-s3.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: Git Backup
|
||||
|
||||
# 手动触发或接口触发
|
||||
trigger:
|
||||
event:
|
||||
- custom
|
||||
|
||||
steps:
|
||||
# 账号密码特殊字符需要使用 URL 编码代替
|
||||
- name: Git Clone
|
||||
image: registry.cn-hangzhou.aliyuncs.com/offends/drone:git
|
||||
pull: if-not-exists
|
||||
environment:
|
||||
GIT_USERNAME:
|
||||
from_secret: GIT_USERNAME
|
||||
GIT_PASSWORD:
|
||||
from_secret: GIT_PASSWORD
|
||||
TAR_NAME:
|
||||
from_secret: TAR_NAME
|
||||
commands:
|
||||
- bash Build.sh "$GIT_USERNAME" "$GIT_PASSWORD" "$TAR_NAME"
|
||||
|
||||
- name: Backup File To S3
|
||||
image: registry.cn-hangzhou.aliyuncs.com/offends/drone:mc
|
||||
pull: if-not-exists
|
||||
environment:
|
||||
S3_URl:
|
||||
from_secret: S3_URl
|
||||
S3_ACCESS_KEY:
|
||||
from_secret: S3_ACCESS_KEY
|
||||
S3_SECRET_KEY:
|
||||
from_secret: S3_SECRET_KEY
|
||||
TAR_NAME:
|
||||
from_secret: TAR_NAME
|
||||
S3_BUCKET:
|
||||
from_secret: S3_BUCKET
|
||||
commands:
|
||||
- mc alias set S3 $S3_URl $S3_ACCESS_KEY $S3_SECRET_KEY
|
||||
- mc cp ./$TAR_NAME.tar.gz S3/$S3_BUCKET/
|
||||
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# ---> macOS
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
42
Build.sh
Normal file
42
Build.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: Clone 项目
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2024-01-18
|
||||
# 更新时间: 2025-12-26
|
||||
#############################################################################################
|
||||
|
||||
# 读取文件并存入数组
|
||||
GIT_NAME=($(<repositories.list))
|
||||
TAR_NAME="$3"
|
||||
|
||||
for FILE in "${GIT_NAME[@]}"; do
|
||||
GIT_URL=$(echo $FILE | awk -F '//' '{print $2}')
|
||||
|
||||
# 拉取项目
|
||||
echo -e "\033[32m 正在拉取 $GIT_URL ... \033[0m"
|
||||
git clone --depth=1 https://$1:$2@$GIT_URL > /dev/null 2>&1
|
||||
|
||||
|
||||
GIT_FILE=$(echo $FILE | sed 's/\.git$//' | grep -oE '[^/]+$')
|
||||
# 清理 .git 文件
|
||||
# rm -rf $GIT_FILE/.git > /dev/null 2>&1
|
||||
echo $GIT_FILE >> file.txt
|
||||
done
|
||||
|
||||
# 打包
|
||||
echo -e "\033[32m 正在打包文件 ... \033[0m"
|
||||
tar -zcvf $TAR_NAME.tar $(cat file.txt) > /dev/null 2>&1
|
||||
|
||||
# GZIP压缩
|
||||
echo -e "\033[32m 正在压缩文件 ... \033[0m"
|
||||
gzip -c $TAR_NAME.tar > $TAR_NAME.tar.gz
|
||||
# 判断是否压缩成功
|
||||
if [ $? -eq 0 ]; then
|
||||
rm -f $TAR_NAME.tar
|
||||
echo -e "\033[32m 文件压缩成功: $TAR_NAME.tar.gz \033[0m"
|
||||
else
|
||||
echo -e "\033[31m 文件压缩失败 \033[0m"
|
||||
exit 1
|
||||
fi
|
||||
52
README.md
Normal file
52
README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Drone备份GIT仓库文件到 OSS & S3(Minio,RustFS等)
|
||||
|
||||
> Drone 基础镜像 Dockerfile 所在仓库
|
||||
>
|
||||
> [Drone-Images](https://gitee.com/offends/Kubernetes/tree/main/Docker/Dockerfile/Drone-Images)
|
||||
|
||||
> Git 账号密码带有特殊符号时需要按照 URL 编码参考手册替换特殊符号!!!
|
||||
>
|
||||
> [URL 编码参考手册](https://www.w3school.com.cn/tags/html_ref_urlencode.asp)
|
||||
>
|
||||
> 例如:如果我的 GIT 账号有 "@" 符号, 则需要用 " %40" 代替
|
||||
|
||||
1. 修改 `repositories.list` 文件内自己需要备份的仓库地址
|
||||
|
||||
2. 更具需要使用的备份方式修改 Drone Configuration 文件为:
|
||||
|
||||
- `.drone-oss.yml`
|
||||
- `.drone-s3.yml`
|
||||
|
||||
3. Drone 工具添加 Secrets
|
||||
|
||||
- 备份至OSS
|
||||
|
||||
**添加 Drone Secrets**
|
||||
|
||||
| 参数 | 解释 | 示例 |
|
||||
| :-----------------: | :--------------------------: | :------------------------: |
|
||||
| GIT_USERNAME | Git仓库账户 | *** |
|
||||
| GIT_PASSWORD | Git仓库密码 | *** |
|
||||
| OOS_ACCESSKEYID | 访问密钥 | *** |
|
||||
| OOS_ACCESSKEYSECRET | 访问密钥 | *** |
|
||||
| OOS_ENDPOINT | 设置Bucket所在地域的域名信息 | oss-cn-<地区>.aliyuncs.com |
|
||||
| OOS_PATH | 配置文件备份 OSS 存储路径 | oss://<Bucket>/<目录> |
|
||||
| TAR_NAME | 指定备份文件保存名称 | *** |
|
||||
|
||||
- 备份至本地 S3 存储(Minio,RustFS等)
|
||||
|
||||
**添加 Drone Secrets**
|
||||
|
||||
| 参数 | 解释 | 示例 |
|
||||
| :-----------: | :------------------: | :------------: |
|
||||
| GIT_USERNAME | Git仓库账户 | *** |
|
||||
| GIT_PASSWORD | Git仓库密码 | *** |
|
||||
| S3_URl | S3存储访问地址 | https://<地址> |
|
||||
| S3_ACCESS_KEY | 访问密钥 | *** |
|
||||
| S3_SECRET_KEY | 访问密钥 | *** |
|
||||
| TAR_NAME | 指定备份文件保存名称 | *** |
|
||||
| S3_BUCKET | 指定S3存储存储路径 | *** |
|
||||
|
||||
4. 点击 Drone "NEW BUILD" 开始备份
|
||||
8
repositories.list
Normal file
8
repositories.list
Normal file
@@ -0,0 +1,8 @@
|
||||
https://gitea.offends.cn/offends/Kubernetes.git
|
||||
https://gitea.offends.cn/offends/Linux.git
|
||||
https://gitea.offends.cn/offends/System.git
|
||||
https://gitea.offends.cn/offends/dinghui40.git
|
||||
https://gitea.offends.cn/offends/Hexo-Async-Offends.git
|
||||
https://gitea.offends.cn/offends/Git_Backup.git
|
||||
https://gitea.offends.cn/offends/Rainbond.git
|
||||
https://gitea.offends.cn/Offends/Game.git
|
||||
Reference in New Issue
Block a user