2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Macでgit pullする前にブランチ名つけてバックアップするスクリプト

Last updated at Posted at 2014-12-26

仕様

  • your_projectでファイルを実行するとプロジェクトをバックアップする
    • デフォルトで生成されるファイルのパスの例 your_workspace/git_backup/your_project/ 現在のブランチ名_15-01-06-11-03-18.zip
  • 7日前から10日までの日付名を含むデータを削除
  • 大きなプロジェクトになると毎回圧縮するのは辛い

準備

  1. 「your_workspace/your_project/bu」にファイルを保存
  2. 「your_project」に移動しchmod a+x ./bu
bu
# バックアップ先フォルダの作成
mkdir -p ../git_backup/${PWD##*/}/
zip -qr ../git_backup/${PWD##*/}/`git rev-parse --abbrev-ref HEAD`_`date +%y-%m-%d-%H-%M-%S`.zip ../${PWD##*/}/
# 自己責任で・・・7日前から10日までの日付名を含むデータを削除
rm -fr ..pwd/git_backup/${PWD##*/}/`date -v-7d +%y_%m%d`_*
rm -fr ../git_backup/${PWD##*/}/`date -v-8d +%y_%m%d`*
rm -fr ../git_backup/${PWD##*/}/`date -v-9d +%y_%m%d`*
rm -fr ../git_backup/${PWD##*/}/`date -v-10d +%y_%m%d`*
# git pull or fetchする
# git pull

実行

./bu

参考にしたサイト

gitで現在のブランチ名を取得する
http://sugamasao.hatenablog.com/entry/2013/11/02/174311
Mac の bash で date を使って先月の今日の日付を取ろうとしたらハマった
http://weble.org/2010/09/21/mac-bash-date

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?