简体   繁体   中英

backup git using shell script

I found and edited a shell script as follow to clone and zip all the repos assigned to a user

#!/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"

When I try to execute it, I get:

./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

The problem is that you use a strange code where you do ${/opt} and such like $/opt/backup . remove the $ or the ${} for the paths, this should be quite better =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM