sh 完成Backblaze B2的git存储库备份脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 完成Backblaze B2的git存储库备份脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# Script to backup git repo to Backblaze B2
# Set bucket, dir, password and account to use for the backup.  I keep mine in local env vars 
# These are set by localrc which lives on an encrypted home directory and is executed by my bashrc
# Ensure you have authorized the B2 command line tool with the correct account AND added your SSH
# public key to your github account, if you need to backup private repositories.

# To restore this repo in the future, download it from B2, extract it and then use this command:
# cd old-repository.git
# git push --mirror https://github.com/exampleuser/new-repository.git
# Future details are here: https://help.github.com/articles/duplicating-a-repository/

bucket=$GITHUB_BACKUP_BUCKET
dir=$GITHUB_BACKUP_DIR
password=$GITHUB_BACKUP_PASSWORD
account=$GITHUB_ACCOUNT

# Setup repository to $1
repository=$1

date=`date '+%Y%m%d%H%M%S'`

# Create the backup directory
mkdir -p $dir

echo "Backing up $repository"

git clone --mirror git@github.com:$repository $dir/$repository.$date.git
if [ $? -ne 0 ]; then
  echo "Error cloning $repository"
  exit 1
fi

tar cpzf $dir/$repository.$date.git.tar.gz $dir/$repository.$date.git
if [ $? -ne 0 ]; then
  echo "Error compressing $repository"
  exit 1
fi

#Optional file encryption
#echo $password | gpg -c --passphrase-fd 0 $dir/$repository.$date.git.tar.gz
#if [ $? -ne 0 ]; then
#  echo "Error encrypting $repository"
#  exit 1
#fi

if [ -f $dir/$repository.$date.git.tar.gz ]; then
  b2 upload-file $bucket $dir/$repository.$date.git.tar.gz git.$repository.$date.git.tar.gz
fi

if [ $? -ne 0 ]; then
  echo "Error uploading $repository to Backblaze B2"
  exit 1
fi

#delete tar file and checked out folder
/bin/rm $dir/$repository.$date.git.tar.gz
/bin/rm -rf $dir/$repository.$date.git
if [ $? -ne 0 ]; then
  echo "Error removing $repository"
  exit 1
fi

echo "Succesfully backed up $repository"

以上是关于sh 完成Backblaze B2的git存储库备份脚本的主要内容,如果未能解决你的问题,请参考以下文章

sh git fatfiles,从git存储库中删除对象

sh 将子目录从Git存储库分离为单独的存储库

sh 带有颜色的完整git存储库历史记录

sh 存储并保存更改git

sh 批量处理多个(git)存储库

sh 推送到多个git存储库