使用shell脚本备份git

时间:2014-11-12 08:07:09

标签: git bash shell github

我找到并编辑了一个shell脚本,如下所示克隆并压缩分配给用户的所有repos

#!/bin/sh

#
# Simple shell script to backup all GitHub repos
#     Usage: github-backup.sh <git@username.co.za>
#

set -ex

USER="$git@username.co.za"
API_URL="https://api.github.com/users/${USER}/repos?type=owner"
DATE=$(date +"%Y%m%d")
TEMP_DIR="github_${USER}_${DATE}"
BACKUP_FILE="${/opt/backup}.tgz"

mkdir "$/opt/backup" && cd "$/opt/backup"
curl -s "$API_URL" | grep -Eo '"git_url": "[^"]+"' | awk '{print $2}' | xargs -n 1 git clone
cd -
tar zcf "$BACKUP_FILE" "$/opt/backup"
rm -rf "$/opt/backup"

当我尝试执行它时,我得到:

./github-backup.sh 
+ USER=@username.co.za
+ API_URL=https://api.github.com/users/@username.co.za/repos?type=owner
+ date +%Y%m%d
+ DATE=20141112
+ TEMP_DIR=github_@username.co.za_20141112
./github-backup.sh: 14: ./github-backup.sh: Bad substitution

1 个答案:

答案 0 :(得分:1)

问题是您在${/opt}处使用了奇怪的代码,例如$/opt/backup。删除路径的$${},这应该更好=)