Linux系统备份Gitee等云git所有仓库与所有分支的数字资产

思路:

1. ssh 配置

2. reps.txt 列出所有仓库名

3. exp的自动化备份脚本

--

环境安装:

exp需要依赖安装的文件,所以先执行下(以ubuntu为例):

   sudo apt-get install expect

操作步骤:

ssh 配置

1. 添加公钥至 Gitee(Linux服务器)

 

ssh-keygen -t rsa -C "your_email@example.com" -f ~/.ssh/gitee
cat ~/.ssh/gitee.pub

 2. 编写 config 文件

 在 ~/.ssh/ 目录中创建或编辑 config 文件,添加以下内容:

Host Gitee
    User git
    Hostname gitee.com
    IdentityFile ~/.ssh/gitee

注意事项

  • 确保 ~/.ssh/ 目录和 config 文件的权限设置正确。通常使用以下命令设置权限:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/gitee
chmod 600 ~/.ssh/config

整理需要clone的仓库名称:reps.txt

rep001

rep002

rep003

自动化备份脚本 

vim clone_repos.exp

#!/usr/bin/expect

set original_dir [pwd]  ;# 记录当前的原始目录
set rep [open "reps.txt"]
while { [gets $rep line] != -1 } {
    set repo_path Gitee:chihj/$line.git"
    set mirror_path "$line.git"  ;# 假设镜像仓库存储在当前目录下,名称为 $line.git

    # 检查镜像仓库是否存在
    if {![file exists $mirror_path]} {
        # 如果不存在,克隆镜像
        spawn git clone --mirror $repo_path
    } else {
        # 如果存在,进入镜像目录并执行更新
        cd $mirror_path
        spawn git fetch --all --prune
    }

    expect {
        "Are you sure you want to continue connecting" {
            send "yes\r"
            expect eof
        }
        eof
    }

    # 返回到原始目录
    cd $original_dir
}

close $rep

运行: 

chmod +x clone_repos.exp
./clone_repos.exp

推荐方案

对于数字资产的长期备份,推荐使用 git clone --mirrorgit fetch --all 的结合方式.

再做个定时任务,就OKAY了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值